Doh! Stupid Programming Mistakes <humor>

Corey Edwards tensai at zmonkey.org
Thu Oct 19 12:24:00 MDT 2006


On Thu, 2006-10-19 at 11:55 -0600, Jacob Fugal wrote:
> void main (int argc, char *argv[])
> {
>    int myrank, size,x;
> 
>    MPI_Init(&argc, &argv);                 /* Initialize MPI       */
> 
>    for(x = 0; x < 10; x++){
>        if(fork() > 0){
>                MPI_Comm_rank(MPI_COMM_WORLD, &myrank); /* Get my rank
>         */
>                MPI_Comm_size(MPI_COMM_WORLD, &size);   /* Get the
> total number of
> processors */
>                printf("Processor %d of %d: Running!\n", myrank, size);
>                return;
>        }
>    }
>    MPI_Finalize();                         /* Terminate MPI        */
> }
> 
> There's no need for a parent flag because each child terminates
> immediately after doing its chores. And only the parent will ever make
> it all the way through the for loop and execute the MPI_Finalize call.

That depends on what exactly MPI is. From the code I get the impression
that it's a library that handles parallel execution, in which case the
whole point is to have multiple processes fork off and remain running.
If that's the case I believe my code is correct. It could also be that
each child is supposed to run MPI_Finalize, signalling that it has
exited and should no longer be included in the process pool. Googling
around for MPI seems to indicate something along those lines.

In the general case, you are correct.

Corey

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : http://plug.org/pipermail/plug/attachments/20061019/cf20f9d2/attachment.bin 


More information about the PLUG mailing list