-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
69 lines (43 loc) · 1.9 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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