diff options
author | Thomas White <taw@physics.org> | 2014-03-11 16:43:06 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2014-03-11 16:43:06 +0100 |
commit | 9df6e29846ad8d7d69069400bd3419fa4749deb6 (patch) | |
tree | cddc1627899472fac90eb1b9bb42d2841f17e883 | |
parent | 22678ec74ccaf34c4b88b4b7ba23869b3074d55a (diff) |
ambigator: Add --really-random
-rw-r--r-- | doc/man/ambigator.1 | 4 | ||||
-rw-r--r-- | src/ambigator.c | 22 |
2 files changed, 26 insertions, 0 deletions
diff --git a/doc/man/ambigator.1 b/doc/man/ambigator.1 index b0978fb7..89dea842 100644 --- a/doc/man/ambigator.1 +++ b/doc/man/ambigator.1 @@ -79,6 +79,10 @@ Write f and g values to \fIfilename\fR, one line per crystal, repeating all crys .IP \fB--ncorr=\fR\fIn\fR Use \fIn\fR correlations per crystal. The default is to correlate against every crystal. If the CC calculation is too slow, try \fB--ncorr=1000\fR. Note that this option sets the maximum number of correlations, and some crystals might not have enough common reflections to correlate to the number requested. The mean number of actual correlations per crystal will be output by the program after the CC calculation, and if this number is much smaller than \fIn\fR then this option will not have a significant effect. +.PD 0 +.IP \fB--really-random\fR +Be non-deterministic by seeding the random number generator (used to make the initial indexing assignments and select patterns to correlate against) from /dev/urandom. Otherwise, with single-threaded operation (\fB-j 1\fR) on the same data, the results from this program should be the same if it is re-run. Using more than one thread already introduces some non-deterministic behaviour. + .SH AUTHOR This page was written by Thomas White. diff --git a/src/ambigator.c b/src/ambigator.c index 86d6d71c..bf9db16a 100644 --- a/src/ambigator.c +++ b/src/ambigator.c @@ -73,6 +73,7 @@ static void show_help(const char *s) " --fg-graph=<fn> Save f and g correlation values to file <fn>.\n" " --ncorr=<n> Use <n> correlations per crystal. Default 1000\n" " -j <n> Use <n> threads for CC calculation.\n" +" --really-random Be non-deterministic.\n" ); } @@ -721,6 +722,7 @@ int main(int argc, char *argv[]) int ncorr_set = 0; float mean_nac; int n_threads = 1; + int config_random = 0; /* Long options */ const struct option longopts[] = { @@ -735,6 +737,8 @@ int main(int argc, char *argv[]) {"fg-graph", 1, NULL, 5}, {"ncorr", 1, NULL, 6}, + {"really-random", 0, &config_random, 1}, + {0, 0, NULL, 0} }; @@ -943,6 +947,24 @@ int main(int argc, char *argv[]) } rng = gsl_rng_alloc(gsl_rng_mt19937); + + if ( config_random ) { + + FILE *fh; + unsigned long int seed; + + fh = fopen("/dev/urandom", "r"); + if ( fh == NULL ) { + ERROR("Failed to open /dev/urandom. Try again without" + " --really-random.\n"); + return 1; + } + + fread(&seed, sizeof(seed), 1, fh); + gsl_rng_set(rng, seed); + fclose(fh); + } + for ( i=0; i<n_crystals; i++ ) { assignments[i] = (random_flat(rng, 1.0) > 0.5); orig_assignments[i] = assignments[i]; |