Doh! Stupid Programming Mistakes <humor>

Nicholas Leippe nick at leippe.com
Thu Oct 19 12:30:10 MDT 2006


On Thursday 19 October 2006 11:51, Doran Barton wrote:
> 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);
> >         }
> >     }
> >

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

Hrm. You've pointed out a big error in what I said, but it becomes not as bad.
The first process starts 10 children, but x is set to 10, 9, 8, ... 1 in each 
of them respectively (not 10 in each as I said before). Thus the 1st child 
then spawns 9, the 2nd 8, etc.

The result is only 2^x total processes.  Still a fork bomb, regardless.





More information about the PLUG mailing list