Commit f5eb3478 authored by Thomas White's avatar Thomas White
Browse files

render_hkl: Run multiple POV-ray instances in parallel

parent 680991c5
...@@ -27,13 +27,17 @@ ...@@ -27,13 +27,17 @@
#include "reflections.h" #include "reflections.h"
#define MAX_PROC (256)
static void show_help(const char *s) static void show_help(const char *s)
{ {
printf("Syntax: %s [options] <file.hkl>\n\n", s); printf("Syntax: %s [options] <file.hkl>\n\n", s);
printf( printf(
"Render intensity lists using POVray.\n" "Render intensity lists using POV-ray.\n"
"\n" "\n"
" -h, --help Display this help message.\n" " -h, --help Display this help message.\n"
" -j <n> Run <n> instances of POV-ray in parallel.\n"
"\n"); "\n");
} }
...@@ -50,8 +54,10 @@ int main(int argc, char *argv[]) ...@@ -50,8 +54,10 @@ int main(int argc, char *argv[])
double asx, asy, asz; double asx, asy, asz;
double bsx, bsy, bsz; double bsx, bsy, bsz;
double csx, csy, csz; double csx, csy, csz;
pid_t pid; pid_t pids[MAX_PROC];
float max; float max;
int nproc = 1;
int i;
/* Long options */ /* Long options */
const struct option longopts[] = { const struct option longopts[] = {
...@@ -60,7 +66,7 @@ int main(int argc, char *argv[]) ...@@ -60,7 +66,7 @@ int main(int argc, char *argv[])
}; };
/* Short options */ /* Short options */
while ((c = getopt_long(argc, argv, "h", longopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, "hj:", longopts, NULL)) != -1) {
switch (c) { switch (c) {
case 'h' : { case 'h' : {
...@@ -68,6 +74,11 @@ int main(int argc, char *argv[]) ...@@ -68,6 +74,11 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
case 'j' : {
nproc = atoi(optarg);
break;
}
case 0 : { case 0 : {
break; break;
} }
...@@ -79,6 +90,11 @@ int main(int argc, char *argv[]) ...@@ -79,6 +90,11 @@ int main(int argc, char *argv[])
} }
if ( (nproc > MAX_PROC) || (nproc < 1) ) {
ERROR("Number of processes is invalid.\n");
return 1;
}
infile = argv[optind]; infile = argv[optind];
cell = load_cell_from_pdb("molecule.pdb"); cell = load_cell_from_pdb("molecule.pdb");
...@@ -276,21 +292,38 @@ int main(int argc, char *argv[]) ...@@ -276,21 +292,38 @@ int main(int argc, char *argv[])
fprintf(fh, "\n"); fprintf(fh, "\n");
fclose(fh); fclose(fh);
pid = fork(); for ( i=0; i<nproc; i++ ) {
if ( !( (pid != 0) && (pid != -1) ) ) {
if ( pid == -1 ) { pids[i] = fork();
fprintf(stderr, "fork() failed.\n"); if ( !( (pids[i] != 0) && (pids[i] != -1) ) ) {
} else { if ( pids[i] == -1 ) {
/* Forked successfully, child process */ ERROR("fork() failed.\n");
execlp("povray", "", "+W320", "+H240", } else {
"+Irender.pov", "+Orender.png",
"+KFI0", "+KFF499", "+KI0", "+KF499", char minf[256];
// "+SF220", "+EF280", char maxf[256];
NULL); int nf, xf, nsec;
}
} else { nsec = 500 / nproc;
nf = nsec * i;
xf = (nsec * i + nsec)-1;
snprintf(minf, 255, "+SF%i", nf);
snprintf(maxf, 255, "+EF%i", xf);
/* Forked successfully, child process */
execlp("povray", "", "+W1024", "+H768",
"+Irender.pov", "+Orender.png",
"+KFI0", "+KFF499", "+KI0", "+KF499",
minf, maxf, NULL);
}
} /* else start the next one */
}
for ( i=0; i<nproc; i++ ) {
int r; int r;
waitpid(pid, &r, 0); waitpid(pids[i], &r, 0);
} }
return 0; return 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment