Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
functioning MPI_Comm_get_name, MPI_Comm_set_name
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / getpartelm.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include <string.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTest_descrip[] = "Receive partial datatypes and check that\
14 MPI_Getelements gives the correct version";
15 */
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0;
20     MPI_Datatype outtype, oldtypes[2];
21     MPI_Aint offsets[2];
22     int blklens[2];
23     MPI_Comm comm;
24     int size, rank, src, dest, tag;
25
26     MTest_Init(&argc, &argv);
27
28     comm = MPI_COMM_WORLD;
29
30     MPI_Comm_rank(comm, &rank);
31     MPI_Comm_size(comm, &size);
32
33     if (size < 2) {
34         errs++;
35         printf("This test requires at least 2 processes\n");
36         MPI_Abort(MPI_COMM_WORLD, 1);
37     }
38
39     src = 0;
40     dest = 1;
41
42     if (rank == src) {
43         int buf[128], position, cnt;
44         MTEST_VG_MEM_INIT(buf, 128 * sizeof(buf[0]));
45         /* sender */
46
47         /* Create a datatype and send it (multiple of sizeof(int)) */
48         /* Create a send struct type */
49         oldtypes[0] = MPI_INT;
50         oldtypes[1] = MPI_CHAR;
51         blklens[0] = 1;
52         blklens[1] = 4 * sizeof(int);
53         offsets[0] = 0;
54         offsets[1] = sizeof(int);
55         MPI_Type_struct(2, blklens, offsets, oldtypes, &outtype);
56         MPI_Type_commit(&outtype);
57
58         buf[0] = 4 * sizeof(int);
59         /* printf("About to send to %d\n", dest); */
60         MPI_Send(buf, 1, outtype, dest, 0, comm);
61         MPI_Type_free(&outtype);
62
63         /* Create a datatype and send it (not a multiple of sizeof(int)) */
64         /* Create a send struct type */
65         oldtypes[0] = MPI_INT;
66         oldtypes[1] = MPI_CHAR;
67         blklens[0] = 1;
68         blklens[1] = 4 * sizeof(int) + 1;
69         offsets[0] = 0;
70         offsets[1] = sizeof(int);
71         MPI_Type_struct(2, blklens, offsets, oldtypes, &outtype);
72         MPI_Type_commit(&outtype);
73
74         buf[0] = 4 * sizeof(int) + 1;
75         MPI_Send(buf, 1, outtype, dest, 1, comm);
76         MPI_Type_free(&outtype);
77
78         /* Pack data and send as packed */
79         position = 0;
80         cnt = 7;
81         MPI_Pack(&cnt, 1, MPI_INT, buf, 128 * sizeof(int), &position, comm);
82         MPI_Pack((void *) "message", 7, MPI_CHAR, buf, 128 * sizeof(int), &position, comm);
83         MPI_Send(buf, position, MPI_PACKED, dest, 2, comm);
84     }
85     else if (rank == dest) {
86         MPI_Status status;
87         int buf[128], i, elms, count;
88
89         /* Receiver */
90         /* Create a receive struct type */
91         oldtypes[0] = MPI_INT;
92         oldtypes[1] = MPI_CHAR;
93         blklens[0] = 1;
94         blklens[1] = 256;
95         offsets[0] = 0;
96         offsets[1] = sizeof(int);
97         MPI_Type_struct(2, blklens, offsets, oldtypes, &outtype);
98         MPI_Type_commit(&outtype);
99
100         for (i = 0; i < 3; i++) {
101             tag = i;
102             /* printf("about to receive tag %d from %d\n", i, src); */
103             MPI_Recv(buf, 1, outtype, src, tag, comm, &status);
104             MPI_Get_elements(&status, outtype, &elms);
105             if (elms != buf[0] + 1) {
106                 errs++;
107                 printf("For test %d, Get elements gave %d but should be %d\n", i, elms, buf[0] + 1);
108             }
109             MPI_Get_count(&status, outtype, &count);
110             if (count != MPI_UNDEFINED) {
111                 errs++;
112                 printf("For partial send, Get_count did not return MPI_UNDEFINED\n");
113             }
114         }
115         MPI_Type_free(&outtype);
116     }
117
118     MTest_Finalize(errs);
119     MPI_Finalize();
120     return 0;
121
122 }