-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparallel.c
34 lines (30 loc) · 878 Bytes
/
parallel.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
#include "headdefs.h"
int myid;
int numprocs;
void InitMPI(int argc, char **argv) {
int ierror, flag;
/* indicate whether MPI_INIT has been called */
ierror = MPI_Initialized(&flag);
if (!flag) {
/* initialize the MPI execution environment */
ierror = MPI_Init(&argc,&argv);
if (ierror) exit(1);
}
/* determine the rank of the calling process in the communicator */
ierror = MPI_Comm_rank(MPI_COMM_WORLD,&myid);
/* determine the size of the group associated with a communicator */
ierror = MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
return;
}
void ExitMPI() {
int ierror, flag;
/* indicate whether MPI_INIT has been called */
ierror = MPI_Initialized(&flag);
if (flag) {
/* synchronize processes */
ierror = MPI_Barrier(MPI_COMM_WORLD);
/* terminate MPI execution environment */
ierror = MPI_Finalize();
}
return;
}