Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / eagerdt.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2006 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include "mpi.h"
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Test of a large number of derived-datatype messages eagerly, with no preposted receive so that an MPI implementation may have to queue up messages on the sending side";
13 */
14
15 #define MAX_MSGS 30
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0;
20     int rank, size, dest, source;
21     int i, indices[40];
22     MPI_Aint extent;
23     int *buf, *bufs[MAX_MSGS];
24     MPI_Comm comm;
25     MPI_Datatype dtype;
26     MPI_Request req[MAX_MSGS];
27
28     MTest_Init(&argc, &argv);
29
30     comm = MPI_COMM_WORLD;
31     MPI_Comm_rank(comm, &rank);
32     MPI_Comm_size(comm, &size);
33     source = 0;
34     dest = size - 1;
35
36     /* Setup by creating a blocked datatype that is likely to be processed
37      * in a piecemeal fashion */
38     for (i = 0; i < 30; i++) {
39         indices[i] = i * 40;
40     }
41
42     /* 30 blocks of size 10 */
43     MPI_Type_create_indexed_block(30, 10, indices, MPI_INT, &dtype);
44     MPI_Type_commit(&dtype);
45
46     /* Create the corresponding message buffers */
47     MPI_Type_extent(dtype, &extent);
48     for (i = 0; i < MAX_MSGS; i++) {
49         bufs[i] = (int *) malloc(extent);
50         if (!bufs[i]) {
51             fprintf(stderr, "Unable to allocate buffer %d of size %ld\n", i, (long) extent);
52             MPI_Abort(MPI_COMM_WORLD, 1);
53         }
54         MTEST_VG_MEM_INIT(bufs[i], extent);
55     }
56     buf = (int *) malloc(10 * 30 * sizeof(int));
57
58     MPI_Barrier(MPI_COMM_WORLD);
59     if (rank == dest) {
60         MTestSleep(2);
61         for (i = 0; i < MAX_MSGS; i++) {
62             MPI_Recv(buf, 10 * 30, MPI_INT, source, i, comm, MPI_STATUS_IGNORE);
63         }
64     }
65     else if (rank == source) {
66         for (i = 0; i < MAX_MSGS; i++) {
67             MPI_Isend(bufs[i], 1, dtype, dest, i, comm, &req[i]);
68         }
69         MPI_Waitall(MAX_MSGS, req, MPI_STATUSES_IGNORE);
70     }
71
72     MPI_Type_free(&dtype);
73     for (i = 0; i < MAX_MSGS; i++) {
74         free(bufs[i]);
75     }
76     free(buf);
77     MTest_Finalize(errs);
78     MPI_Finalize();
79     return 0;
80 }