Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
finally activate all weird modes of allpairf(90)
[simgrid.git] / teshsuite / smpi / coll-gather / coll-gather.c
1 /* Copyright (c) 2009-2019. 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 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <errno.h>
11 #include "mpi.h"
12
13 int main(int argc, char *argv[])
14 {
15   int rank;
16   int size;
17   int status;
18
19   int root = 0;
20
21   MPI_Init(&argc, &argv);
22   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
23   MPI_Comm_size(MPI_COMM_WORLD, &size);
24
25   int count = 2;
26   int* sb = (int *) xbt_malloc(count * sizeof(int));
27   int* rb = (int *) xbt_malloc(count * size * sizeof(int));
28
29   for (int i = 0; i < count; ++i)
30     sb[i] = rank * count + i;
31   for (int i = 0; i < count * size; ++i)
32     rb[i] = 0;
33
34   printf("[%d] sndbuf=[", rank);
35   for (int i = 0; i < count; i++)
36     printf("%d ", sb[i]);
37   printf("]\n");
38
39   status = MPI_Gather(NULL, count, MPI_INT, rb, count, MPI_INT, root, MPI_COMM_WORLD);
40   if(status!=MPI_ERR_BUFFER)
41     printf("MPI_Gather did not return MPI_ERR_BUFFER for empty sendbuf\n");
42   status = MPI_Gather(sb, -1, MPI_INT, rb, count, MPI_INT, root, MPI_COMM_WORLD);
43   if(status!=MPI_ERR_COUNT)
44     printf("MPI_Gather did not return MPI_ERR_COUNT for -1 sendcount\n");
45   status = MPI_Gather(sb, count, MPI_DATATYPE_NULL, rb, count, MPI_INT, root, MPI_COMM_WORLD);
46   if(status!=MPI_ERR_TYPE)
47     printf("MPI_Gather did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL sendtype\n");
48   status = MPI_Gather(sb, count, MPI_INT, rb, count, MPI_INT, -1, MPI_COMM_WORLD);
49   if(status!=MPI_ERR_ROOT)
50     printf("MPI_Gather did not return MPI_ERR_ROOT for root -1\n");
51   status = MPI_Gather(sb, count, MPI_INT, rb, count, MPI_INT, size+1, MPI_COMM_WORLD);
52   if(status!=MPI_ERR_ROOT)
53     printf("MPI_Gather did not return MPI_ERR_ROOT for root > size\n");
54   status = MPI_Gather(sb, count, MPI_INT, rb, count, MPI_INT, root, MPI_COMM_NULL);
55   if(status!=MPI_ERR_COMM)
56     printf("MPI_Gather did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
57
58   status = MPI_Gather(sb, count, MPI_INT, rb, count, MPI_INT, root, MPI_COMM_WORLD);
59
60   if (rank == root) {
61     printf("[%d] rcvbuf=[", rank);
62     for (int i = 0; i < count * size; i++)
63       printf("%d ", rb[i]);
64     printf("]\n");
65
66     if (status != MPI_SUCCESS) {
67       printf("gather returned %d\n", status);
68       fflush(stdout);
69     }
70   }
71   xbt_free(sb);
72   xbt_free(rb);
73   MPI_Barrier(MPI_COMM_WORLD);
74   MPI_Finalize();
75   return (EXIT_SUCCESS);
76 }