/* parallel Monte Carlo area calculation */ /* master program */ #include #include #define task 100 /* number of tasks per quadrant */ main() { struct pvmhostinfo *hostp; int bufid, check, dum, htid, nhost, narch, ptid, stid, type; int back[1], done[5], i, j, q, k, min_t, min_q, result; char name[20], name2[20], tmp[2]; double area; ptid = pvm_mytid(); /* get your PVM ID number */ pvm_config( &nhost, &narch, &hostp ); /* configuration of virtual machine */ gethostname(name, 20); printf("The master process runs on %s \n", name); printf("I found the following hosts in your virtual machine\n"); for (i = 0; i < nhost; i++) { printf("\t%s\n", hostp[i].hi_name); } printf("\nStarting slaves\n"); for (i=0; i<4; i++) done[i]=0; /* reset some counters */ i=0; j=0; result=0; do { i++; /* start slaves 1,2,3,4,1,... */ if(i==5) i=1; /* until all machines have a */ strcpy(name, "monteslave"); /* job running */ sprintf(tmp, "%i", i); strcat(name, tmp); check=pvm_spawn(name, 0,PvmTaskHost,hostp[j].hi_name, 1, &stid); if (!check) { printf("Couldn't start process on %s\n", hostp[j].hi_name); nhost--; } else { printf("started slave for quadrant %i on %s\n", i, hostp[j].hi_name); done[i]++; } j++; }while ((j