Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into adrien
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / bsend2.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include <stdio.h>
7 #include "mpi.h"
8 #include "mpitest.h"
9
10 #define BUFSIZE 2000
11 int main(int argc, char *argv[])
12 {
13     MPI_Status status;
14     int a[10], b[10];
15     int buf[BUFSIZE], *bptr, bl, i, j, rank, size;
16     int errs = 0;
17
18     MTest_Init(0, 0);
19     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
20     MPI_Comm_size(MPI_COMM_WORLD, &size);
21     MPI_Buffer_attach(buf, BUFSIZE);
22
23     for (j = 0; j < 10; j++) {
24         for (i = 0; i < 10; i++) {
25             a[i] = (rank + 10 * j) * size + i;
26         }
27         MPI_Bsend(a, 10, MPI_INT, 0, 27 + j, MPI_COMM_WORLD);
28     }
29     if (rank == 0) {
30
31         for (i = 0; i < size; i++) {
32             for (j = 0; j < 10; j++) {
33                 int k;
34                 status.MPI_TAG = -10;
35                 status.MPI_SOURCE = -20;
36                 MPI_Recv(b, 10, MPI_INT, i, 27 + j, MPI_COMM_WORLD, &status);
37
38                 if (status.MPI_TAG != 27 + j) {
39                     errs++;
40                     printf("Wrong tag = %d\n", status.MPI_TAG);
41                 }
42                 if (status.MPI_SOURCE != i) {
43                     errs++;
44                     printf("Wrong source = %d\n", status.MPI_SOURCE);
45                 }
46                 for (k = 0; k < 10; k++) {
47                     if (b[k] != (i + 10 * j) * size + k) {
48                         errs++;
49                         printf("received b[%d] = %d from %d tag %d\n", k, b[k], i, 27 + j);
50                     }
51                 }
52             }
53         }
54     }
55     MPI_Buffer_detach(&bptr, &bl);
56
57     MTest_Finalize(errs);
58     MPI_Finalize();
59     return 0;
60 }