Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / tresized2.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 <stdlib.h>
10 #include "mpitest.h"
11
12 /*
13 static char MTEST_Descrip[] = "Test of type resized with non-zero LB";
14 */
15
16 int main(int argc, char *argv[])
17 {
18     int errs = 0, i;
19     int rank, size, source, dest;
20     int count;
21     int *buf;
22     MPI_Comm comm;
23     MPI_Status status;
24     MPI_Datatype newtype;
25
26     MTest_Init(&argc, &argv);
27
28     comm = MPI_COMM_WORLD;
29
30     /* Determine the sender and receiver */
31     MPI_Comm_rank(comm, &rank);
32     MPI_Comm_size(comm, &size);
33     source = 0;
34     dest = size - 1;
35
36     /* Create an type that is "* INT * "
37      * that is, there is a int-sized pad at the beginning of the type,
38      * and the extent is still 3 ints.  Note, however, that the INT
39      * is still at displacement 0, so the effective pattern i */
40     MPI_Type_create_resized(MPI_INT, -(int) sizeof(int), 3 * sizeof(int), &newtype);
41     MPI_Type_commit(&newtype);
42     for (count = 1; count < 65000; count = count * 2) {
43         buf = (int *) malloc(count * 3 * sizeof(int));
44         if (!buf) {
45             MPI_Abort(comm, 1);
46         }
47         for (i = 0; i < 3 * count; i++)
48             buf[i] = -1;
49         if (rank == source) {
50             for (i = 0; i < count; i++)
51                 buf[3 * i] = i;
52             MPI_Send(buf, count, newtype, dest, 0, comm);
53             MPI_Send(buf, count, newtype, dest, 1, comm);
54         }
55         else if (rank == dest) {
56             MPI_Recv(buf, count, MPI_INT, source, 0, comm, &status);
57             for (i = 0; i < count; i++) {
58                 if (buf[i] != i) {
59                     errs++;
60                     if (errs < 10) {
61                         printf("buf[%d] = %d\n", i, buf[i]);
62                     }
63                 }
64             }
65             for (i = 0; i < count * 3; i++)
66                 buf[i] = -1;
67             MPI_Recv(buf, count, newtype, source, 1, comm, &status);
68             for (i = 0; i < count; i++) {
69                 if (buf[3 * i] != i) {
70                     errs++;
71                     if (errs < 10) {
72                         printf("buf[3*%d] = %d\n", i, buf[i]);
73                     }
74                 }
75             }
76         }
77         free(buf);
78     }
79     MPI_Type_free(&newtype);
80
81     MTest_Finalize(errs);
82     MPI_Finalize();
83     return 0;
84 }