-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
54 lines (42 loc) · 1.43 KB
/
main.c
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
// -------------------------------------------------------
// a demo test with a simple mpi C & Python code.
// -------------------------------------------------------
// compile with
// clang execute_py.c main.c -ldl -rdynamic -lmpi
//
#include "execute_py.h"
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
if (argc != 3) {
fprintf(stderr, "Requires 2 args : Python shared lib location + script");
return 1;
}
int ierr, num_procs, my_id;
ierr = MPI_Init(&argc, &argv);
// do somethign with mpi
ierr = MPI_Comm_rank(MPI_COMM_WORLD, &my_id);
ierr = MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
printf("Hello world! I'm process %i out of %i processes\n", my_id, num_procs);
// launch python
// init_python_interpreter(argv[1]);
init_python_interpreter_from_env(argv[1]);
execute_python_file(argv[2]);
printf("Between 2 calls from C : I'm process %i out of %i processes\n", my_id, num_procs);
execute_python_file(argv[2]);
// check it has not been finalized
int final;
MPI_Finalized(&final);
if (final) {
fprintf(stderr, "MPI is finalized on node %i\n", my_id);
return 1;
}
// wait for all python to conclude
// and redo some mpi after closing python
MPI_Barrier(MPI_COMM_WORLD);
ierr = MPI_Comm_rank(MPI_COMM_WORLD, &my_id);
ierr = MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
printf("Hello again ! I'm process %i out of %i processes\n", my_id, num_procs);
close_python_interpreter();
MPI_Finalize();
}