-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPI5Comm18.cpp
More file actions
32 lines (27 loc) · 746 Bytes
/
Copy pathMPI5Comm18.cpp
File metadata and controls
32 lines (27 loc) · 746 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
#include "pt4.h"
#include "mpi.h"
void Solve()
{
Task("MPI5Comm18");
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 = size / 3, x = 0;
int* num = new int[n];
if (rank == 0 || rank == 1 || rank == 2)
for (int i = 0; i < n; i++)
pt >> num[i];
MPI_Comm comm;
int dims[2] = { n, 3 };
int periods[2] = { 0, 0 };
MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, 0, &comm);
MPI_Comm newcomm;
int remain_dims[2] = { 1, 0 };
MPI_Cart_sub(comm, remain_dims, &newcomm);
MPI_Scatter(num, 1, MPI_INT, &x, 1, MPI_INT, 0, newcomm);
pt << x;
}