-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_mpi.cpp
69 lines (53 loc) · 1.35 KB
/
main_mpi.cpp
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
66
67
68
69
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <mpi.h>
#include "my_sig_handler.h"
namespace {
int numranks, rank;
char hn[256];
}
void do_checkpoint (MPI_Comm comm)
{
for (int i=1; i<=10; i++)
{
if (0 == rank)
{
printf("\t%2d : Inside checkpoint function\n",i);
fflush(stdout);
sleep(5);
}
MPI_Barrier(comm);
}
done_checkpoint();
return;
}
int main (int argc, char **argv)
{
gethostname(hn, sizeof(hn) / sizeof(char));
MPI_Init(&argc, &argv);
MPI_Comm_size (MPI_COMM_WORLD, &numranks);
MPI_Comm_rank (MPI_COMM_WORLD, &rank);
std::cout << "Hello from " << rank << " / " << std::string (hn)
<< ", running " << argv[0] << " on " << numranks << " ranks" << std::endl;
// register our user-defined signal handlers, on every rank
register_sig_handler();
for (int i=1; i<=50 ;i++)
{
if (0 == rank)
{
printf("%2d : Inside main function\n",i);
fflush(stdout);
sleep(5);
}
MPI_Barrier(MPI_COMM_WORLD);
// this function needs to perform a reduction to see if any rank received
// a signal, hence it is blocking.
if (mpi_checkpoint_requested(MPI_COMM_WORLD))
do_checkpoint(MPI_COMM_WORLD);
}
MPI_Finalize();
return 0;
}