Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / dtypelife.c
1 /*
2  * Program to test that datatypes that are freed with MPI_TYPE_FREE
3  * are not actually deleted until communication that they are a part of
4  * has completed.
5  *
6  */
7
8 #include <stdio.h>
9 #include "test.h"
10 #include "mpi.h"
11
12 #define SIZE 10000
13 static int src  = 1;
14 static int dest = 0;
15
16 /* Prototypes for picky compilers */
17 void Generate_Data ( int *, int );
18
19 void Generate_Data(buffer, buff_size)
20 int *buffer;
21 int buff_size;
22 {
23     int i;
24
25     for (i = 0; i < buff_size; i++)
26         buffer[i] = i+1;
27 }
28
29 int main( int argc, char **argv)
30 {
31     int rank; /* My Rank (0 or 1) */
32     int tag, count, i, errcnt = 0;
33     MPI_Request handle;
34     double data[100];
35     MPI_Status status;
36     MPI_Datatype rowtype;
37
38     MPI_Init(&argc, &argv);
39     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
40
41     tag    = 2001;
42     count  = 1;
43     for (i = 0; i < 100; i++)
44         data[i] = i;
45     MPI_Type_vector( 10, 1, 10, MPI_DOUBLE, &rowtype );
46     MPI_Type_commit( &rowtype );
47     if (rank == src) { 
48         MPI_Irecv(data, count, rowtype, dest, tag, MPI_COMM_WORLD,
49                  &handle ); 
50         MPI_Type_free( &rowtype );
51         MPI_Recv( (void *)0, 0, MPI_INT, dest, tag+1, 
52                   MPI_COMM_WORLD, &status );
53         MPI_Wait( &handle, &status );
54         /* Check for correct data */
55         for (i = 0; i < 10; i++) if (data[i*10] != i*10) {
56             errcnt++;
57             fprintf( stderr, 
58                     "[%d](rcv row-row) %d'th element = %f, should be %f\n",
59                      rank, i, data[i*10], 10.0*i );
60             }
61
62     } else if (rank == dest) {
63         MPI_Send( (void *)0, 0, MPI_INT, src, tag+1, MPI_COMM_WORLD );
64         /* By using an Ssend first, we make sure that the Irecv doesn't
65            match until after the type has been freed */
66         MPI_Isend( data, count, rowtype, src, tag, MPI_COMM_WORLD, 
67                   &handle );
68         MPI_Type_free( &rowtype );
69         MPI_Wait( &handle, &status );
70         }
71
72     i = errcnt;
73     MPI_Allreduce( &i, &errcnt, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
74     if (errcnt > 0) {
75         printf( "Found %d errors in the run\n", errcnt );
76         }
77     Test_Waitforall( );
78     MPI_Finalize();
79
80     return 0;
81 }
82
83
84