Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Free memory.
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / dtype_send.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2016 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <mpi.h>
10
11 #define NUM_LOOPS  (128)
12
13 int main(int argc, char **argv)
14 {
15     int i, rank, size;
16     MPI_Request *req=NULL;
17     MPI_Datatype newtype;
18     int snd_buf[3], rcv_buf[3];
19     int count = 2;
20     int *displs;
21
22     MPI_Init(&argc, &argv);
23     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24     MPI_Comm_size(MPI_COMM_WORLD, &size);
25
26     if (size < 2) {
27         fprintf(stderr, "Must run with at least 2 processes\n");
28         MPI_Abort(MPI_COMM_WORLD, 1);
29     }
30
31     displs = (int *) malloc(count * sizeof(int));
32     for (i = 0; i < count; i++)
33         displs[i] = i * 2;
34
35     MPI_Barrier(MPI_COMM_WORLD);
36
37     /* test isends */
38     MPI_Type_create_indexed_block(count, 1, displs, MPI_INT, &newtype);
39     MPI_Type_commit(&newtype);
40
41     if (rank == 0) {
42         req = (MPI_Request *) malloc(NUM_LOOPS * sizeof(MPI_Request));
43         for (i = 0; i < NUM_LOOPS; i++)
44             MPI_Isend(snd_buf, 1, newtype, !rank, 0, MPI_COMM_WORLD, &req[i]);
45     }
46     else {
47         for (i = 0; i < NUM_LOOPS; i++)
48             MPI_Recv(rcv_buf, 1, newtype, !rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
49     }
50     MPI_Type_free(&newtype);
51     if (rank == 0)
52         MPI_Waitall(NUM_LOOPS, req, MPI_STATUSES_IGNORE);
53
54     MPI_Barrier(MPI_COMM_WORLD);
55     free(req);
56
57     /* test issends */
58     MPI_Type_create_indexed_block(count, 1, displs, MPI_INT, &newtype);
59     MPI_Type_commit(&newtype);
60
61     if (rank == 0) {
62         req = (MPI_Request *) malloc(NUM_LOOPS * sizeof(MPI_Request));
63         for (i = 0; i < NUM_LOOPS; i++)
64             MPI_Issend(snd_buf, 1, newtype, !rank, 0, MPI_COMM_WORLD, &req[i]);
65     }
66     else {
67         for (i = 0; i < NUM_LOOPS; i++)
68             MPI_Recv(rcv_buf, 1, newtype, !rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
69     }
70     MPI_Type_free(&newtype);
71     if (rank == 0)
72         MPI_Waitall(NUM_LOOPS, req, MPI_STATUSES_IGNORE);
73
74     MPI_Barrier(MPI_COMM_WORLD);
75     free(req);
76
77     /* test irsends */
78     MPI_Type_create_indexed_block(count, 1, displs, MPI_INT, &newtype);
79     MPI_Type_commit(&newtype);
80
81     req = (MPI_Request *) malloc(NUM_LOOPS * sizeof(MPI_Request));
82     if (rank == 0) {
83         MPI_Barrier(MPI_COMM_WORLD);
84         for (i = 0; i < NUM_LOOPS; i++)
85             MPI_Irsend(snd_buf, 1, newtype, !rank, 0, MPI_COMM_WORLD, &req[i]);
86     }
87     else {
88         for (i = 0; i < NUM_LOOPS; i++)
89             MPI_Irecv(rcv_buf, 1, newtype, !rank, 0, MPI_COMM_WORLD, &req[i]);
90         MPI_Barrier(MPI_COMM_WORLD);
91     }
92     MPI_Type_free(&newtype);
93     MPI_Waitall(NUM_LOOPS, req, MPI_STATUSES_IGNORE);
94
95     MPI_Barrier(MPI_COMM_WORLD);
96     free(req);
97     free(displs);
98
99     MPI_Finalize();
100
101     if (rank == 0)
102         printf(" No Errors\n");
103
104     return 0;
105 }