The
general approach recommended here is to use the clock variable to define
sequential animation scenes, and then spawn a number of
UNIX processes using the command fork(), each of which calls
a command line with a slightly different POV-ray scripts that are passed
to the system()
command. From within a loop, the function sprintf() can be used to
create the different commands that POV-Ray will use, passing
the +K and +O options the loop
variable for the appropriate animation frames. In the example below,
the character array str[ ] will contain the povray command
with whatever loop variable is being executed.
sprintf (str, "povray +K%d +Ooutfile%d.ppm", loop, loop);If the value of loop = 3,
The following code is from the Cluster How To example developed by the sysadmins from 1999-2000.
/* forktest.c */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <unistd.h> int main(void) { char name[10]; FILE *outfile; unsigned int pnum, i, pid; double b=1, c=1; nice(5); // The command "nice" will run the program at a lower priority for(pnum=0; pnum<16; pnum++) // Loop through 16 processes { /* Fork a duplicate child process that starts running at this location but with the inherited values of the variables. */ switch (pid=fork()) { case -1: /* could not fork */ printf("uh oh.\n"); exit(1); break; case 0: /* child process */ sprintf(name,"file%d",pnum); // Use sprintf to create file name outfile = fopen(name,"w"); // Open file for output fprintf(outfile,"I am process %d\nMy PID is #%d",pnum,getpid()); fclose(outfile); for(i=pnum << 16; pnum+1 << 16; i++) { // Make garbage computations. Use bit shift to make huge numbers b = sin(b*i)+cos(c*i); c = sin(c*i)+cos(b*i); } exit(0); default: /* parent process */ break; } } return 0; }