Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
57dbbdd3dccc469ccf658781eadbdc50ba1c6ddb
[simgrid.git] / teshsuite / smpi / coll-allgather / coll-allgather.c
1 /* Copyright (c) 2009-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <errno.h>
10 #include "mpi.h"
11
12 int main(int argc, char *argv[])
13 {
14   int rank;
15   int size;
16   int status;
17
18   MPI_Init(&argc, &argv);
19   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
20   MPI_Comm_size(MPI_COMM_WORLD, &size);
21
22   int count = 2;
23   int* sb = (int *) xbt_malloc(count * sizeof(int));
24   int* rb = (int *) xbt_malloc(count * size * sizeof(int));
25
26   for (int i = 0; i < count; ++i)
27     sb[i] = rank * count + i;
28   for (int i = 0; i < count * size; ++i)
29     rb[i] = 0;
30
31   status = MPI_Allgather(NULL, count, MPI_INT, rb, count, MPI_INT, MPI_COMM_WORLD);
32   if(status!=MPI_ERR_BUFFER)
33     printf("MPI_Allgather did not return MPI_ERR_BUFFER for empty sendbuf\n");
34   status = MPI_Allgather(sb, -1, MPI_INT, rb, count, MPI_INT, MPI_COMM_WORLD);
35   if(status!=MPI_ERR_COUNT)
36     printf("MPI_Allgather did not return MPI_ERR_COUNT for -1 sendcount\n");
37   status = MPI_Allgather(sb, count, MPI_DATATYPE_NULL, rb, count, MPI_INT, MPI_COMM_WORLD);
38   if(status!=MPI_ERR_TYPE)
39     printf("MPI_Allgather did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL sendtype\n");
40   status = MPI_Allgather(sb, count, MPI_INT, NULL, count, MPI_INT, MPI_COMM_WORLD);
41   if(status!=MPI_ERR_BUFFER)
42     printf("MPI_Allgather did not return MPI_ERR_BUFFER for empty recvbuf\n");
43   status = MPI_Allgather(sb, count, MPI_INT, rb, -1, MPI_INT, MPI_COMM_WORLD);
44   if(status!=MPI_ERR_COUNT)
45     printf("MPI_Allgather did not return MPI_ERR_COUNT for -1 recvcount\n");
46   status = MPI_Allgather(sb, count, MPI_INT, rb, count, MPI_DATATYPE_NULL, MPI_COMM_WORLD);
47   if(status!=MPI_ERR_TYPE)
48     printf("MPI_Allgather did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL recvtype\n");
49   status = MPI_Allgather(sb, count, MPI_INT, rb, count, MPI_INT, MPI_COMM_NULL);
50   if(status!=MPI_ERR_COMM)
51     printf("MPI_Allgather did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
52
53   printf("[%d] sndbuf=[", rank);
54   for (int i = 0; i < count; i++)
55     printf("%d ", sb[i]);
56   printf("]\n");
57
58   status = MPI_Allgather(sb, count, MPI_INT, rb, count, MPI_INT, MPI_COMM_WORLD);
59
60   printf("[%d] rcvbuf=[", rank);
61   for (int i = 0; i < count * size; i++)
62     printf("%d ", rb[i]);
63   printf("]\n");
64
65   if (rank == 0 && status != MPI_SUCCESS) {
66     printf("allgather returned %d\n", status);
67     fflush(stdout);
68   }
69   xbt_free(sb);
70   xbt_free(rb);
71   MPI_Finalize();
72   return (EXIT_SUCCESS);
73 }