Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change include order for smpi tests/examples to avoid conflicts
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / eagerdt.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2006 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Test of a large number of derived-datatype messages eagerly, with no preposted receive so that an MPI implementation may have to queue up messages on the sending side";
13 */
14
15 #define MAX_MSGS 30
16
17 int main( int argc, char *argv[] )
18 {
19     int errs = 0;
20     int rank, size, dest, source;
21     int i, indices[40];
22     MPI_Aint extent;
23     int *buf, *bufs[MAX_MSGS];
24     MPI_Comm      comm;
25     MPI_Datatype  dtype;
26     MPI_Request   req[MAX_MSGS];
27
28     MTest_Init( &argc, &argv );
29
30     comm = MPI_COMM_WORLD;
31     MPI_Comm_rank( comm, &rank );
32     MPI_Comm_size( comm, &size );
33     source = 0;
34     dest   = size - 1;
35     
36     /* Setup by creating a blocked datatype that is likely to be processed
37        in a piecemeal fashion */
38     for (i=0; i<30; i++) {
39         indices[i] = i*40;
40     }
41
42     /* 30 blocks of size 10 */
43     MPI_Type_create_indexed_block( 30, 10, indices, MPI_INT, &dtype );
44     MPI_Type_commit( &dtype );
45     
46     /* Create the corresponding message buffers */
47     MPI_Type_extent( dtype, &extent );
48     for (i=0; i<MAX_MSGS; i++) {
49         bufs[i] = (int *)malloc( extent );
50         if (!bufs[i]) {
51             fprintf( stderr, "Unable to allocate buffer %d of size %ld\n", 
52                         i, (long)extent );
53             MPI_Abort( MPI_COMM_WORLD, 1 );
54             exit(1);
55         }
56     }
57     buf = (int *)malloc( 10 * 30 * sizeof(int) );
58     
59     MPI_Barrier( MPI_COMM_WORLD );
60     if (rank == dest) {
61         MTestSleep( 2 );
62         for (i=0; i<MAX_MSGS; i++) {
63             MPI_Recv( buf, 10*30, MPI_INT, source, i, comm, 
64                       MPI_STATUS_IGNORE );
65         }
66     }
67     else if (rank == source ) {
68         for (i=0; i<MAX_MSGS; i++) {
69             MPI_Isend( bufs[i], 1, dtype, dest, i, comm, &req[i] );
70         }
71         MPI_Waitall( MAX_MSGS, req, MPI_STATUSES_IGNORE );
72     }
73
74     MPI_Type_free( &dtype );
75     MTest_Finalize( errs );
76     MPI_Finalize();
77     return 0;
78 }