PhreeqcUsers Discussion Forum
Click here to donate to keep PhreeqcUsers open

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 

  • Forum Home
  • Login
  • Register

  • PhreeqcUsers Discussion Forum »
  • Conceptual Models »
  • Incorporation PHREEQC in programming languages »
  • PhreeqcRM fail at compilation with MPI (PHRQ_io)
« previous next »
  • Print
Pages: [1]   Go Down

Author Topic: PhreeqcRM fail at compilation with MPI (PHRQ_io)  (Read 313 times)

oatteia

  • Frequent Contributor
  • Posts: 18
PhreeqcRM fail at compilation with MPI (PHRQ_io)
« on: October 14, 2023, 09:59:10 AM »
Hello,
I am on a linux muticore server. I have compiled phreeqcRM in different ways, which give the same error. The last version was using Cmake (with MPI option). The phreeqcRM  compilation is ok, but when I use this library in my phreeqc test there is an error :

undefined reference to `PhreeqcRM::PhreeqcRM(int, ompi_communicator_t*, PHRQ_io*)'

my class starts with
public:
   PhreeqcRM *PhreeqcRM_ptr;
in the same class, in the init() function, the concerned line is : PhreeqcRM phreeqc_rm(nxyz, MPI_COMM_WORLD)
in
      #ifdef USE_MPI
         int argc; char **argv;
         MPI_Init(&argc, &argv);
         PhreeqcRM phreeqc_rm(nxyz, MPI_COMM_WORLD);

(I also tried : PhreeqcRM *phreeqc_rm = new PhreeqcRM(nxyz, MPI_COMM_WORLD); giving same error)

I tried with MPI_Init() and MPI_Init_thread() same results
the characteristics of the libraries are given below (by cmake) :
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found MPI_C: /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so (found version "3.1")
-- Found MPI_CXX: /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so (found version "3.1")
-- Found MPI: TRUE (found version "3.1")
-- Run: /usr/bin/mpiexec -n 24  EXECUTABLE  ARGS
-- Configuring done
-- Generating done
-- Build files have been written to: /home/oatteia/muFlowRT/solvers/phreeqc/build
Logged

oatteia

  • Frequent Contributor
  • Posts: 18
Re: PhreeqcRM fail at compilation with MPI (PHRQ_io)
« Reply #1 on: October 14, 2023, 10:05:22 AM »
Sorry me again, just to add something, I verified MPI alone on the server, it is working correctly with the same options
and the cmake lines for mpi are (same as in cmake of phreeqc)

find_package( MPI REQUIRED )
message(STATUS "Run: ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS")
# add this line only when you are using openmpi which has a different c++ bindings
add_definitions(-DOMPI_SKIP_MPICXX)
set(DEFINITIONS_COMPILE "-std=c++11 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wno-unused-parameter -Wno-overloaded-virtual -Wno-unused-variable -Wno-unused-local-typedef -Wno-invalid-offsetof -Wno-deprecated-register -Wno-undefined-var-template -O0 -g -DFULLDEBUG -DNoRepository -ftemplate-depth-100 -fPIC")
add_definitions(-DUSE_MPI)
include_directories(${MPI_CXX_INCLUDE_PATH})
set(LINK_LIBS ${LINK_LIBS} ${MPI_CXX_LIBRARIES})
link_directories( ${PATH_LIB_OPENMPI})

add_executable(runFreak runFreak.cpp)
target_link_libraries(${PROJECT_NAME} ${MPI_CXX_LIBRARIES})
Logged

charlton

  • Top Contributor
  • Posts: 38
Re: PhreeqcRM fail at compilation with MPI (PHRQ_io)
« Reply #2 on: October 14, 2023, 05:06:21 PM »
Hi,

Can you post which version of PhreeqcRM you're using?

Scott

Logged

charlton

  • Top Contributor
  • Posts: 38
Re: PhreeqcRM fail at compilation with MPI (PHRQ_io)
« Reply #3 on: October 14, 2023, 09:03:06 PM »
Hi again,

I'm assuming you're using phreeqcrm-3.7.3.  I think you just need to add PhreeqcRM to the link libraries:

Code: [Select]
target_link_libraries(${PROJECT_NAME} PhreeqcRM MPI::MPI_CXX)
I was unable to attach any files so here they are in text form:

main.cpp:
Code: [Select]
#include <mpi.h>
#include <PhreeqcRM.h>
#include <stdlib.h>
#include <iostream>

int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
PhreeqcRM *phreeqc_rm = new PhreeqcRM(24, MPI_COMM_WORLD);
delete phreeqc_rm;
return EXIT_SUCCESS;
}

CMakeLists.txt:
Code: [Select]
cmake_minimum_required(VERSION 3.15)

project(simple CXX)

find_package(MPI)

add_executable(${PROJECT_NAME} main.cpp)

target_compile_definitions(${PROJECT_NAME}
  PRIVATE
    USE_MPI
)

target_link_libraries(${PROJECT_NAME} PhreeqcRM MPI::MPI_CXX)

Scott
Logged

oatteia

  • Frequent Contributor
  • Posts: 18
Re: PhreeqcRM fail at compilation with MPI (PHRQ_io)
« Reply #4 on: October 19, 2023, 06:40:13 AM »
Hi Scott,
Thank you for your reply. I made some progress, but there is still difficulties. There is something that I don't understand. When I compile phreeqc (with ..\configure with MPI option), I get a libphreeqcrm-3.7.1.so, wihch I copy to /usr/lib (it does not work if I don't do it) and make a symbolic link to libphreeqcrm. Then in Cmake, I use

target_link_libraries(${PROJECT_NAME} PRIVATE pthread OpenFOAM dl m finiteVolume meshTools phase phreeqcrm)
target_link_libraries(${PROJECT_NAME} PRIVATE phreeqcrm MPI::MPI_CXX)

If I use this it compiles correctly but then when running the case it does not find PhreeqcRM. I don't exactly understand the differecne between the upper and lower case. For me the phreeqcrm sis the library which should be use with a class PhreeqcRM... but does not seem to work.

sincerely
Olivier
Logged

oatteia

  • Frequent Contributor
  • Posts: 18
Re: PhreeqcRM fail at compilation with MPI (PHRQ_io)
« Reply #5 on: October 23, 2023, 06:23:09 AM »
Hello,
I have been able to solve by compiling with cmake, adding in the cmake for phreeqc
ADD_DEFINITIONS(-DUSE_MPI)
include_directories(${MPI_CXX_INCLUDE_PATH})
set(LINK_LIBS ${LINK_LIBS} ${MPI_CXX_LIBRARIES}) 
 
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
link_directories( ${PATH_LIB_OPENMPI})
target_link_libraries(${PROJECT_NAME} PUBLIC MPI::MPI_CXX)


and in the cmake for my program
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
include_directories(${MPI_CXX_INCLUDE_PATH})
set(LINK_LIBS ${LINK_LIBS} ${MPI_CXX_LIBRARIES})
link_directories( ${PATH_LIB_OPENMPI})
target_link_libraries(${PROJECT_NAME} PhreeqcRM ${MPI_CXX_LIBRARIES})


olivier
Logged

charlton

  • Top Contributor
  • Posts: 38
Re: PhreeqcRM fail at compilation with MPI (PHRQ_io)
« Reply #6 on: October 23, 2023, 05:50:09 PM »
Hi olivier,

I was answering your question when your next post came through.  I released another hotfix that fixes a missing header in the autotools build:

https://github.com/usgs-coupled/phreeqcrm/releases/tag/v3.7.3-hotfix-2

Notes:
1. If you install in the default location '/usr/local' you shouldn't need to use LD_LIBRARY_PATH for the phreeqcrm shared libraries.
2. You can use the command 'ldd' to show what shared object libraries your executable requires.
3. When built with autotools (../configure;make) the phreeqcrm library is all lowercase phreeqcrm.  When built with cmake the library is case sensitive as PhreeqcRM.
4. Use the 'ldconfig' command to update the shared library cache
5. Use the build system to install phreeqcrm ('sudo make install' or 'sudo cmake --install .')

Here are examples of building phreeqcrm using autotools and cmake:

Build and install phreeqcrm using autotools:
Code: [Select]
tar xzf phreeqcrm-3.7.3-15968-hotfix-2.tar.gz
cd phreeqcrm-3.7.3-15968-hotfix-2
mkdir _build
cd _build
../configure --with-mpi
make -j 8
make check
sudo make install
sudo ldconfig

Build and install phreeqcrm using cmake:
Code: [Select]
tar xzf phreeqcrm-3.7.3-15968-hotfix-2.tar.gz
cd phreeqcrm-3.7.3-15968-hotfix-2
mkdir _cmake
cmake .. -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE:STRING=Release -DPHREEQCRM_BUILD_MPI:BOOL=ON -L
cmake --build . --parallel 8
ctest
sudo cmake --install .
sudo ldconfig


Updated CMakeLists.txt:
Code: [Select]
cmake_minimum_required(VERSION 3.15)

project(simple CXX)

find_package(MPI)

add_executable(${PROJECT_NAME} main.cpp)

target_compile_definitions(${PROJECT_NAME}
  PRIVATE
    USE_MPI
)

#target_link_libraries(${PROJECT_NAME} PhreeqcRM MPI::MPI_CXX) # cmake
target_link_libraries(${PROJECT_NAME} phreeqcrm MPI::MPI_CXX) # autotools

Scott
Logged

oatteia

  • Frequent Contributor
  • Posts: 18
Re: PhreeqcRM fail at compilation with MPI (PHRQ_io)
« Reply #7 on: October 27, 2023, 10:48:40 AM »
Hi Scott,
thanks a lot for this information. I think that however by tests and web info I finally found a solution. I compiled phreeqcRM with ../configure --with-mpi=yes, then in cmake I use :
target_link_libraries(${PROJECT_NAME} phreeqcrm ${MPI_CXX_LIBRARIES})
and I am able to run in tests main.ccp (I tested advection case)

I have done a new file very similar to advection but without the advection step, just to test the phreeqc intiialization (compiled with cmake). When I use mpirun -n 2 name.cpp, it goes to runCells and work for that.
very curiously, although I have done exactly the same as in the advection file :

Code: [Select]
std::vector<double> c;
c.resize(nxyz*ph_ncomp); # where ph_ncomp is the number of components got from GetComponents()
status = phreeqc_rm.GetConcentrations(c);
it fails at that line, with output error like
Signal: Segmentation fault (11)
Signal code: Address not mapped (1)
and the names after concern phreeqc and not mpi.
any idea?

sincerely

Olivier
Logged

dlparkhurst

  • Top Contributor
  • Posts: 3174
Re: PhreeqcRM fail at compilation with MPI (PHRQ_io)
« Reply #8 on: October 27, 2023, 03:31:11 PM »
I am going to need more information. I'll send a message to you and we can pursue this offline.
Logged

  • Print
Pages: [1]   Go Up
« previous next »
  • PhreeqcUsers Discussion Forum »
  • Conceptual Models »
  • Incorporation PHREEQC in programming languages »
  • PhreeqcRM fail at compilation with MPI (PHRQ_io)
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines | Terms and Policies
  • XHTML
  • RSS
  • WAP2