1 /* Copyright (c) 2012-2014. 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
19 double *sndbuf = NULL;
21 int root = 0; // arbitrary choice
23 MPI_Init(&argc, &argv);
24 MPI_Comm_size(MPI_COMM_WORLD, &size);
25 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
27 // on root, initialize sendbuf
29 sndbuf = malloc(size * sizeof(double));
30 for (i = 0; i < size; i++) {
31 sndbuf[i] = (double) i;
35 retval = MPI_Scatter(sndbuf, sendcount, MPI_DOUBLE, &rcvd, recvcount, MPI_DOUBLE, root, MPI_COMM_WORLD);
39 if (retval != MPI_SUCCESS) {
40 fprintf(stderr, "(%s:%d) MPI_Scatter() returned retval=%d\n", __FILE__, __LINE__, retval);
44 if ((double) rank != rcvd) {
45 fprintf(stderr, "[%d] has %f instead of %d\n", rank, rcvd, rank);
51 printf("** Small Test Result: ...\n");
53 printf("\t[%d] failed.\n", rank);
55 printf("\t[%d] ok.\n", rank);