-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPI6File9.cpp
More file actions
39 lines (31 loc) · 873 Bytes
/
MPI6File9.cpp
File metadata and controls
39 lines (31 loc) · 873 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
#include "pt4.h"
#include "mpi.h"
void Solve()
{
Task("MPI6File9");
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];
if (rank == 0)
pt >> name;
MPI_Bcast(name, 12, MPI_CHAR, 0, MPI_COMM_WORLD);
MPI_File f;
MPI_File_open(MPI_COMM_WORLD, name, MPI_MODE_RDONLY, MPI_INFO_NULL, &f);
MPI_Offset rk = rank * sizeof(int);
MPI_File_seek(f, rk, MPI_SEEK_SET);
MPI_Offset offs;
MPI_File_get_size(f, &offs);
int file_sz = offs / sizeof(int);
int count = min(rank + 1, file_sz - rank);
MPI_Status s;
int* num = new int[count];
MPI_File_read_all(f, num, count, MPI_INT, &s);
for (int i = 0; i < count; i++)
pt << num[i];
MPI_File_close(&f);
}