[petsc-users] Calling MATLAB code within a parallel C/C++ code

Sanjay Govindjee s_g at berkeley.edu
Tue Jun 9 16:55:24 CDT 2020


Try looking in:

$(MLROOT)/bin/maci64

where MLROOT = /Applications/MATLAB_R2019a.app or the like


On 6/9/20 2:51 PM, Junchao Zhang wrote:
> Find recursively where is libeng.dylib under 
> /Applications/MATLAB_R2019b.app/extern/engines/
>
> --Junchao Zhang
>
>
> On Tue, Jun 9, 2020 at 4:27 PM Amneet Bhalla <mail2amneet at gmail.com 
> <mailto:mail2amneet at gmail.com>> wrote:
>
>     Forgot to mention that configure found the following about MATLAB
>
>     Matlab:
>
>     Includes: -I/Applications/MATLAB_R2019b.app/extern/include
>
>     /Applications/MATLAB_R2019b.app
>
>     MatlabEngine:
>
>     Library: -L/Applications/MATLAB_R2019b.app/bin/maci64
>     -L/Applications/MATLAB_R2019b.app/extern/lib/maci64 -leng -lmex
>     -lmx -lmat -lut -licudata -licui18n -licuuc
>
>
>     On Tue, Jun 9, 2020 at 2:20 PM Amneet Bhalla
>     <mail2amneet at gmail.com <mailto:mail2amneet at gmail.com>> wrote:
>
>         Do these additional configure flags for MATLAB look OK?
>
>         --with-matlab=1
>         --with-matlab-dir=/Applications/MATLAB_R2019b.app
>         --with-matlab-engine=1
>         --with-matlab-engine-dir=/Applications/MATLAB_R2019b.app/extern/engines/
>
>
>
>
>         With this configuration make compiled files like:
>
>
>                   CC
>         darwin-dbg/obj/sys/classes/viewer/impls/matlab/vmatlab.o
>
>                   CC
>         darwin-dbg/obj/sys/classes/viewer/impls/matlab/ftn-custom/zvmatlabf.o
>
>                   CC darwin-dbg/obj/sys/classes/matlabengine/matlab.o
>
>                   CC
>         darwin-dbg/obj/sys/classes/matlabengine/ftn-auto/matlabf.o
>
>                   CC
>         darwin-dbg/obj/sys/classes/matlabengine/ftn-custom/zmatlabf.o
>
>                   CC darwin-dbg/obj/vec/pf/impls/matlab/cmatlab.o
>
>                   CC darwin-dbg/obj/vec/vec/utils/matlab/gcreatev.o
>
>
>         make[2]: Leaving directory
>         `/Users/amneetb/Softwares/PETSc-Gitlab/PETSc'
>
>         BEGINNING TO COMPILE MATLAB INTERFACE
>
>         Building with 'Xcode with Clang'.
>
>         ld: warning: cannot export hidden symbol
>         _mexfilerequiredapiversion from c_mexapi_version.o
>
>
>         ld: warning: cannot export hidden symbol
>         _mexfilerequiredapiversion from c_mexapi_version.o
>
>
>         MEX completed successfully.
>
>         Building with 'Xcode with Clang'.
>
>         ld: warning: cannot export hidden symbol
>         _mexfilerequiredapiversion from c_mexapi_version.o
>
>
>         ld: warning: cannot export hidden symbol
>         _mexfilerequiredapiversion from c_mexapi_version.o
>
>
>         MEX completed successfully.
>
>         Building with 'Xcode with Clang'.
>
>         ld: warning: cannot export hidden symbol
>         _mexfilerequiredapiversion from c_mexapi_version.o
>
>
>         MEX completed successfully.
>
>         Building with 'Xcode with Clang'.
>
>         ld: warning: cannot export hidden symbol
>         _mexfilerequiredapiversion from c_mexapi_version.o
>
>
>         ld: warning: cannot export hidden symbol
>         _mexfilerequiredapiversion from c_mexapi_version.o
>
>
>         MEX completed successfully.
>
>
>
>         However, make check gives error
>
>
>         amneetb at Amneets-MBP:~/Softwares/PETSc-Gitlab/PETSc$ make
>         PETSC_DIR=/Users/amneetb/Softwares/PETSc-Gitlab/PETSc
>         PETSC_ARCH=darwin-dbg check
>
>         Running test examples to verify correct installation
>
>         Using PETSC_DIR=/Users/amneetb/Softwares/PETSc-Gitlab/PETSc
>         and PETSC_ARCH=darwin-dbg
>
>         Possible error running C/C++ src/snes/examples/tutorials/ex19
>         with 1 MPI process
>
>         See http://www.mcs.anl.gov/petsc/documentation/faq.html
>
>         dyld: Library not loaded: @rpath/libeng.dylib
>
>           Referenced from:
>         /Users/amneetb/Softwares/PETSc-Gitlab/PETSc/src/snes/examples/tutorials/./ex19
>
>           Reason: image not found
>
>
>         ===================================================================================
>
>         =   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
>
>         =   PID 14057 RUNNING AT Amneets-MBP
>
>         =   EXIT CODE: 6
>
>         =   CLEANING UP REMAINING PROCESSES
>
>         =   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
>
>         ===================================================================================
>
>         YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Abort trap:
>         6 (signal 6)
>
>         This typically refers to a problem with your application.
>
>         Please see the FAQ page for debugging suggestions
>
>         Possible error running C/C++ src/snes/examples/tutorials/ex19
>         with 2 MPI processes
>
>         See http://www.mcs.anl.gov/petsc/documentation/faq.html
>
>         dyld: Library not loaded: @rpath/libeng.dylib
>
>           Referenced from:
>         /Users/amneetb/Softwares/PETSc-Gitlab/PETSc/src/snes/examples/tutorials/./ex19
>
>           Reason: image not found
>
>         dyld: Library not loaded: @rpath/libeng.dylib
>
>           Referenced from:
>         /Users/amneetb/Softwares/PETSc-Gitlab/PETSc/src/snes/examples/tutorials/./ex19
>
>           Reason: image not found
>
>
>         ===================================================================================
>
>         =   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
>
>         =   PID 14062 RUNNING AT Amneets-MBP
>
>         =   EXIT CODE: 6
>
>         =   CLEANING UP REMAINING PROCESSES
>
>         =   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
>
>         ===================================================================================
>
>         YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Abort trap:
>         6 (signal 6)
>
>         This typically refers to a problem with your application.
>
>         Please see the FAQ page for debugging suggestions
>
>         1,5c1,17
>
>         < lid velocity = 0.0016, prandtl # = 1., grashof # = 1.
>
>         <   0 SNES Function norm 0.0406612
>
>         <   1 SNES Function norm 4.12227e-06
>
>         <   2 SNES Function norm 6.098e-11
>
>         < Number of SNES iterations = 2
>
>         ---
>
>         > dyld: Library not loaded: @rpath/libeng.dylib
>
>         >   Referenced from:
>         /Users/amneetb/Softwares/PETSc-Gitlab/PETSc/src/snes/examples/tutorials/./ex19
>
>         >   Reason: image not found
>
>         > dyld: Library not loaded: @rpath/libeng.dylib
>
>         >   Referenced from:
>         /Users/amneetb/Softwares/PETSc-Gitlab/PETSc/src/snes/examples/tutorials/./ex19
>
>         >   Reason: image not found
>
>         > 
>
>         > ===================================================================================
>
>         > =   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
>
>         > =   PID 14072 RUNNING AT Amneets-MBP
>
>         > =   EXIT CODE: 6
>
>         > =   CLEANING UP REMAINING PROCESSES
>
>         > =   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
>
>         > ===================================================================================
>
>         > YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Abort trap: 6 (signal 6)
>
>         > This typically refers to a problem with your application.
>
>         > Please see the FAQ page for debugging suggestions
>
>         /Users/amneetb/Softwares/PETSc-Gitlab/PETSc/src/snes/examples/tutorials
>
>         Possible problem with ex19 running with hypre, diffs above
>
>         =========================================
>
>         Possible error running Fortran example
>         src/snes/examples/tutorials/ex5f with 1 MPI process
>
>         See http://www.mcs.anl.gov/petsc/documentation/faq.html
>
>         dyld: Library not loaded: @rpath/libeng.dylib
>
>           Referenced from:
>         /Users/amneetb/Softwares/PETSc-Gitlab/PETSc/src/snes/examples/tutorials/./ex5f
>
>           Reason: image not found
>
>
>         ===================================================================================
>
>         =   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
>
>         =   PID 14211 RUNNING AT Amneets-MBP
>
>         =   EXIT CODE: 6
>
>         =   CLEANING UP REMAINING PROCESSES
>
>         =   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
>
>         ===================================================================================
>
>         YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Abort trap:
>         6 (signal 6)
>
>         This typically refers to a problem with your application.
>
>         Please see the FAQ page for debugging suggestions
>
>         Completed test examples
>
>
>
>         I have added the following paths in my .profile and sourced it
>         before make all and make check
>
>         exportDYLD_FALLBACK_LIBRARY_PATH=/Applications/MATLAB_R2019b.app/bin/maci64:/Applications/MATLAB_R2019b.app/sys/os/maci64:$DYLD_FALLBACK_LIBRARY_PATH
>
>
>         exportDYLD_LIBRARY_PATH=/Applications/MATLAB_R2019b.app/bin/maci64:/Applications/MATLAB_R2019b.app/sys/os/maci64:$DYLD_LIBRARY_PATH
>
>
>
>
>         On Mon, Jun 8, 2020 at 6:39 PM Barry Smith <bsmith at petsc.dev
>         <mailto:bsmith at petsc.dev>> wrote:
>
>
>               Looks like the tool to list the examples in the manual
>             pages is broken since it didn't find these other examples,
>             I'll take a look at it.
>
>               There is also a discussion in the users manual
>
>             $ git grep MatlabEngine | grep ex
>             src/docs/tex/manual/part2.tex:PetscMatlabEngineCreate(MPI_Comm
>             comm,char *machine,PetscMatlabEngine *e);
>             src/docs/tex/manual/part2.tex:PetscMatlabEnginePut(PetscMatlabEngine
>             e,PetscObject obj);
>             src/docs/tex/manual/part2.tex:PetscMatlabEngineGet(PetscMatlabEngine
>             e,PetscObject obj);
>             src/docs/tex/manual/part2.tex:PetscMatlabEnginePutArray(PetscMatlabEngine
>             e,int m,int n,PetscScalar *array,char *name);
>             src/docs/tex/manual/part2.tex:PetscMatlabEngineGetArray(PetscMatlabEngine
>             e,int m,int n,PetscScalar *array,char *name);
>             src/docs/tex/manual/part2.tex:PetscMatlabEngineEvaluate(PetscMatlabEngine,"format",...);
>             src/docs/tex/manual/part2.tex:PetscMatlabEngineEvaluate(PetscMatlabEngine,"x
>             = \%g *y + z;",avalue);
>             src/docs/tex/manual/part2.tex:PetscMatlabEngineGetOutput(PetscMatlabEngine,char
>             **);
>             src/docs/tex/manual/part2.tex:PetscMatlabEnginedPrintOutput(PetscMatlabEngine,FILE*).
>             src/snes/tutorials/ex5.c: ierr =
>             PetscMatlabEnginePut(PETSC_MATLAB_ENGINE_(comm),(PetscObject)localX);CHKERRQ(ierr);
>             src/snes/tutorials/ex5.c: ierr =
>             PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_(comm),"localF=ex5m(localX,%18.16e,%18.16e,%18.16e)",hx,hy,lambda);CHKERRQ(ierr);
>             src/snes/tutorials/ex5.c: ierr =
>             PetscMatlabEngineGet(PETSC_MATLAB_ENGINE_(comm),(PetscObject)localF);CHKERRQ(ierr);
>             src/sys/tests/ex16.c:static char help[] = "Demonstrates
>             PetscMatlabEngineXXX()\n";
>             src/sys/tests/ex16.c: ierr =
>             PetscMatlabEngineGetOutput(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),&output);CHKERRQ(ierr);
>             src/sys/tests/ex16.c: ierr =
>             PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),"MPI_Comm_rank");CHKERRQ(ierr);
>             src/sys/tests/ex16.c:   ierr =
>             PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_(PETSC_COMM_WORLD),user);CHKERRQ(ierr);
>             src/vec/vec/tests/ex31.c:static const char help[] =
>             "Demonstrates PetscMatlabEngineXXX()\n";
>             src/vec/vec/tests/ex31.c: ierr =
>             PetscMatlabEngineGetOutput(PETSC_MATLAB_ENGINE_WORLD,&output);
>             src/vec/vec/tests/ex31.c: ierr =
>             PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_WORLD,"MPI_Comm_rank");
>             src/vec/vec/tests/ex31.c: ierr =
>             PetscMatlabEnginePut(PETSC_MATLAB_ENGINE_WORLD,(PetscObject)x);CHKERRQ(ierr);
>             src/vec/vec/tests/ex31.c: ierr =
>             PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_WORLD,"x = x
>             + MPI_Comm_rank;\n");
>             src/vec/vec/tests/ex31.c: ierr =
>             PetscMatlabEngineGet(PETSC_MATLAB_ENGINE_WORLD,(PetscObject)x);CHKERRQ(ierr);
>             src/vec/vec/tests/ex31.c: ierr =
>             PetscMatlabEngineEvaluate(PETSC_MATLAB_ENGINE_WORLD,"whos\n");CHKERRQ(ierr);
>
>>             On Jun 8, 2020, at 8:26 PM, Amneet Bhalla
>>             <mail2amneet at gmail.com <mailto:mail2amneet at gmail.com>> wrote:
>>
>>             Great!
>>
>>             Clicking on some of the functions pointed me to this example
>>             https://www.mcs.anl.gov/petsc/petsc-3.13/src/snes/tutorials/ex5.c.html
>>
>>             Are there more examples, which are perhaps simpler than
>>             the above, which I can refer to?
>>
>>             On Mon, Jun 8, 2020 at 5:51 PM Barry Smith
>>             <bsmith at petsc.dev <mailto:bsmith at petsc.dev>> wrote:
>>
>>
>>                   You should use the PetscMatlabEngine
>>                 https://www.mcs.anl.gov/petsc/petsc-3.13/docs/manualpages/Sys/PetscMatlabEngine.html
>>
>>                   Barry
>>
>>
>>>                 On Jun 8, 2020, at 7:09 PM, Amneet Bhalla
>>>                 <mail2amneet at gmail.com
>>>                 <mailto:mail2amneet at gmail.com>> wrote:
>>>
>>>                 Hi Folks,
>>>
>>>                 My parallel application written in C++ (which also
>>>                 uses PETSc library for linear solvers) requires
>>>                 calling control and optimization toolbox of MATLAB
>>>                 at every time step to get a small number of double
>>>                 values. Likewise the MATLAB function will need to
>>>                 know some values from the parallel C++ application
>>>                 to return those doubles. I'm wondering if there is a
>>>                 recommended way of calling MATLAB from parallel
>>>                 C/C++/Fortran codes, and if PETSc has some interface
>>>                 that could be leveraged for this exchange.
>>>
>>>                 Thanks,
>>>                 -- 
>>>                 --Amneet
>>>
>>>
>>>
>>
>>
>>
>>             -- 
>>             --Amneet
>>
>>
>>
>
>
>
>         -- 
>         --Amneet
>
>
>
>
>
>     -- 
>     --Amneet
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200609/df272182/attachment-0001.html>


More information about the petsc-users mailing list