Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix tests for shared and partial-shared.
[simgrid.git] / teshsuite / smpi / coll-alltoallv / coll-alltoallv.c
1 /* Copyright (c) 2013-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 /*
8  *  (C) 2001 by Argonne National Laboratory.
9  *      See COPYRIGHT in top-level directory.
10  */
11 #include <string.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include "mpi.h"
15
16 /* This program tests MPI_Alltoallv by having processor i send different amounts of data to each processor.
17
18    TODO As there are separate send and receive types to alltoallv, there need to be tests to rearrange data on the fly.
19    The first test sends i items to processor i from all processors.
20    Currently, the test uses only MPI_INT; this is adequate for testing systems that use point-to-point operations
21
22    Example values for 3 processes:
23  * <0> sbuf: (#9):   [0][1][2][3][4][5][6][7][8]
24    <0> scount: (#3): [0][1][2]
25    <0> rcount: (#3): [0][0][0]
26    <0> sdisp: (#3):  [0][1][3]
27    <0> rdisp: (#3):  [0][0][0]
28
29    <1> sbuf: (#9):   [100][101][102][103][104][105][106][107][108]
30    <1> scount: (#3): [0][1][2]
31    <1> rcount: (#3): [1][1][1]
32    <1> sdisp: (#3):  [0][1][3]
33    <1> rdisp: (#3):  [0][1][2]
34
35    <2> sbuf: (#9):   [200][201][202][203][204][205][206][207][208]
36    <2> scount: (#3): [0][1][2]
37    <2> rcount: (#3): [2][2][2]
38    <2> sdisp: (#3):  [0][1][3]
39    <2> rdisp: (#3):  [0][2][4]
40
41    after MPI_Alltoallv :
42    <0> rbuf: (#9):   [-1][-1][-1][-1][-1][-1][-1][-1][-1]
43    <1> rbuf: (#9):   [1][101][201][-1][-1][-1][-1][-1][-1]
44    <2> rbuf: (#9):   [3][4][103][104][203][204][-1][-1][-1]
45 */
46
47 static void print_buffer_int(void *buf, int len, char *msg, int rank)
48 {
49   int* v;
50   printf("[%d] %s (#%d): ", rank, msg, len);
51   for (int tmp = 0; tmp < len; tmp++) {
52     v = buf;
53     printf("[%d]", v[tmp]);
54   }
55   printf("\n");
56   free(msg);
57 }
58
59 int main(int argc, char **argv)
60 {
61   MPI_Comm comm;
62   int i;
63   int rank;
64   int size;
65   int *sendcounts, *recvcounts, *rdispls, *sdispls;
66
67   MPI_Init(&argc, &argv);
68
69   comm = MPI_COMM_WORLD;
70
71   /* Create the buffer */
72   MPI_Comm_size(comm, &size);
73   MPI_Comm_rank(comm, &rank);
74   int* sbuf = (int *) xbt_malloc(size * size * sizeof(int));
75   int* rbuf = (int *) xbt_malloc(size * size * sizeof(int));
76
77   /* Load up the buffers */
78   for (i = 0; i < size * size; i++) {
79     sbuf[i] = i + 100 * rank;
80     rbuf[i] = -1;
81   }
82
83   /* Create and load the arguments to alltoallv */
84   sendcounts = (int *) xbt_malloc(size * sizeof(int));
85   recvcounts = (int *) xbt_malloc(size * sizeof(int));
86   rdispls = (int *) xbt_malloc(size * sizeof(int));
87   sdispls = (int *) xbt_malloc(size * sizeof(int));
88   for (i = 0; i < size; i++) {
89     sendcounts[i] = i;
90     recvcounts[i] = rank;
91     rdispls[i] = i * rank;
92     sdispls[i] = (i * (i + 1)) / 2;
93   }
94
95   print_buffer_int( sbuf, size*size, strdup("sbuf:"),rank);
96   print_buffer_int( sendcounts, size, strdup("scount:"),rank);
97   print_buffer_int( recvcounts, size, strdup("rcount:"),rank);
98   print_buffer_int( sdispls, size, strdup("sdisp:"),rank);
99   print_buffer_int( rdispls, size, strdup("rdisp:"),rank);
100
101   MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT, rbuf, recvcounts, rdispls, MPI_INT, comm);
102
103   print_buffer_int( rbuf, size*size, strdup("rbuf:"),rank);
104
105   MPI_Barrier(MPI_COMM_WORLD);  
106   if (0 == rank) {
107     printf("Alltoallv TEST COMPLETE.\n");
108   }
109   free(sdispls);
110   free(rdispls);
111   free(recvcounts);
112   free(sendcounts);
113   free(rbuf);
114   free(sbuf);
115
116   MPI_Finalize();
117   return 0;
118 }