diff options
author | Thomas White <taw@physics.org> | 2015-07-17 11:34:49 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2015-07-17 14:38:47 +0200 |
commit | eed34caa5fa7208cd63da88ceb987f027d650ee9 (patch) | |
tree | 24e7c9b72e026a893d2fd3ceee0365d3e1a7f3ec /src/post-refinement.c | |
parent | e80578dd35e486666390baf7a557f1605c06f004 (diff) |
Move post refinement multiprocessing stuff to post-refinement.c
Diffstat (limited to 'src/post-refinement.c')
-rw-r--r-- | src/post-refinement.c | 109 |
1 files changed, 107 insertions, 2 deletions
diff --git a/src/post-refinement.c b/src/post-refinement.c index 139b8b9a..9484da43 100644 --- a/src/post-refinement.c +++ b/src/post-refinement.c @@ -546,8 +546,8 @@ static double residual(Crystal *cr, const RefList *full, int verbose, int free) } -struct prdata pr_refine(Crystal *cr, const RefList *full, - PartialityModel pmodel, int no_scale) +static struct prdata pr_refine(Crystal *cr, const RefList *full, + PartialityModel pmodel, int no_scale) { int i; int verbose = 0; @@ -614,3 +614,108 @@ struct prdata pr_refine(Crystal *cr, const RefList *full, return prdata; } + + +struct refine_args +{ + RefList *full; + Crystal *crystal; + PartialityModel pmodel; + int no_scale; + struct prdata prdata; +}; + + +struct queue_args +{ + int n_started; + int n_done; + Crystal **crystals; + int n_crystals; + struct refine_args task_defaults; + double initial_residual; + double initial_free_residual; + double final_residual; + double final_free_residual; +}; + + +static void refine_image(void *task, int id) +{ + struct refine_args *pargs = task; + Crystal *cr = pargs->crystal; + + pargs->prdata = pr_refine(cr, pargs->full, pargs->pmodel, + pargs->no_scale); +} + + +static void *get_image(void *vqargs) +{ + struct refine_args *task; + struct queue_args *qargs = vqargs; + + task = malloc(sizeof(struct refine_args)); + memcpy(task, &qargs->task_defaults, sizeof(struct refine_args)); + + task->crystal = qargs->crystals[qargs->n_started]; + + qargs->n_started++; + + return task; +} + + +static void done_image(void *vqargs, void *task) +{ + struct queue_args *qargs = vqargs; + struct refine_args *pargs = task; + + qargs->n_done++; + qargs->initial_residual += pargs->prdata.initial_residual; + qargs->initial_free_residual += pargs->prdata.initial_free_residual; + qargs->final_residual += pargs->prdata.final_residual; + qargs->final_free_residual += pargs->prdata.final_free_residual; + + progress_bar(qargs->n_done, qargs->n_crystals, "Refining"); + free(task); +} + + +void refine_all(Crystal **crystals, int n_crystals, + RefList *full, int nthreads, PartialityModel pmodel, + int no_scale, + double *initial_residual, double *initial_free_residual, + double *final_residual, double *final_free_residual) +{ + struct refine_args task_defaults; + struct queue_args qargs; + + task_defaults.full = full; + task_defaults.crystal = NULL; + task_defaults.pmodel = pmodel; + task_defaults.prdata.refined = 0; + task_defaults.prdata.n_filtered = 0; + task_defaults.no_scale = no_scale; + + qargs.task_defaults = task_defaults; + qargs.n_started = 0; + qargs.n_done = 0; + qargs.n_crystals = n_crystals; + qargs.crystals = crystals; + qargs.initial_residual = 0.0; + qargs.initial_free_residual = 0.0; + qargs.final_residual = 0.0; + qargs.final_free_residual = 0.0; + + /* Don't have threads which are doing nothing */ + if ( n_crystals < nthreads ) nthreads = n_crystals; + + run_threads(nthreads, refine_image, get_image, done_image, + &qargs, n_crystals, 0, 0, 0); + + *initial_residual = qargs.initial_residual; + *initial_free_residual = qargs.initial_free_residual; + *final_residual = qargs.final_residual; + *final_free_residual = qargs.final_free_residual; +} |