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 / bsendalign.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include <stdio.h>
8 #include "mpi.h"
9 #include "mpitest.h"
10
11 /* Test bsend with a buffer with arbitray alignment */
12 #define BUFSIZE 2000*4
13 int main(int argc, char *argv[])
14 {
15     MPI_Status status;
16     int a[10], b[10];
17     int align;
18     char buf[BUFSIZE + 8], *bptr;
19     int bl, i, j, rank, size;
20     int errs = 0;
21
22     MTest_Init(0, 0);
23     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
24     MPI_Comm_size(MPI_COMM_WORLD, &size);
25     for (align = 0; align < 7; align++) {
26         MPI_Buffer_attach(buf + align, BUFSIZE);
27
28         for (j = 0; j < 10; j++) {
29             for (i = 0; i < 10; i++) {
30                 a[i] = (rank + 10 * j) * size + i;
31             }
32             MPI_Bsend(a, 10, MPI_INT, 0, 27 + j, MPI_COMM_WORLD);
33         }
34         if (rank == 0) {
35
36             for (i = 0; i < size; i++) {
37                 for (j = 0; j < 10; j++) {
38                     int k;
39                     status.MPI_TAG = -10;
40                     status.MPI_SOURCE = -20;
41                     MPI_Recv(b, 10, MPI_INT, i, 27 + j, MPI_COMM_WORLD, &status);
42
43                     if (status.MPI_TAG != 27 + j) {
44                         errs++;
45                         printf("Wrong tag = %d\n", status.MPI_TAG);
46                     }
47                     if (status.MPI_SOURCE != i) {
48                         errs++;
49                         printf("Wrong source = %d\n", status.MPI_SOURCE);
50                     }
51                     for (k = 0; k < 10; k++) {
52                         if (b[k] != (i + 10 * j) * size + k) {
53                             errs++;
54                             printf("(Align=%d) received b[%d] = %d (expected %d) from %d tag %d\n",
55                                    align, k, b[k], (i + 10 * j), i, 27 + j);
56                         }
57                     }
58                 }
59             }
60         }
61         MPI_Buffer_detach(&bptr, &bl);
62         if (bptr != buf + align) {
63             errs++;
64             printf
65                 ("Did not recieve the same buffer on detach that was provided on init (%p vs %p)\n",
66                  bptr, buf);
67         }
68     }
69
70     MTest_Finalize(errs);
71     MPI_Finalize();
72     return 0;
73 }