Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ignore generated tesh files
[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   int comm = MPI_COMM_WORLD;
43   char processor_name[128];
44   int namelen = 128;
45   int i, basic_extent;
46   int blocklens[3], displs[3];
47   MPI_Datatype structtypes[3]; 
48   MPI_Datatype newtype[2]; 
49   MPI_Request aReq[2];
50   MPI_Status aStatus[2];
51   test_small_struct_t small_struct_buf[SMALL_SIZE];
52   test_big_struct_t big_struct_buf[BIG_SIZE];
53
54   /* init */
55   MPI_Init (&argc, &argv);
56   MPI_Comm_size (comm, &nprocs);
57   MPI_Comm_rank (comm, &rank);
58   MPI_Get_processor_name (processor_name, &namelen);
59   printf ("(%d) is alive on %s\n", rank, processor_name);
60   fflush (stdout);
61
62   structtypes[0] = MPI_DOUBLE;
63   structtypes[1] = MPI_CHAR;
64   structtypes[2] = MPI_DOUBLE;
65   blocklens[0] = blocklens[1] = blocklens[2] = 1;
66   displs[0] = 0;
67   displs[1] = sizeof(double);
68   displs[2] = 
69     ((void *) &(big_struct_buf[0].the_other_double)) - 
70     ((void *) big_struct_buf);
71
72   if (displs[2] < 0) displs[2] = -displs[2];
73
74   MPI_Barrier (comm);
75
76   /* create the types */
77   MPI_Type_struct (2, blocklens, displs, structtypes, &newtype[0]);
78   MPI_Type_struct (3, blocklens, displs, structtypes, &newtype[1]);
79   
80   MPI_Type_extent (newtype[0], &basic_extent);
81   if (basic_extent != sizeof (test_small_struct_t)) {
82     fprintf (stderr, "(%d): Unexpected extent for small struct\n");
83     MPI_Abort (MPI_COMM_WORLD, 666);
84   }
85   
86   MPI_Type_extent (newtype[1], &basic_extent);
87   if (basic_extent != sizeof (test_big_struct_t)) {
88     fprintf (stderr, "(%d): Unexpected extent for big struct\n");
89     MPI_Abort (MPI_COMM_WORLD, 666);
90   }
91
92   MPI_Type_commit (&newtype[0]);
93   MPI_Type_commit (&newtype[1]);
94
95   if (rank == 0) {
96     /* initialize buffers */
97     for (i = 0; i < SMALL_SIZE; i++) {
98       small_struct_buf[i].the_double = 1.0;
99       small_struct_buf[i].the_char = 'a';
100     }
101         
102     for (i = 0; i < BIG_SIZE; i++) {
103       big_struct_buf[i].the_double = 1.0;
104       big_struct_buf[i].the_char = 'a';
105       big_struct_buf[i].the_other_double = 1.0;
106     }
107         
108     /* set up the sends */
109     MPI_Isend (small_struct_buf, 1, newtype[0], 1, 0, comm, &aReq[0]);
110     MPI_Isend (big_struct_buf, 1, newtype[1], 1, 1, comm, &aReq[1]);
111   }
112   else if (rank == 1) {
113     /* initialize buffers */
114     for (i = 0; i < SMALL_SIZE; i++) {
115       small_struct_buf[i].the_double = 2.0;
116       small_struct_buf[i].the_char = 'b';
117     }
118
119     for (i = 0; i < BIG_SIZE; i++) {
120       big_struct_buf[i].the_double = 2.0;
121       big_struct_buf[i].the_char = 'b';
122       big_struct_buf[i].the_other_double = 2.0;
123     }
124
125     /* set up the receives... */
126     MPI_Irecv (big_struct_buf, BIG_SIZE, newtype[1],0,0, comm, &aReq[0]);
127     MPI_Irecv (small_struct_buf, SMALL_SIZE, newtype[0],0,1, comm, &aReq[1]);
128   }
129
130   if ((rank == 0) || (rank == 1)) {
131     /* wait on everything... */
132     MPI_Waitall (2, aReq, aStatus);
133   }
134
135   for (i = 0; i < 2; i++) {
136     MPI_Type_free (&newtype[i]);
137   }
138
139   MPI_Barrier (comm);
140
141   printf ("(%d) Finished normally\n", rank);
142   MPI_Finalize ();
143 }
144
145 /* EOF */