Hi, your program hangs because rank 0 does not call MPI_Bcast()
generally speaking, when using collective operations (such as MPI_Bcast), all tasks of the communicators must invoke the collective operation, and with "matching" arguments. in the case of MPI_Bcast(), the root value must be the same on all tasks, and all tasks must transfer the same amount of data : if all tasks use the same datatype, then the count must be the same on all tasks, otherwise, the datatype size * count must be the same on all tasks /* for the sake of completion, there are known issues specific to Open MPI when you mix large and small datatypes */ Cheers, Gilles ----- Original Message ----- > Greetings! > > I include a static header file utils.h with a function linspace. My main.cpp file is as follows: > > #include <iostream> > #include <utils.h> > #include <mpi.h> > > using namespace std; > > int main(int argc, const char * argv[]) { > > float start = 0., end = 1.; > unsigned long int num = 100; > > double *linspaced; > > float delta = (end - start) / num; > int size, rank; > > > MPI_Init(NULL, NULL); > > MPI_Comm_size(MPI_COMM_WORLD, &size); > MPI_Comm_rank(MPI_COMM_WORLD, &rank); > MPI_Status status; > > // These have to be converted into unsigned long ints > int casesPerNode = num / size; > int remainderCases = num % size; > > > if(rank==0){ > linspaced = new double[num]; > > if(remainderCases!=0){ > linspace(&linspaced[(size-1)*casesPerNode], end - delta* remainderCases, end, remainderCases); > > } else { > linspace(&linspaced[(size-1)*casesPerNode], end - delta* casesPerNode, end, casesPerNode); > > } > > } else { > > MPI_Bcast(&linspaced, num, MPI_DOUBLE, 0, MPI_COMM_WORLD); > > > // Sending job to master node. > // The node is already overloaded with coordinating. > // Additional task now is also to take on remainder cases. > > > // cout << "Rank " << rank << endl; > float start_in = start + casesPerNode*delta*(rank-1); > float end_in = start + casesPerNode*delta*(rank) - delta; > > linspace(&linspaced[(rank-1)*casesPerNode], start_in, end_in, casesPerNode); > > > } > > MPI_Barrier(MPI_COMM_WORLD); > // cout << "Print Here Rank " << rank << endl ; > > > MPI_Finalize(); > > /* > for(int i=0; i< num; i++){ > cout << *(linspaced + i) << endl; > } > */ > > return 0; > > } > and my utils.h file is: > > void linspace(double *ret, double start_in, double end_in, unsigned long int num_in) > { > /* This function generates equally spaced elements and returns > an array with the results */ > > > assert(num_in!=0); > > > cout << "\tReceived start :" << start_in << "\tEnd :" << end_in < < "\tNum_in :" << num_in << endl; > > double delta_in = (end_in - start_in) / (num_in - 1); > > if(num_in == 1){ > *(ret) = start_in; > } > > *(ret) = start_in; > for(int i=1; i < num_in-1; i++) { > *(ret + i) = *(ret + i - 1) + delta_in; > } > *(ret + (num_in - 1)) = end_in; > > /* > cout << "Finished executing linspace " << endl; > for(int i = 0; i<num_in; i++){ > cout << "Address : " << &ret << "\tElement " << i << " : " << *( ret + i) << endl; > } > */ > } > I am unable to diagnose why my code gets stuck at MPI_Bcast. What could I do to fix it? > > Thanks > > > PS: I’m new to OpenMPI and may have a lot of these doubts initially. Thanks for patience and support. > _______________________________________________ > users mailing list > users@lists.open-mpi.org > https://rfd.newmexicoconsortium.org/mailman/listinfo/users _______________________________________________ users mailing list users@lists.open-mpi.org https://rfd.newmexicoconsortium.org/mailman/listinfo/users