1 /* Copyright (c) 2009-2023. The SimGrid Team.
2 * All rights reserved. */
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. */
13 int main(int argc, char *argv[])
21 MPI_Init(&argc, &argv);
22 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
23 MPI_Comm_size(MPI_COMM_WORLD, &size);
24 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
27 int* sb = (int *) xbt_malloc(count * sizeof(int));
28 int* rb = (int *) xbt_malloc(count * size * sizeof(int));
30 for (int i = 0; i < count; ++i)
31 sb[i] = rank * count + i;
32 for (int i = 0; i < count * size; ++i)
35 printf("[%d] sndbuf=[", rank);
36 for (int i = 0; i < count; i++)
40 status = MPI_Gather(NULL, count, MPI_INT, rb, count, MPI_INT, root, MPI_COMM_WORLD);
41 if(status!=MPI_ERR_BUFFER)
42 printf("MPI_Gather did not return MPI_ERR_BUFFER for empty sendbuf\n");
43 status = MPI_Gather(sb, -1, MPI_INT, rb, count, MPI_INT, root, MPI_COMM_WORLD);
44 if(status!=MPI_ERR_COUNT)
45 printf("MPI_Gather did not return MPI_ERR_COUNT for -1 sendcount\n");
46 status = MPI_Gather(sb, count, MPI_DATATYPE_NULL, rb, count, MPI_INT, root, MPI_COMM_WORLD);
47 if(status!=MPI_ERR_TYPE)
48 printf("MPI_Gather did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL sendtype\n");
49 status = MPI_Gather(sb, count, MPI_INT, rb, count, MPI_INT, -1, MPI_COMM_WORLD);
50 if(status!=MPI_ERR_ROOT)
51 printf("MPI_Gather did not return MPI_ERR_ROOT for root -1\n");
52 status = MPI_Gather(sb, count, MPI_INT, rb, count, MPI_INT, size+1, MPI_COMM_WORLD);
53 if(status!=MPI_ERR_ROOT)
54 printf("MPI_Gather did not return MPI_ERR_ROOT for root > size\n");
55 status = MPI_Gather(sb, count, MPI_INT, rb, count, MPI_INT, root, MPI_COMM_NULL);
56 if(status!=MPI_ERR_COMM)
57 printf("MPI_Gather did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
59 status = MPI_Gather(sb, count, MPI_INT, rb, count, MPI_INT, root, MPI_COMM_WORLD);
62 printf("[%d] rcvbuf=[", rank);
63 for (int i = 0; i < count * size; i++)
67 if (status != MPI_SUCCESS) {
68 printf("gather returned %d\n", status);
74 MPI_Barrier(MPI_COMM_WORLD);