Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
test more extensively error returns for collectives.
[simgrid.git] / teshsuite / smpi / coll-allgather / coll-allgather.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   MPI_Init(&argc, &argv);
20   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
21   MPI_Comm_size(MPI_COMM_WORLD, &size);
22
23   int count = 2;
24   int* sb = (int *) xbt_malloc(count * sizeof(int));
25   int* rb = (int *) xbt_malloc(count * size * sizeof(int));
26
27   for (int i = 0; i < count; ++i)
28     sb[i] = rank * count + i;
29   for (int i = 0; i < count * size; ++i)
30     rb[i] = 0;
31
32   status = MPI_Allgather(NULL, count, MPI_INT, rb, count, MPI_INT, MPI_COMM_WORLD);
33   if(status!=MPI_ERR_BUFFER)
34     printf("MPI_Allgather did not return MPI_ERR_BUFFER for empty sendbuf\n");
35   status = MPI_Allgather(sb, -1, MPI_INT, rb, count, MPI_INT, MPI_COMM_WORLD);
36   if(status!=MPI_ERR_COUNT)
37     printf("MPI_Allgather did not return MPI_ERR_COUNT for -1 sendcount\n");
38   status = MPI_Allgather(sb, count, MPI_DATATYPE_NULL, rb, count, MPI_INT, MPI_COMM_WORLD);
39   if(status!=MPI_ERR_TYPE)
40     printf("MPI_Allgather did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL sendtype\n");
41   status = MPI_Allgather(sb, count, MPI_INT, NULL, count, MPI_INT, MPI_COMM_WORLD);
42   if(status!=MPI_ERR_BUFFER)
43     printf("MPI_Allgather did not return MPI_ERR_BUFFER for empty recvbuf\n");
44   status = MPI_Allgather(sb, count, MPI_INT, rb, -1, MPI_INT, MPI_COMM_WORLD);
45   if(status!=MPI_ERR_COUNT)
46     printf("MPI_Allgather did not return MPI_ERR_COUNT for -1 recvcount\n");
47   status = MPI_Allgather(sb, count, MPI_INT, rb, count, MPI_DATATYPE_NULL, MPI_COMM_WORLD);
48   if(status!=MPI_ERR_TYPE)
49     printf("MPI_Allgather did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL recvtype\n");
50   status = MPI_Allgather(sb, count, MPI_INT, rb, count, MPI_INT, MPI_COMM_NULL);
51   if(status!=MPI_ERR_COMM)
52     printf("MPI_Allgather did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
53
54   printf("[%d] sndbuf=[", rank);
55   for (int i = 0; i < count; i++)
56     printf("%d ", sb[i]);
57   printf("]\n");
58
59   status = MPI_Allgather(sb, count, MPI_INT, rb, count, MPI_INT, MPI_COMM_WORLD);
60
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 (rank == 0 && status != MPI_SUCCESS) {
67     printf("allgather returned %d\n", status);
68     fflush(stdout);
69   }
70   xbt_free(sb);
71   xbt_free(rb);
72   MPI_Finalize();
73   return (EXIT_SUCCESS);
74 }