- smpi_bench_end();
- SIMIX_mutex_lock(smpi_global->do_once_mutex);
- prev = NULL;
- for(curr = smpi_global->do_once_duration_nodes;
- NULL != curr && (strcmp(curr->file, file) || curr->line != line);
- curr = curr->next) {
- prev = curr;
- }
- if(NULL == curr) {
- curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
- curr->file = xbt_strdup(file);
- curr->line = line;
- curr->duration = -1;
- curr->next = NULL;
- if(NULL == prev) {
- smpi_global->do_once_duration_nodes = curr;
+int smpi_gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ double now = SIMIX_get_clock();
+
+ if (tv) {
+ tv->tv_sec = (time_t) now;
+ tv->tv_usec = (suseconds_t) (now * 1e6);
+ }
+ return 0;
+}
+
+static char *sample_location(int global, const char *file, int line)
+{
+ if (global) {
+ return bprintf("%s:%d", file, line);
+ } else {
+ return bprintf("%s:%d:%d", file, line, smpi_process_index());
+ }
+}
+
+int smpi_sample_1(int global, const char *file, int line, int iters, double threshold)
+{
+ char *loc = sample_location(global, file, line);
+ local_data_t *data;
+
+ smpi_bench_end(); /* Take time from previous MPI call into account */
+ if (!samples) {
+ samples = xbt_dict_new();
+ }
+ data = xbt_dict_get_or_null(samples, loc);
+ if (!data) {
+ data = (local_data_t *) xbt_new(local_data_t, 1);
+ data->count = 0;
+ data->sum = 0.0;
+ data->sum_pow2 = 0.0;
+ data->iters = iters;
+ data->threshold = threshold;
+ data->started = 0;
+ xbt_dict_set(samples, loc, data, &free);
+ return 0;
+ }
+ free(loc);
+ return 1;
+}
+
+int smpi_sample_2(int global, const char *file, int line)
+{
+ char *loc = sample_location(global, file, line);
+ local_data_t *data;
+
+ xbt_assert(samples, "You did something very inconsistent, didn't you?");
+ data = xbt_dict_get_or_null(samples, loc);
+ if (!data) {
+ xbt_assert(data, "Please, do thing in order");
+ }
+ if (!data->started) {
+ if ((data->iters > 0 && data->count >= data->iters)
+ || (data->count > 1 && data->threshold > 0.0 && data->relstderr <= data->threshold)) {
+ XBT_DEBUG("Perform some wait of %f", data->mean);
+ smpi_execute(data->mean);