1 /* Copyright (c) 2012-2014, 2016-2017. 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)
16 int sendcount = 1; // one double to each process
18 double *sndbuf = NULL;
20 int root = 0; // arbitrary choice
22 MPI_Init(&argc, &argv);
23 MPI_Comm_size(MPI_COMM_WORLD, &size);
24 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26 // on root, initialize sendbuf
28 sndbuf = malloc(size * sizeof(double));
29 for (int i = 0; i < size; i++) {
30 sndbuf[i] = (double) i;
34 retval = MPI_Scatter(sndbuf, sendcount, MPI_DOUBLE, &rcvd, recvcount, MPI_DOUBLE, root, MPI_COMM_WORLD);
38 if (retval != MPI_SUCCESS) {
39 fprintf(stderr, "(%s:%d) MPI_Scatter() returned retval=%d\n", __FILE__, __LINE__, retval);
43 if ((double) rank != rcvd) {
44 fprintf(stderr, "[%d] has %f instead of %d\n", rank, rcvd, rank);
50 printf("** Small Test Result: ...\n");
52 printf("\t[%d] failed.\n", rank);
54 printf("\t[%d] ok.\n", rank);