aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2015-07-17 11:34:49 +0200
committerThomas White <taw@physics.org>2015-07-17 14:38:47 +0200
commiteed34caa5fa7208cd63da88ceb987f027d650ee9 (patch)
tree24e7c9b72e026a893d2fd3ceee0365d3e1a7f3ec
parente80578dd35e486666390baf7a557f1605c06f004 (diff)
Move post refinement multiprocessing stuff to post-refinement.c
-rw-r--r--src/partialator.c105
-rw-r--r--src/post-refinement.c109
-rw-r--r--src/post-refinement.h8
3 files changed, 113 insertions, 109 deletions
diff --git a/src/partialator.c b/src/partialator.c
index 46353c25..4398c9f8 100644
--- a/src/partialator.c
+++ b/src/partialator.c
@@ -84,111 +84,6 @@ static void show_help(const char *s)
}
-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);
-}
-
-
-static 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;
-}
-
-
static void display_progress(int n_images, int n_crystals)
{
if ( !isatty(STDERR_FILENO) ) return;
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;
+}
diff --git a/src/post-refinement.h b/src/post-refinement.h
index fd2d771b..a0d27591 100644
--- a/src/post-refinement.h
+++ b/src/post-refinement.h
@@ -54,8 +54,12 @@ struct prdata
};
-extern struct prdata pr_refine(Crystal *cr, const RefList *full,
- PartialityModel pmodel, int no_scale);
+
+extern 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);
/* Exported so it can be poked by tests/pr_p_gradient_check */
extern double gradient(Crystal *cr, int k, Reflection *refl,