Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into clean_events
[simgrid.git] / teshsuite / smpi / isp / umpire / partial-recv.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov)  */
3
4 /* type-no-error-exhaustive-with-isends.c -- send with weird types */
5
6 #ifndef lint
7 static char *rcsid =
8   "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/partial-recv.c,v 1.1 2002/10/24 17:04:56 bronis Exp $";
9 #endif
10
11 #include <stdio.h>
12 #include <string.h>
13 #include <assert.h>
14 #include "mpi.h"
15
16
17 typedef struct _test_small_struct_t
18 {
19   double the_double;
20   char the_char;
21 }
22 test_small_struct_t;
23
24
25 typedef struct _test_big_struct_t
26 {
27   double the_double;
28   char the_char;
29   double the_other_double;
30 }
31 test_big_struct_t;
32
33
34 #define SMALL_SIZE  10
35 #define BIG_SIZE    10
36
37 int
38 main (int argc, char **argv)
39 {
40   int nprocs = -1;
41   int rank = -1;
42   MPI_Comm comm = MPI_COMM_WORLD;
43   char processor_name[128];
44   int namelen = 128;
45   int i;
46   MPI_Aint basic_extent;
47   int blocklens[3];
48   MPI_Aint displs[3];
49   MPI_Datatype structtypes[3];
50   MPI_Datatype newtype[2];
51   MPI_Request aReq[2];
52   MPI_Status aStatus[2];
53   test_small_struct_t small_struct_buf[SMALL_SIZE];
54   test_big_struct_t big_struct_buf[BIG_SIZE];
55
56   /* init */
57   MPI_Init (&argc, &argv);
58   MPI_Comm_size (comm, &nprocs);
59   MPI_Comm_rank (comm, &rank);
60   MPI_Get_processor_name (processor_name, &namelen);
61   printf ("(%d) is alive on %s\n", rank, processor_name);
62   fflush (stdout);
63
64   structtypes[0] = MPI_DOUBLE;
65   structtypes[1] = MPI_CHAR;
66   structtypes[2] = MPI_DOUBLE;
67   blocklens[0] = blocklens[1] = blocklens[2] = 1;
68   displs[0] = 0;
69   displs[1] = sizeof(double);
70   displs[2] =
71     ((void *) &(big_struct_buf[0].the_other_double)) -
72     ((void *) big_struct_buf);
73
74   if (displs[2] < 0) displs[2] = -displs[2];
75
76   MPI_Barrier (comm);
77
78   /* create the types */
79   MPI_Type_struct (2, blocklens, displs, structtypes, &newtype[0]);
80   MPI_Type_struct (3, blocklens, displs, structtypes, &newtype[1]);
81
82   MPI_Type_extent (newtype[0], &basic_extent);
83   if (basic_extent != sizeof (test_small_struct_t)) {
84     fprintf (stderr, "(%d): Unexpected extent for small struct\n", rank);
85     MPI_Abort (MPI_COMM_WORLD, 666);
86   }
87
88   MPI_Type_extent (newtype[1], &basic_extent);
89   if (basic_extent != sizeof (test_big_struct_t)) {
90     fprintf (stderr, "(%d): Unexpected extent for big struct\n", rank);
91     MPI_Abort (MPI_COMM_WORLD, 666);
92   }
93
94   MPI_Type_commit (&newtype[0]);
95   MPI_Type_commit (&newtype[1]);
96
97   if (rank == 0) {
98     /* initialize buffers */
99     for (i = 0; i < SMALL_SIZE; i++) {
100       small_struct_buf[i].the_double = 1.0;
101       small_struct_buf[i].the_char = 'a';
102     }
103         
104     for (i = 0; i < BIG_SIZE; i++) {
105       big_struct_buf[i].the_double = 1.0;
106       big_struct_buf[i].the_char = 'a';
107       big_struct_buf[i].the_other_double = 1.0;
108     }
109         
110     /* set up the sends */
111     MPI_Isend (small_struct_buf, 1, newtype[0], 1, 0, comm, &aReq[0]);
112     MPI_Isend (big_struct_buf, 1, newtype[1], 1, 1, comm, &aReq[1]);
113   }
114   else if (rank == 1) {
115     /* initialize buffers */
116     for (i = 0; i < SMALL_SIZE; i++) {
117       small_struct_buf[i].the_double = 2.0;
118       small_struct_buf[i].the_char = 'b';
119     }
120
121     for (i = 0; i < BIG_SIZE; i++) {
122       big_struct_buf[i].the_double = 2.0;
123       big_struct_buf[i].the_char = 'b';
124       big_struct_buf[i].the_other_double = 2.0;
125     }
126
127     /* set up the receives... */
128     MPI_Irecv (big_struct_buf, BIG_SIZE, newtype[1],0,0, comm, &aReq[0]);
129     MPI_Irecv (small_struct_buf, SMALL_SIZE, newtype[0],0,1, comm, &aReq[1]);
130   }
131
132   if ((rank == 0) || (rank == 1)) {
133     /* wait on everything... */
134     MPI_Waitall (2, aReq, aStatus);
135   }
136
137   for (i = 0; i < 2; i++) {
138     MPI_Type_free (&newtype[i]);
139   }
140
141   MPI_Barrier (comm);
142
143   printf ("(%d) Finished normally\n", rank);
144   MPI_Finalize ();
145 }
146
147 /* EOF */