Question

I'm trying to build a multi-process raytracer for my undergraduate Senior Project using OpenMPI so I can run it on my school's supercomputer.

I got it to the point where the code compiles fine and runs fine until I reach the line

MPI_Gather(subscn,w*rows,MPI_BYTE,&scn,w*rows,MPI_BYTE,0,MPI_COMM_WORLD);

My question is what the problem with this line is, as it causes my program to either segfault or causes one of (so far) up to 5 different assertion errors depending on the number of processes I run with or the scene I am attempting to render.

The function in question, with unneccesary printf() statements removed.

int main(int argc, char **argv) {
init_MPI(argc, argv);

if (argc == 2) {
    string arg1 = argv[1];
    if (arg1 == "--help" || arg1 == "-?") print_help_message();
}

glutInit(&argc,argv);

bool OK = get_params(argc, argv);

Ray cam;
if (buildScene(scene, cam) == -1) {
    MPI_Abort(MPI_COMM_WORLD,rc);
    exit(1);
}
if (tid == MASTER) scn.initNewRGBApixmap(w,h);  /* RGBA pixel map to display */

int rows = h / numprocs;
RGBA *subscn = new RGBA[w*rows];
samples = samples > 0 ? whitted ? 1 : samples : 1;

MPI_Barrier(MPI_COMM_WORLD);            /* Synchronize all processes */
rtrace_time = 0.0 - MPI_Wtime();        /* Begin timer */

MPI_Scatter(&scn,w*rows,MPI_BYTE,subscn,w*rows,MPI_BYTE,0,MPI_COMM_WORLD);

raytrace(cam, rows, subscn);

MPI_Gather(subscn,w*rows,MPI_BYTE,&scn,w*rows,MPI_BYTE,0,MPI_COMM_WORLD);

MPI_Barrier(MPI_COMM_WORLD);            /* Synchronize all processes */
rtrace_time += MPI_Wtime();             /* End timer */

if (tid == MASTER) {
    initGlut(argc, argv);
    glutMainLoop();
}

MPI_Finalize();
return 0;
}

The function init_MPI(argc,argv) is as follows:

void init_MPI(int argc, char **argv) {
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&tid);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
if (numprocs < 2) {
    printf("\nError: At least two MPI tasks must be created. Exiting.\n");
    MPI_Abort(MPI_COMM_WORLD,rc);
    exit(1);
} else if (numprocs > MAX_PROCS) {
    printf("\nError: More than %d MPI tasks started. Exiting.\n",MAX_PROCS);
    MPI_Abort(MPI_COMM_WORLD,rc);
    exit(1);
}

}

Was it helpful?

Solution

Thanks to Hristo Iliev for his comments. As it turns out I was using two different data types in my call to MPI_Gather().

Revised code is as follows:

int main(int argc, char **argv) {
init_MPI(argc, argv);

if (argc == 2) {
    string arg1 = argv[1];
    if (arg1 == "--help" || arg1 == "-?") print_help_message();
}

glutInit(&argc,argv);

bool OK = get_params(argc, argv);

Ray cam;
if (buildScene(scene, cam) == -1) {
    MPI_Abort(MPI_COMM_WORLD,rc);
    exit(1);
}
if (pid == MASTER) scn = new RGBApixmap[w*h];

int rows = h / numprocs;
RGBApixmap *subscn = new RGBApixmap[w*rows];
samples = samples > 0 ? whitted ? 1 : samples : 1;

MPI_Barrier(MPI_COMM_WORLD);            /* Synchronize all processes */
rtrace_time = 0.0 - MPI_Wtime();        /* Begin timer */

raytrace(cam, rows, subscn);

MPI_Gather(subscn,w*rows,MPI_BYTE,scn,w*rows,MPI_BYTE,0,MPI_COMM_WORLD);

MPI_Barrier(MPI_COMM_WORLD);            /* Synchronize all processes */
rtrace_time += MPI_Wtime();             /* End timer */

if (pid == MASTER) {
    initGlut(argc, argv);
    glutMainLoop();
}

MPI_Finalize();
return 0;
}

So the lesson here is to always check your datatypes and ensure that you're not using different classes in MPI Scatter and Gather.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top