Skip to content

parcollet/execute_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WARNING: just a temporary development for the TRIQS project, not intended for distribution.

Goal
----

A demo code to call Python from a C (or Fortran code).

- execute_py.h, execute_py.c : 
  the function to open a new interpreter, run a script in it and close it

- main.c : a small demo code, which : 
   
   - opens mpi in C, does a basic operation with it
   - call Python, which itself launch mpi4py and use it a bit
   - redo some mpi after the Python is finalized, to check mpi is not affected.

- test.py : the python script for the test

NB : one can also split the function in 3 functions (init, run, finalize) 
to keep the interpreter alive between calls. Is it useful ?

- main.f90 : the same demo code for Fortran90
   

Compilation
------------

- This is a C code (not C++), you need to compile with a C compiler.
  (to have a mangling compatible with fortran).

- You need to link to dl (for dlopen), and mpi (for the test)

- Compilation instructions.

 * OS X : 
   clang execute_py.c main.c  -ldl  -lmpi

 * F90 demo :
   mpif90 -ldl main.f90 execute_py.o
 

Run
----

if using the enivronmental variable, you have to set it first to the path to the python lib, e.g.
aichhorn@faepop60:~/TRIQS1.x/EXECUTE_PYTHON$ export PYTHONLIB=/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so

./a.out requires two arguments:

 - the name of the environment variable containing location of the Python shared library (.so on Linux, .dylib on OS X).
 - the name of the script

e.g.

aichhorn@faepop60:~/TRIQS1.x/EXECUTE_PYTHON$ mpirun -np 2 ./a.out PYTHONLIB ./test.py 
   Python lib: PYTHONLIB
   Python script: ./test.py
   I am rank            0   out of            2
   I am rank            1   out of            2
Python I am node  0
Python I am node  1
   Call between: I am rank            0   out of            2
   Call between: I am rank            1   out of            2
Python I am node  0
Python I am node  1




About

Demo code for some TRIQS dev. issue

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published