Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
added smpi to cvs repository. still need to do a lot of integration work.
[simgrid.git] / src / smpi / sample / bcast.c
diff --git a/src/smpi/sample/bcast.c b/src/smpi/sample/bcast.c
new file mode 100644 (file)
index 0000000..2d84c13
--- /dev/null
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <mpi.h>
+
+int main (int argc, char **argv) {
+  int size, rank;
+  int value = 3;
+  MPI_Init(&argc, &argv);
+  MPI_Comm_size(MPI_COMM_WORLD, &size);
+  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+  if (0 == rank) {
+    value = 17;
+  }
+  printf("node %d has value %d\n", rank, value);
+  MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
+  printf("node %d has value %d\n", rank, value);
+  MPI_Finalize();
+  return 0;
+}