Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update RMA tests
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / putpscw1.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Put with Post/Start/Complete/Wait";
13 */
14
15 int main(int argc, char *argv[])
16 {
17     int errs = 0, err;
18     int rank, size, source, dest;
19     int minsize = 2, count;
20     MPI_Comm comm;
21     MPI_Win win;
22     MPI_Aint extent, lb;
23     MPI_Group wingroup, neighbors;
24     MTestDatatype sendtype, recvtype;
25
26     MTest_Init(&argc, &argv);
27
28     /* The following illustrates the use of the routines to
29      * run through a selection of communicators and datatypes.
30      * Use subsets of these for tests that do not involve combinations
31      * of communicators, datatypes, and counts of datatypes */
32     while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
33         if (comm == MPI_COMM_NULL)
34             continue;
35         /* Determine the sender and receiver */
36         MPI_Comm_rank(comm, &rank);
37         MPI_Comm_size(comm, &size);
38         source = 0;
39         dest = size - 1;
40
41         MTEST_DATATYPE_FOR_EACH_COUNT(count) {
42             while (MTestGetDatatypes(&sendtype, &recvtype, count)) {
43                 /* Make sure that everyone has a recv buffer */
44                 recvtype.InitBuf(&recvtype);
45
46                 MPI_Type_extent(recvtype.datatype, &extent);
47                 MPI_Type_lb(recvtype.datatype, &lb);
48                 MPI_Win_create(recvtype.buf, recvtype.count * extent + lb,
49                                (int) extent, MPI_INFO_NULL, comm, &win);
50                 MPI_Win_get_group(win, &wingroup);
51                 if (rank == source) {
52                     /* To improve reporting of problems about operations, we
53                      * change the error handler to errors return */
54                     MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN);
55                     sendtype.InitBuf(&sendtype);
56
57                     /* Neighbor is dest only */
58                     MPI_Group_incl(wingroup, 1, &dest, &neighbors);
59                     err = MPI_Win_start(neighbors, 0, win);
60                     if (err) {
61                         errs++;
62                         if (errs < 10) {
63                             MTestPrintError(err);
64                         }
65                     }
66                     MPI_Group_free(&neighbors);
67                     err = MPI_Put(sendtype.buf, sendtype.count,
68                                   sendtype.datatype, dest, 0,
69                                   recvtype.count, recvtype.datatype, win);
70                     if (err) {
71                         errs++;
72                         MTestPrintError(err);
73                     }
74                     err = MPI_Win_complete(win);
75                     if (err) {
76                         errs++;
77                         if (errs < 10) {
78                             MTestPrintError(err);
79                         }
80                     }
81                 }
82                 else if (rank == dest) {
83                     MPI_Group_incl(wingroup, 1, &source, &neighbors);
84                     MPI_Win_post(neighbors, 0, win);
85                     MPI_Group_free(&neighbors);
86                     MPI_Win_wait(win);
87                     /* This should have the same effect, in terms of
88                      * transfering data, as a send/recv pair */
89                     err = MTestCheckRecv(0, &recvtype);
90                     if (err) {
91                         errs += errs;
92                     }
93                 }
94                 else {
95                     /* Nothing; the other processes need not call any
96                      * MPI routines */
97                     ;
98                 }
99                 MPI_Win_free(&win);
100                 MTestFreeDatatype(&sendtype);
101                 MTestFreeDatatype(&recvtype);
102                 MPI_Group_free(&wingroup);
103             }
104         }
105         MTestFreeComm(&comm);
106     }
107
108     MTest_Finalize(errs);
109     MPI_Finalize();
110     return 0;
111 }