Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
handle nested datatypes in smpi (structs of vectors for example), which previously...
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / dtyperecv.c
1
2 /*
3 > so, my second question:
4
5 >   2. what is the output of that MPI program?
6
7 > i think it should be 42 -1 42 -1.
8
9 > but compiling with mpich-1.1.0 an running on solaris machines
10 > (ch_p4) writes : 42 -1 42 0.
11
12 > thanks,
13 >     Holger
14
15 > MPI code:
16 > -------------------------------------------------------
17 */
18 #include "test.h"
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include "mpi.h"
22
23 int main( int argc, char **argv )
24 {
25   int my_rank, i, data[6];
26   MPI_Status  status;
27   MPI_Datatype  my_type;
28   int errs = 0, toterrs;
29
30   MPI_Init(&argc, &argv);
31   MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
32
33   MPI_Type_vector(2, 1, 2, MPI_INT, &my_type);
34   MPI_Type_commit(&my_type);
35
36   if (my_rank == 0) {
37     data[0]=42;data[1]=42;
38     MPI_Send(&(data[0]), 2, MPI_INT, 1, 42, MPI_COMM_WORLD);
39   } else {
40     for (i=0; i<6; i++)
41       data[i] = -1;
42     MPI_Recv(&(data[0]), 2, my_type, 0, 42, MPI_COMM_WORLD, &status);
43     /* Check for correct receipt */
44     if (data[0] != 42 || data[1] != -1 || data[2] != 42 || data[3] != -1 
45         || data[4] != -1 || data[5] != -1) {
46         errs++;
47         for (i=0; i<4; i++)
48             printf("%i ",data[i]);
49         printf("\n");
50     }
51   }
52   MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
53   if (my_rank == 0) {
54       if (toterrs > 0) printf( "Found %d errors\n", toterrs );
55       else             printf( " No Errors\n" );
56   }
57
58   MPI_Type_free( &my_type );
59   MPI_Finalize();
60   return 0;
61 }