Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2aaba8229e116fa60c7fab5af2712c37839e7512
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / getfence1.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[] = "Get with Fence";
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     MTestDatatype sendtype, recvtype;
24
25     MTest_Init( &argc, &argv );
26
27     /* The following illustrates the use of the routines to 
28        run through a selection of communicators and datatypes.
29        Use subsets of these for tests that do not involve combinations 
30        of communicators, datatypes, and counts of datatypes */
31     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
32         if (comm == MPI_COMM_NULL) continue;
33         /* Determine the sender and receiver */
34         MPI_Comm_rank( comm, &rank );
35         MPI_Comm_size( comm, &size );
36         source = 0;
37         dest   = size - 1;
38         
39         for (count = 1; count < 65000; count = count * 2) {
40             while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
41                 /* Make sure that everyone has a recv buffer */
42                 recvtype.InitBuf( &recvtype );
43                 sendtype.InitBuf( &sendtype );
44                 /* By default, print information about errors */
45                 recvtype.printErrors = 1;
46                 sendtype.printErrors = 1;
47
48                 MPI_Type_extent( sendtype.datatype, &extent );
49                 MPI_Win_create( sendtype.buf, sendtype.count * extent, 
50                                 (int)extent, MPI_INFO_NULL, comm, &win );
51                 MPI_Win_fence( 0, win );
52                 if (rank == source) {
53                     /* The source does not need to do anything besides the
54                        fence */
55                     MPI_Win_fence( 0, win );
56                 }
57                 else if (rank == dest) {
58                     /* To improve reporting of problems about operations, we
59                        change the error handler to errors return */
60                     MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
61
62                     /* This should have the same effect, in terms of
63                        transfering data, as a send/recv pair */
64                     err = MPI_Get( recvtype.buf, recvtype.count, 
65                                    recvtype.datatype, source, 0, 
66                                    sendtype.count, sendtype.datatype, win );
67                     if (err) {
68                         errs++;
69                         if (errs < 10) {
70                             MTestPrintError( err );
71                         }
72                     }
73                     err = MPI_Win_fence( 0, win );
74                     if (err) {
75                         errs++;
76                         if (errs < 10) {
77                             MTestPrintError( err );
78                         }
79                     }
80                     err = MTestCheckRecv( 0, &recvtype );
81                     if (err) {
82                         errs += err;
83                     }
84                 }
85                 else {
86                     MPI_Win_fence( 0, win );
87                 }
88                 MPI_Win_free( &win );
89                 MTestFreeDatatype( &recvtype );
90                 MTestFreeDatatype( &sendtype );
91             }
92         }
93         MTestFreeComm(&comm);
94     }
95
96     MTest_Finalize( errs );
97     MPI_Finalize();
98     return 0;
99 }