-
Notifications
You must be signed in to change notification settings - Fork 6
/
analysis.cpp
57 lines (45 loc) · 1.24 KB
/
analysis.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
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <unistd.h>
#include <mpi.h>
#include <henson/data.h>
#include <henson/data.hpp>
#include <henson/context.h>
// simulation [SLEEP]
int main(int argc, char** argv)
{
if (!henson_active())
{
printf("Must run under henson, but henson is not active\n");
return 1;
}
int sleep_interval = 0;
if (argc > 1)
sleep_interval = atoi(argv[1]);
MPI_Comm world = henson_get_world();
int rank, size;
MPI_Comm_rank(world, &rank);
MPI_Comm_size(world, &size);
if (henson_stop())
return 0;
int t;
henson_load_int("t", &t);
if (sleep_interval)
sleep(sleep_interval);
float* data;
size_t count;
size_t type;
size_t stride;
henson_load_array("data", (void**) &data, &type, &count, &stride);
assert(type == sizeof(float));
float sum = 0;
for (size_t i = 0; i < count; ++i)
sum += data[i];
float total_sum;
MPI_Reduce(&sum, &total_sum, 1, MPI_FLOAT, MPI_SUM, 0, world);
henson_save_float("sum", total_sum);
if (rank == 0)
printf("[%d]: Analysis [t=%d]: total_sum = %f\n", rank, t, total_sum);
printf("[%d]: Analysis [t=%d]: sum = %f\n", rank, t, sum);
}