Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / isendirecv.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2015 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7
8 #include "mpi.h"
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include "mpitest.h"
12
13 int main(int argc, char *argv[])
14 {
15     int errors = 0;
16     int elems = 20;
17     int rank, nproc, i;
18     float *in_buf, *out_buf;
19     MPI_Comm comm;
20     MPI_Request *reqs;
21
22     MTest_Init(&argc, &argv);
23
24     comm = MPI_COMM_WORLD;
25     MPI_Comm_rank(comm, &rank);
26     MPI_Comm_size(comm, &nproc);
27
28     reqs = (MPI_Request *) malloc(2 * nproc * sizeof(MPI_Request));
29     in_buf = (float *) malloc(elems * nproc * sizeof(float));
30     out_buf = (float *) malloc(elems * nproc * sizeof(float));
31     MTEST_VG_MEM_INIT(out_buf, elems * nproc * sizeof(float));
32
33     for (i = 0; i < nproc; i++) {
34         MPI_Irecv(&in_buf[elems * i], elems, MPI_FLOAT, i, 0, comm, &reqs[i]);
35     }
36
37     for (i = 0; i < nproc; i++) {
38         MPI_Isend(&out_buf[elems * i], elems, MPI_FLOAT, i, 0, comm, &reqs[i + nproc]);
39     }
40
41     MPI_Waitall(nproc * 2, reqs, MPI_STATUSES_IGNORE);
42
43     free(reqs);
44     free(in_buf);
45     free(out_buf);
46     MTest_Finalize(errors);
47     MPI_Finalize();
48     return 0;
49
50 }