0
votes

I am using MPI to run a program in parallel and measure the execution time. I am currently splitting the computation between each process by giving a start and end index as a parameter in the "voxelise" function. This will then work on different sections of the data set and store the result in "p_voxel_data".

I then want to send all of these sub arrays to the root process using "MPI_Gather" so the data can be written to a file and the timer stopped.

The program executes fine when i have the "MPI_Gather" line commented out, i get output similar to this:

Computing time: NODE 3 = 1.07 seconds.
Computing time: NODE 2 = 1.12 seconds.

But when that line is included i get

"APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)

And also the computing time for the root node 0 shows up as a minus number "-1.40737e+08" Can anyone suggest any issues in my call to MPI_Gather?

int main(int argc, char** argv)
//-----------------------------
{
    int rank;
    int nprocs;
    MPI_Comm comm; 
    MPI::Init(argc, argv);
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    /* Set up data for voxelise function */
    . . . . . .

    clock_t start(clock());

    // Generate the density field
    voxelise(density_function,
        a,
        b,
        p_control_point_set,
        p_voxel_data,
        p_number_of_voxel,
        p_voxel_size,
        p_centre,
    begin,
        endInd  );

    std::vector<float> completeData(512);
    std::vector<float> cpData(toProcess);
    std::copy(p_voxel_data.begin() + begin, p_voxel_data.begin() + endInd, cpData.begin());

    MPI_Gather(&cpData, toProcess, MPI::FLOAT, &completeData, toProcess, MPI::FLOAT, 0, MPI_COMM_WORLD);

    // Stop the timer
    clock_t end(clock());

    float number_of_seconds(float(end - start) / CLOCKS_PER_SEC);

    std::cout << "Computing time:\t" << "NODE " << rank << " = " << number_of_seconds << " seconds." <<std::endl;
    if(rank == 0) {

    MPI::Finalize();
    return (EXIT_SUCCESS);
}
1

1 Answers

1
votes

You are giving MPI_Gather address to vector object, not address to vector data. You must do:

MPI_Gather(&cpData[0], toProcess, MPI::FLOAT, &completeData[0], ...

Of course you have to make sure sizes are correct too.