1 /* Copyright (c) 2009-2019. 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. */
10 int main(int argc, char **argv)
18 MPI_Init(&argc, &argv);
19 MPI_Comm_size(MPI_COMM_WORLD, &size);
20 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
21 MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
23 int *values = (int *) xbt_malloc(count * sizeof(int));
25 for (i = 0; i < count; i++)
26 values[i] = (0 == rank) ? 17 : 3;
28 status = MPI_Bcast(NULL, count, MPI_INT, 0, MPI_COMM_WORLD);
29 if(status!=MPI_ERR_BUFFER)
30 printf("MPI_Bcast did not return MPI_ERR_BUFFER for empty sendbuf\n");
31 status = MPI_Bcast(values, -1, MPI_INT, 0, MPI_COMM_WORLD);
32 if(status!=MPI_ERR_COUNT)
33 printf("MPI_Bcast did not return MPI_ERR_COUNT for -1 sendcount\n");
34 status = MPI_Bcast(values, count, MPI_DATATYPE_NULL, 0, MPI_COMM_WORLD);
35 if(status!=MPI_ERR_TYPE)
36 printf("MPI_Bcast did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL sendtype\n");
37 status = MPI_Bcast(values, count, MPI_INT, -1, MPI_COMM_WORLD);
38 if(status!=MPI_ERR_ROOT)
39 printf("MPI_Bcast did not return MPI_ERR_ROOT for -1 root\n");
40 status = MPI_Bcast(values, count, MPI_INT, size, MPI_COMM_WORLD);
41 if(status!=MPI_ERR_ROOT)
42 printf("MPI_Bcast did not return MPI_ERR_ROOT for root > size\n");
43 status = MPI_Bcast(values, count, MPI_INT, 0, MPI_COMM_NULL);
44 if(status!=MPI_ERR_COMM)
45 printf("MPI_Bcast did not return MPI_ERR_COMM for MPI_COMM_NULL comm\n");
47 MPI_Bcast(values, count, MPI_INT, 0, MPI_COMM_WORLD);
50 for (i = 0; i < count; i++)
51 if (values[i]==17) good++;
52 printf("[%d] number of values equals to 17: %d\n", rank, good);
54 MPI_Barrier(MPI_COMM_WORLD);
58 values = (int *) xbt_malloc(count * sizeof(int));
60 for (i = 0; i < count; i++)
61 values[i] = (size -1 == rank) ? 17 : 3;
63 status = MPI_Bcast(values, count, MPI_INT, size-1, MPI_COMM_WORLD);
66 for (i = 0; i < count; i++)
67 if (values[i]==17) good++;
68 printf("[%d] number of values equals to 17: %d\n", rank, good);
70 if (rank == 0 && status != MPI_SUCCESS) {
71 printf("bcast returned %d\n", status);