Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / datatype / large_vec.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2014 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 /* tests non-contig send/recv of a message > 2GB. count=270M, type=long long
12    run with 3 processes to exercise both shared memory and TCP in Nemesis tests*/
13
14 int main(int argc, char *argv[])
15 {
16     int i, size, rank;
17     int elems = 270000000;
18     MPI_Status status;
19     MPI_Datatype dtype;
20     long long *cols;
21     int errs = 0;
22
23
24     MTest_Init(&argc, &argv);
25
26     /* need large memory */
27     if (sizeof(void *) < 8) {
28         MTest_Finalize(errs);
29         MPI_Finalize();
30         return 0;
31     }
32
33     MPI_Comm_size(MPI_COMM_WORLD, &size);
34     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
35     if (size != 3) {
36         fprintf(stderr, "[%d] usage: mpiexec -n 3 %s\n", rank, argv[0]);
37         MPI_Abort(MPI_COMM_WORLD, 1);
38     }
39
40     cols = malloc(elems * sizeof(long long));
41     if (cols == NULL) {
42         printf("malloc of >2GB array failed\n");
43         errs++;
44         MTest_Finalize(errs);
45         MPI_Finalize();
46         return 0;
47     }
48
49     MPI_Type_vector(elems / 2, 1, 2, MPI_LONG_LONG_INT, &dtype);
50     MPI_Type_commit(&dtype);
51
52     if (rank == 0) {
53         for (i = 0; i < elems; i++)
54             cols[i] = i;
55         /* printf("[%d] sending...\n",rank); */
56         MPI_Send(cols, 1, dtype, 1, 0, MPI_COMM_WORLD);
57         MPI_Send(cols, 1, dtype, 2, 0, MPI_COMM_WORLD);
58     }
59     else {
60         /* printf("[%d] receiving...\n",rank); */
61         for (i = 0; i < elems; i++)
62             cols[i] = -1;
63         MPI_Recv(cols, 1, dtype, 0, 0, MPI_COMM_WORLD, &status);
64         /* MPI_Get_count(&status,MPI_LONG_LONG_INT,&cnt);
65          * Get_count still fails because count is not 64 bit */
66         for (i = 0; i < elems; i++) {
67             if (i % 2)
68                 continue;
69             if (cols[i] != i) {
70                 printf("Rank %d, cols[i]=%lld, should be %d\n", rank, cols[i], i);
71                 errs++;
72             }
73         }
74     }
75
76     MPI_Type_free(&dtype);
77     free(cols);
78
79     MTest_Finalize(errs);
80     MPI_Finalize();
81     return 0;
82 }