GingrasO/execute_python
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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 ? - to use it form fortran, call the execute_py with 2 strings... (todo) 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 Run ---- ./a.out requires two arguments: - the location of the Python shared library (.so on Linux, .dylib on OS X). - the name of the script e.g. kondo:~/execute_python (master)$ mpirun -np 4 ./a.out /usr/local/install/python-2.7.5/lib/libpython2.7.so ./test.py Hello world! I'm process 0 out of 4 processes Hello world! I'm process 1 out of 4 processes Hello world! I'm process 2 out of 4 processes Hello world! I'm process 3 out of 4 processes Python I am node 2 Python I am node 3 Python I am node 0 Python I am node 1 Hello again ! I'm process 1 out of 4 processes Hello again ! I'm process 3 out of 4 processes Hello again ! I'm process 0 out of 4 processes Hello again ! I'm process 2 out of 4 processes
Releases
No releases published
Languages
- C 57.2%
- Fortran 35.7%
- C++ 5.2%
- Python 1.9%