-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPI6File30.cpp
More file actions
41 lines (33 loc) · 1 KB
/
MPI6File30.cpp
File metadata and controls
41 lines (33 loc) · 1 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
#include "pt4.h"
#include "mpi.h"
void Solve()
{
Task("MPI6File30");
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);
char name[12];
int n = 0;
if (rank == 0)
pt >> name >> n;
MPI_Bcast(name, 12, MPI_CHAR, 0, MPI_COMM_WORLD);
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_File f;
MPI_File_open(MPI_COMM_WORLD, name, MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &f);
int i = 0, j = 0;
pt >> i >> j;
MPI_Datatype type;
MPI_Type_vector(n, n, 3 * n, MPI_INT, &type);
char native[7] = "native";
MPI_File_set_view(f, ((j - 1) * n + (i - 1) * 3 * n * n) * sizeof(int), MPI_INT, type, native, MPI_INFO_NULL);
int newsize = n * n;
int* num = new int[newsize];
for (int i = 0; i < newsize; i++)
num[i] = rank;
MPI_File_write_all(f, num, newsize, MPI_INT, MPI_STATUS_IGNORE);
MPI_File_close(&f);
}