Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Free memory.
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / huge_underflow.c
1
2 /*
3  *  (C) 2017 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  *
6  *  Portions of this code were written by Intel Corporation.
7  *  Copyright (C) 2011-2017 Intel Corporation.  Intel provides this material
8  *  to Argonne National Laboratory subject to Software Grant and Corporate
9  *  Contributor License Agreement dated February 8, 2012.
10  *
11  *  This program checks if MPICH can correctly handle a huge message receive
12  *  when the sender underflows by sending a much smaller message
13  *
14  */
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <memory.h>
19 #include <mpi.h>
20
21 #define HUGE_SIZE (10*1024*1024)
22
23 int main(int argc, char *argv[])
24 {
25     int size, rank;
26     int dest;
27     char *buff;
28
29     MPI_Init(&argc, &argv);
30
31     buff = malloc(HUGE_SIZE);
32     buff[0] = 0;
33
34     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
35     MPI_Comm_size(MPI_COMM_WORLD, &size);
36
37     dest = size - 1;
38
39     /* Try testing underflow to make sure things work if we try to send 1 byte
40      * when receiving a huge message */
41     if (rank == 0) {
42         MPI_Send(buff, 1, MPI_BYTE, dest, 0, MPI_COMM_WORLD);
43     } else if (rank == dest) {
44         MPI_Recv(buff, HUGE_SIZE, MPI_BYTE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
45     }
46
47     free(buff);
48
49     MPI_Barrier(MPI_COMM_WORLD);
50
51     if (rank == 0)
52         puts(" No Errors");
53
54     MPI_Finalize();
55
56     return 0;
57 }