diff options
author | Thomas White <taw@physics.org> | 2018-02-27 15:14:26 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2018-02-27 17:12:42 +0100 |
commit | 1ebf2772e92a4f9344f9dca456abf8c30be731d2 (patch) | |
tree | 88bfd466928befb51b818736b1e41e0e5e1623f1 | |
parent | 5a8c9a183d2412c7bfda942dda56b2561bc67edb (diff) |
Write spectra and grid scans after every iteration, and also before the first and at end
Also, do it in parallel.
-rw-r--r-- | src/partialator.c | 78 | ||||
-rw-r--r-- | src/post-refinement.c | 8 |
2 files changed, 80 insertions, 6 deletions
diff --git a/src/partialator.c b/src/partialator.c index 3b489d74..4c9ad1c1 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -767,6 +767,79 @@ static void dump_parameters(const char *filename, Crystal **crystals, } +struct log_qargs +{ + int iter; + int next; + Crystal **crystals; + int n_crystals; + RefList *full; +}; + + +struct log_args +{ + Crystal *cr; + RefList *full; + int iter; + int cnum; +}; + + +static void *get_log_task(void *vp) +{ + struct log_qargs *qargs = vp; + struct log_args *task; + + if ( qargs->next >= qargs->n_crystals ) return NULL; + + task = malloc(sizeof(struct log_args)); + if ( task == NULL ) return NULL; + + task->cr = qargs->crystals[qargs->next]; + task->full = qargs->full; + task->iter = qargs->iter; + task->cnum = qargs->next; + + qargs->next += 20; + return task; +} + + +static void write_logs(void *vp, int cookie) +{ + struct log_args *args = vp; + write_specgraph(args->cr, args->full, args->iter, args->cnum); + write_gridscan(args->cr, args->full, args->iter, args->cnum); +} + + +static void done_log(void *qargs, void *vp) +{ + struct log_args *task = vp; + free(task); +} + + +static void write_logs_parallel(Crystal **crystals, int n_crystals, + RefList *full, int iter, int n_threads) +{ + struct log_qargs qargs; + + + qargs.iter = iter; + qargs.next = 0; + qargs.full = full; + qargs.crystals = crystals; + qargs.n_crystals = n_crystals; + + STATUS("Writing logs...\n"); + run_threads(n_threads, write_logs, get_log_task, done_log, &qargs, + n_crystals/20, 0, 0, 0); + STATUS("Done.\n"); +} + + int main(int argc, char *argv[]) { int c; @@ -1190,6 +1263,7 @@ int main(int argc, char *argv[]) check_rejection(crystals, n_crystals, full, max_B); show_all_residuals(crystals, n_crystals, full); write_pgraph(full, crystals, n_crystals, 0, ""); + write_logs_parallel(crystals, n_crystals, full, 0, nthreads); /* Iterate */ for ( i=0; i<n_iter; i++ ) { @@ -1262,9 +1336,7 @@ int main(int argc, char *argv[]) /* Write final figures of merit (no rejection any more) */ show_all_residuals(crystals, n_crystals, full); write_pgraph(full, crystals, n_crystals, -1, ""); - for ( i=0; i<n_crystals; i+=20 ) { - write_specgraph(crystals[i], full, -1, i); - } + write_logs_parallel(crystals, n_crystals, full, -1, nthreads); /* Output results */ STATUS("Writing overall results to %s\n", outfile); diff --git a/src/post-refinement.c b/src/post-refinement.c index 68f72bf2..b2fbb537 100644 --- a/src/post-refinement.c +++ b/src/post-refinement.c @@ -709,9 +709,6 @@ static void do_pr_refine(Crystal *cr, const RefList *full, char fn[64]; - write_gridscan(cr, full, cycle, serial); - write_specgraph(cr, full, cycle, serial); - snprintf(fn, 63, "pr-logs/crystal%i-cycle%i.log", serial, cycle); fh = fopen(fn, "w"); if ( fh != NULL ) { @@ -830,6 +827,11 @@ static void do_pr_refine(Crystal *cr, const RefList *full, ERROR("Bad refinement: crystal %i\n", serial); } + if ( write_logs ) { + write_gridscan(cr, full, cycle, serial); + write_specgraph(cr, full, cycle, serial); + } + gsl_multimin_fminimizer_free(min); gsl_vector_free(priv.initial); gsl_vector_free(priv.vals); |