Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / multi_psend_derived.c
1 /*
2  *  (C) 2018 by Argonne National Laboratory.
3  *      See COPYRIGHT in top-level directory.
4  *
5  *  Portions of this code were written by Intel Corporation.
6  *  Copyright (C) 2011-2018 Intel Corporation.  Intel provides this material
7  *  to Argonne National Laboratory subject to Software Grant and Corporate
8  *  Contributor License Agreement dated February 8, 2012.
9  *
10  *  This program checks if MPICH can correctly handle multiple persistent
11  *  communication calls with a derived datatype
12  *
13  */
14
15 #include <mpi.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include "mpitest.h"
19
20 #define ITER 16
21
22 int main(int argc, char *argv[])
23 {
24     int size, rank;
25     int i;
26     MPI_Request req;
27     MPI_Datatype int_dup;
28     int v = 1, errs = 0;
29
30     MTest_Init(&argc, &argv);
31
32     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
33     MPI_Comm_size(MPI_COMM_WORLD, &size);
34
35     if (size != 2) {
36         fprintf(stderr, "Launch with two processes\n");
37         MPI_Abort(MPI_COMM_WORLD, 1);
38     }
39
40     if (rank == 0)
41         MTestPrintfMsg(1, "Test 1: Persistent send - Recv\n");
42
43     if (rank == 0) {
44         MPI_Type_dup(MPI_INT, &int_dup);
45         v = 42;
46         MPI_Send_init(&v, 1, int_dup, 1, 0, MPI_COMM_WORLD, &req);
47         MPI_Type_free(&int_dup);
48         for (i = 0; i < ITER; i++) {
49             MPI_Status s;
50             MPI_Start(&req);
51             MPI_Wait(&req, &s);
52         }
53         MPI_Request_free(&req);
54     } else {
55         for (i = 0; i < ITER; i++) {
56             v = -1;
57             MPI_Recv(&v, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
58             if (v != 42) {
59                 errs++;
60                 fprintf(stderr, "Psend-recv iteration %d: Expected 42 but got %d\n", i, v);
61             }
62         }
63     }
64
65     if (rank == 0)
66         MTestPrintfMsg(1, "Test 2: Send - Persistent recv (with ANY_SOURCE)\n");
67
68     if (rank == 0) {
69         for (i = 0; i < ITER; i++) {
70             v = i;
71             MPI_Send(&v, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
72         }
73     } else {
74         MPI_Type_dup(MPI_INT, &int_dup);
75         MPI_Recv_init(&v, 1, int_dup, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &req);
76         MPI_Type_free(&int_dup);
77         for (i = 0; i < ITER; i++) {
78             MPI_Status s;
79             v = -1;
80             MPI_Start(&req);
81             MPI_Wait(&req, &s);
82             if (v != i) {
83                 errs++;
84                 fprintf(stderr, "Send-precv(anysrc) iteration %d: Expected %d but got %d\n",
85                         i, i, v);
86             }
87         }
88         MPI_Request_free(&req);
89     }
90
91     MTest_Finalize(errs);
92     MPI_Finalize();
93     return MTestReturnValue(errs);
94 }