-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPI2Send9.cpp
More file actions
45 lines (41 loc) · 1.01 KB
/
MPI2Send9.cpp
File metadata and controls
45 lines (41 loc) · 1.01 KB
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
#include "pt4.h"
#include "mpi.h"
void Solve()
{
Task("MPI2Send9");
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);
if (rank > 0)
{
int n;
pt >> n;
if (n > 0)
{
double x;
double* bs = new double[n];
for (int i = 0; i < n; i++)
{
pt >> x;
bs[i] = x;
}
MPI_Send(bs, n, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
}
}
else
{
MPI_Status s;
MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &s);
int count = 0;
MPI_Get_count(&s, MPI_DOUBLE, &count);
double* br = new double[count];
MPI_Recv(br, count, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &s);
for (int i = 0; i < count; i++)
pt << br[i];
pt << s.MPI_SOURCE;
}
}