Commit 8aae3789 authored by Chuck's avatar Chuck
Browse files

Multiprocess indexamajig

parent 98250896
......@@ -46,3 +46,4 @@ build-aux/missing
build-aux/config.guess
build-aux/depcomp
build-aux/ltmain.sh
/nbproject/private/
\ No newline at end of file
......@@ -50,6 +50,35 @@
#include "reax.h"
#include "geometry.h"
#ifdef HAVE_CLOCK_GETTIME
#include <time.h>
#else
#include <sys/time.h>
#endif
#ifdef HAVE_CLOCK_GETTIME
static double get_time()
{
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
double sec = (double) tp.tv_sec+ (double) tp.tv_nsec/1000000000;
return sec; //nano resolution
}
#else
/* Fallback version of the above. The time according to gettimeofday() is not
* monotonic, so measuring intervals based on it will screw up if there's a
* timezone change (e.g. daylight savings) while the program is running. */
static double get_time()
{
struct timeval tp;
gettimeofday(&tp, NULL);
double sec = (double) tp.tv_sec+ (double) tp.tv_usec/1000000;
return sec; //micro resolution
}
#endif
/* Base class constructor for unspecialised indexing private data */
IndexingPrivate *indexing_private(IndexingMethod indm)
......@@ -159,6 +188,8 @@ void index_pattern(struct image *image, UnitCell *cell, IndexingMethod *indm,
int cellr, int verbose, IndexingPrivate **ipriv,
int config_insane, float *ltl)
{
//double t1,t2;
//t1 = get_time();
int i;
int n = 0;
......@@ -167,6 +198,9 @@ void index_pattern(struct image *image, UnitCell *cell, IndexingMethod *indm,
map_all_peaks(image);
image->indexed_cell = NULL;
double tDI,tDO;
double tMI,tMO;
while ( indm[n] != INDEXING_NONE ) {
image->ncells = 0;
......@@ -176,10 +210,16 @@ void index_pattern(struct image *image, UnitCell *cell, IndexingMethod *indm,
case INDEXING_NONE :
return;
case INDEXING_DIRAX :
tDI = get_time();
run_dirax(image);
tDO = get_time();
ERROR("run_dirax DONE %.2f %.2f %.2f\n",tDI,tDO,tDO-tDI);
break;
case INDEXING_MOSFLM :
tMI = get_time();
run_mosflm(image, cell);
tMO = get_time();
ERROR("run_mosflm DONE %.2f %.2f %.5f\n",tMI,tMO,tMO-tMI);
break;
case INDEXING_REAX :
reax_index(ipriv[n], image, cell);
......@@ -251,6 +291,8 @@ done:
/* May free(NULL) if all algorithms were tried and no success */
cell_free(image->candidate_cells[i]);
}
//t2 = get_time();
//ERROR("index_pattern DONE %.2f %.2f %.5f\n",t1,t2,t2-t1);
}
......
......@@ -82,6 +82,37 @@
#include "peaks.h"
#ifdef HAVE_CLOCK_GETTIME
#include <time.h>
#else
#include <sys/time.h>
#endif
#ifdef HAVE_CLOCK_GETTIME
static double get_time()
{
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
double sec = (double) tp.tv_sec+ (double) tp.tv_nsec/1000000000;
return sec; //nano resolution
}
#else
/* Fallback version of the above. The time according to gettimeofday() is not
* monotonic, so measuring intervals based on it will screw up if there's a
* timezone change (e.g. daylight savings) while the program is running. */
static double get_time()
{
struct timeval tp;
gettimeofday(&tp, NULL);
double sec = (double) tp.tv_sec+ (double) tp.tv_usec/1000000;
return sec; //micro resolution
}
#endif
#define MOSFLM_VERBOSE 0
......@@ -358,6 +389,7 @@ static void mosflm_send_next(struct image *image, struct mosflm_data *mosflm)
break;
case 10 :
//ERROR(">>>>>>>>>>>>>> OK\n");
mosflm_sendline("GO\n", mosflm);
mosflm->finished_ok = 1;
break;
......@@ -376,12 +408,12 @@ static int mosflm_readable(struct image *image, struct mosflm_data *mosflm)
{
int rval;
int no_string = 0;
//ERROR("read pty: %d %d %d ===",mosflm->pty,mosflm->rbuffer+mosflm->rbufpos, (int) mosflm->rbuflen-mosflm->rbufpos);
rval = read(mosflm->pty, mosflm->rbuffer+mosflm->rbufpos,
mosflm->rbuflen-mosflm->rbufpos);
//ERROR("read val: %d\n",rval);
if ( (rval == -1) || (rval == 0) ) return 1;
//ERROR("Enter here\n");
mosflm->rbufpos += rval;
assert(mosflm->rbufpos <= mosflm->rbuflen);
......@@ -436,7 +468,7 @@ static int mosflm_readable(struct image *image, struct mosflm_data *mosflm)
break;
case MOSFLM_INPUT_PROMPT :
//ERROR("Enter mosflm_send_next\n");
mosflm_send_next(image, mosflm);
endbit_length = i+7;
break;
......@@ -512,14 +544,16 @@ void run_mosflm(struct image *image, UnitCell *cell)
snprintf(mosflm->newmatfile, 127, "xfel-%i.newmat", image->id);
remove(mosflm->newmatfile);
// fork a new process operating in pseudoterminal
mosflm->pid = forkpty(&mosflm->pty, NULL, NULL, NULL);
//ERROR("forkpty: %d\n",mosflm->pid);
if ( mosflm->pid == -1 ) {
ERROR("Failed to fork for MOSFLM\n");
free(mosflm);
return;
}
if ( mosflm->pid == 0 ) {
if ( mosflm->pid == 0 ) { // child process
//ERROR("Enter the dragon\n");
/* Child process: invoke MOSFLM */
struct termios t;
......@@ -545,32 +579,61 @@ void run_mosflm(struct image *image, UnitCell *cell)
mosflm->step = 1; /* This starts the "initialisation" procedure */
mosflm->finished_ok = 0;
//double t1,t2,t3,t4,t5,t6,t7;
//t1 = get_time();
do {
//t2 = get_time();
fd_set fds;
struct timeval tv;
int sval;
//t3 = get_time();
FD_ZERO(&fds);
FD_SET(mosflm->pty, &fds);
FD_SET(mosflm->pty, &fds); // file descriptor set
//t4 = get_time();
tv.tv_sec = 30;
tv.tv_sec = 30; // 30 second timeout
tv.tv_usec = 0;
sval = select(mosflm->pty+1, &fds, NULL, NULL, &tv);
//t5 = get_time();
//sval = 1;
sval = select(mosflm->pty+1, &fds, NULL, NULL, &tv); // is mosflm ready for reading?
if (sval != 1){
ERROR("******************* sval: %d ",sval);
}
//t6 = get_time();
if ( sval == -1 ) {
int err = errno;
ERROR("select() failed: %s\n", strerror(err));
rval = 1;
} else if ( sval != 0 ) {
rval = mosflm_readable(image, mosflm);
//ERROR("mosflm_readable: %d %d %d ===",mosflm->pty,mosflm->rbuffer+mosflm->rbufpos, (int) mosflm->rbuflen-mosflm->rbufpos);
rval = mosflm_readable(image, mosflm); // read mosflm results
} else {
ERROR("No response from MOSFLM..\n");
rval = 1;
}
//if (sval != 1){
// ERROR("rval: %d\n",rval);
//}
//t7 = get_time();
//ERROR("mosflm_do DONE %.5f %.5f %.5f %.5f %.5f %.5f\n",t2-t1,t3-t2,t4-t3,t5-t4,t6-t5,t7-t6);
} while ( !rval );
//ERROR("DONE\n");
close(mosflm->pty);
free(mosflm->rbuffer);
......
This diff is collapsed.
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