[petsc-users] How to interface with PETSc from another application?

Jed Brown jed at jedbrown.org
Wed Oct 4 15:51:28 CDT 2017


Klaus Burkart <k_burkart at yahoo.com> writes:

> Adding the path to LD_LIBRARY_PATH doesn't help, the problems remain the same, it has no effect

You're having a problem linking correctly from the plugin, and maybe
some error messages are being swallowed, but this is not a PETSc issue.
You can use ldd to check whether the plugin was linked correctly (it
should find libpetsc.so).

>
>     Jed Brown <jed at jedbrown.org> schrieb am 21:39 Mittwoch, 4.Oktober 2017:
>  
>
>  Klaus Burkart <k_burkart at yahoo.com> writes:
>
>> When I link the petsc library, the application side code is not properly compiled and the solver is not available for selection
>>
>> --> FOAM FATAL IO ERROR:
>> Unknown asymmetric matrix solver petGMRES
>
> There must be some earlier error message.
>
>> Valid asymmetric matrix solvers are :
>>
>> 4
>> (
>> GAMG
>> PBiCG
>> PBiCGStab
>> smoothSolver
>> )
>> I added the following to my makefile to link the petsc library
>>
>>     -L$(PETSC_DIR)/arch-linux2-c-debug/lib    -lpetsc
>
> In this case, you'd need to add that path to LD_LIBRARY_PATH so the
> loader can find it.  None of these are PETSc issues, just linking
> dynamic libraries.
>
>>    Jed Brown <jed at jedbrown.org> schrieb am 18:45 Mittwoch, 4.Oktober 2017:
>>  
>>
>>  Klaus Burkart <k_burkart at yahoo.com> writes:
>>
>>> My setup:
>>>
>>> .bashrc
>>> export PETSC_DIR=/home/klaus/OpenFOAM/klaus-5.0/petsc-3.7.6
>>> export PETSC_ARCH=arch-linux2-c-debug
>>> export PETSC_CONFIGDIR=${PETSC_DIR}/lib/petsc
>>>
>>>
>>> make options
>>>     -I$(PETSC_CONFIGDIR)/conf \
>>
>> The above should not be needed.
>>
>>>     -I$(PETSC_DIR)/include \
>>>     -I$(PETSC_DIR)/arch-linux2-c-debug/include
>>>
>>> Installation and tests worked fine.
>>>
>>> The output using:     PetscInitialize(0,0,NULL,NULL); at the beginning and PetscFinalize(); at the end of the code section including PETSc (solver section) is:
>>>
>>> simpleFoam: symbol lookup error: /home/klaus/OpenFOAM/klaus-5.0/platforms/linux64GccDPInt32Opt/lib/libpetFoam.so: undefined symbol: PetscInitialize
>>
>> How have you linked libpetFoam.so to libpetsc.so and did you use RPATH?
>> That seems to be the problem.
>>
>>> No simulation is triggered
>>>
>>>
>>> When I just declare Mat M; and call a function with M as a parameter which outputs "Petsc - Hello" and sets the matrix M to symmetric (using: MatSetOption(A, MAT_SYMMETRIC, PETSC_TRUE);), the execution of a simulation is triggered but MatSetOption is causing a problem, I assume because PetscInitialize is missing
>>>
>>> Petsc - Hello nonepetGMRES:  Solving for Ux, Initial residual = 1, Final residual = 1, No Iterations 0
>>> Petsc - Hello nonepetGMRES:  Solving for Uz, Initial residual = 1, Final residual = 1, No Iterations 0
>>> simpleFoam: symbol lookup error: /home/klaus/OpenFOAM/klaus-5.0/platforms/linux64GccDPInt32Opt/lib/libpetFoam.so: undefined symbol: MatSetOption
>>>
>>> Maybe important to know, there's no way to enter commmand line input in the terminal while a simulation is running because the application displays continuously the intermediate simulation results. That's why I use PetscInitialize(0,0,NULL,NULL); There's now way to provide command line input.
>>
>> That's fine.  You can use the PETSC_OPTIONS environment variable or a
>> configuration file to get run-time options to PETSc.
>>
>>> I came back to this simple test after writing "the complete code" which showed these problems and stripped it down, step-by-step, to figure out what causes the problem i.e. everything but a declaration. 
>>>
>>>  
>>>
>>>    Jed Brown <jed at jedbrown.org> schrieb am 17:17 Mittwoch, 4.Oktober 2017:
>>>  
>>>
>>>  Klaus Burkart <k_burkart at yahoo.com> writes:
>>>
>>>> What's the concept to interface with PETSc from another application to solve a linear system with PETSc?
>>>>
>>>> The standard procedure of the job:
>>>>
>>>> 1: The application provides a matrix which needs to be converted and be loaded into PETSc
>>>>
>>>> 2: The application provides the rhs vector (containing pointers!) which needs to be loaded into PETSc 
>>>>
>>>> 3: The linear system is to be solved using PETSc
>>>>
>>>> 4: The application provides the result vector x, the PETSc result needs to be copied back to the application into vector x (also expecting pointers)
>>>>
>>>>
>>>> The problem - maybe a completely wrong approach when it comes to using PETSc: 
>>>>
>>>> With other linear algebra libraries, I included the library functionality in the code of a new solver accessing the functionality usually via header files and created a plugin which can be called from the application when running a simulation. 
>>>>
>>>> Even so the mixed code including PETSc code can be compiled, the bit of the plugin, interfacing with the application is broken as soon as I include more than a PETSc declaration in the mixed code.
>>>
>>> Sounds like maybe you haven't correctly linked to the PETSc library.
>>> Sending us the commands run and output/errors would be helpful to debug.
>>>
>>>> How to interface with PETSc from a software application?  (I am using c++ and Ubuntu)
>>>>
>>>> Klaus
>>>
>>>    
>>
>>    
>
>    


More information about the petsc-users mailing list