So.... I"m trying to use MPI_Bcast because it seems like the easiest way to take a multidimensional array (the full program has a 3-d one all filled out) and make it available to every process. The code below, however, does not work... 'grid' holds nothing but 0s when accessed from a child process. (Example: "Proc 1 has found 0, Proc 0 has found 600 ").
Anyone know how to properly do this?
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include "mpi.h"
using namespace std;
int grid[10][10][1];
main (int argc, char* argv[]) {
int procID, nproc;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &procID);
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
int root = 0;
if(procID == root) {
grid[0][0][0] = 600;
printf("Proc %i has found %i \n", procID, grid[0][0][0]);
MPI_Bcast(&grid, 200, MPI_INT, root, MPI_COMM_WORLD);
}
else {
printf("Proc %i has found %i \n", procID, grid[0][0][0]);
}
MPI_Finalize();
}