-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPI1Proc9.cpp
More file actions
50 lines (48 loc) · 885 Bytes
/
MPI1Proc9.cpp
File metadata and controls
50 lines (48 loc) · 885 Bytes
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
#include "pt4.h"
#include "mpi.h"
void Solve()
{
Task("MPI1Proc9");
int flag;
MPI_Initialized(&flag);
if (flag == 0)
return;
int rank, size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int n;
double x;
double sum = 0;
double mult = 1;
pt >> n;
if (rank == 0)
{
for (int i = 0; i < n; i++)
{
pt >> x;
mult *= x;
}
pt << mult;
}
else
{
if (rank % 2 == 0)
{
for (int i = 0; i < n; i++)
{
pt >> x;
sum += x;
}
pt << sum;
}
else
{
for (int i = 0; i < n; i++)
{
pt >> x;
sum += x;
}
pt << sum / (1.0 * n);
}
}
}