Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[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;
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) continue;
34         /* Determine the sender and receiver */
35         MPI_Comm_rank( comm, &rank );
36         MPI_Comm_size( comm, &size );
37         source = 0;
38         dest   = size - 1;
39         
40         for (count = 1; count < 65000; count = count * 2) {
41             while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
42                 /* Make sure that everyone has a recv buffer */
43                 recvtype.InitBuf( &recvtype );
44
45                 MPI_Type_extent( recvtype.datatype, &extent );
46                 MPI_Win_create( recvtype.buf, recvtype.count * extent, 
47                                 (int)extent, MPI_INFO_NULL, comm, &win );
48                 MPI_Win_get_group( win, &wingroup );
49                 if (rank == source) {
50                     /* To improve reporting of problems about operations, we
51                        change the error handler to errors return */
52                     MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
53                     sendtype.InitBuf( &sendtype );
54                     
55                     /* Neighbor is dest only */
56                     MPI_Group_incl( wingroup, 1, &dest, &neighbors );
57                     err = MPI_Win_start( neighbors, 0, win );
58                     if (err) {
59                         errs++;
60                         if (errs < 10) {
61                             MTestPrintError( err );
62                         }
63                     }
64                     MPI_Group_free( &neighbors );
65                     err = MPI_Put( sendtype.buf, sendtype.count, 
66                                     sendtype.datatype, dest, 0, 
67                                    recvtype.count, recvtype.datatype, win );
68                     if (err) {
69                         errs++;
70                         MTestPrintError( err );
71                     }
72                     err = MPI_Win_complete( win );
73                     if (err) {
74                         errs++;
75                         if (errs < 10) {
76                             MTestPrintError( err );
77                         }
78                     }
79                 }
80                 else if (rank == dest) {
81                     MPI_Group_incl( wingroup, 1, &source, &neighbors );
82                     MPI_Win_post( neighbors, 0, win );
83                     MPI_Group_free( &neighbors );
84                     MPI_Win_wait( win );
85                     /* This should have the same effect, in terms of
86                        transfering data, as a send/recv pair */
87                     err = MTestCheckRecv( 0, &recvtype );
88                     if (err) {
89                         errs += errs;
90                     }
91                 }
92                 else {
93                     /* Nothing; the other processes need not call any 
94                        MPI routines */
95                     ;
96                 }
97                 MPI_Win_free( &win );
98                 MTestFreeDatatype( &sendtype );
99                 MTestFreeDatatype( &recvtype );
100                 MPI_Group_free( &wingroup );
101             }
102         }
103         MTestFreeComm( &comm );
104     }
105
106     MTest_Finalize( errs );
107     MPI_Finalize();
108     return 0;
109 }