Doh! Stupid Programming Mistakes <humor>
Corey Edwards
tensai at zmonkey.org
Thu Oct 19 08:07:26 MDT 2006
On Thu, 2006-10-19 at 05:40 -0600, Steve wrote:
> 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);
> }
> }
>
> This code looks harmless at first glance, but turns out it is idiotic,
> however it took me a full on hour to figure out why.
> Anyone wanna guess whats wrong?
I guess you forked off 10! (3,628,800) processes. We like to call that a
fork bomb.
Let's see. You could probably do this:
int x, parent = 1;
for (x = 0; x < 10; x++){
if (parent && !fork()){
parent = 0;
MPI_stuff();
}
}
}
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/0bb43229/attachment.bin
More information about the PLUG
mailing list