Doh! Stupid Programming Mistakes <humor>

Doran Barton fozz at iodynamics.com
Thu Oct 19 11:51:49 MDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nicholas Leippe wrote:
> On Thursday 19 October 2006 11:30, Alex Esplin wrote:
>> Eh?  Somebody wanna enlighten a confused young whippersnapper that has
>> no clue what is going on here but would like to learn something?
> 
>  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);
>         }
>     }
> 
> - The 1st process will execute the loop 10 times, spawning 10 children. Call 
> them generation 1.
> - Each of the 10 generation-1 children continue executing the loop, which at 
> this point has 9 iterations left to go, and thus they each spawn 9 children. 
> Call them generation 2.
> - Each of the 90 generation-2 children continue executing the loop, which at 
> this point now has 8 iterations left to go, and thus they each spawn 8 
> children.
> - etc.

It's actually worse than this since x isn't incremented before the fork() call.

- --
fozz at iodynamics.com is Doran L. Barton, president/CTO, Iodynamics LLC
Iodynamics: IT and Web services by Linux/Open Source specialists
 "We build bodies that last a lifetime."
    -- Seen in a fitness club ad
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFFN7s1fSztmbgzr0ERAp6GAJ95bzgu0q5/8Nb+qHIenudcQbu1PgCfSZDn
J50+6yO+nueU/1lo3VRhTSQ=
=ZsFh
-----END PGP SIGNATURE-----



More information about the PLUG mailing list