-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
55 lines (42 loc) · 1.19 KB
/
test.cpp
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
51
52
53
54
55
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
typedef struct
{
int num_tasks;
vector<long> task_ids;
} desc_tasks_t;
int main()
{
MPI_Init(NULL, NULL);
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Datatype DESC_TASKS_TYPE;
MPI_Type_contiguous(sizeof(int) + 5 * sizeof(long), MPI_BYTE, &DESC_TASKS_TYPE);
MPI_Type_commit(&DESC_TASKS_TYPE);
printf("Hello world from rank %d of %d\n", rank, size);
if (rank == 0)
{
vector<MPI_Request> requests(1);
int data = 42;
MPI_Isend(&data, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &requests[0]);
int outcount = 0;
int indices[1];
printf("1 outcount: %d\n", outcount);
MPI_Waitsome(1, requests.data(), &outcount, indices, MPI_STATUSES_IGNORE);
printf("outcount: %d\n", outcount);
printf("indices[0]: %d\n", indices[0]);
}
else
{
int data;
MPI_Barrier(MPI_COMM_WORLD);
MPI_Recv(&data, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Received data %d\n", data);
}
MPI_Finalize();
return 0;
}