+ smpi_execute((double) secs);
+ smpi_bench_begin();
+ return secs;
+}
+
+int smpi_gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ double now;
+ smpi_bench_end();
+ now = SIMIX_get_clock();
+ if (tv) {
+ tv->tv_sec = (time_t)now;
+ tv->tv_usec = (suseconds_t)((now - tv->tv_sec) * 1e6);
+ }
+ smpi_bench_begin();
+ return 0;
+}
+
+extern double sg_maxmin_precision;
+unsigned long long smpi_rastro_resolution (void)
+{
+ smpi_bench_end();
+ double resolution = (1/sg_maxmin_precision);
+ smpi_bench_begin();
+ return (unsigned long long)resolution;
+}
+
+unsigned long long smpi_rastro_timestamp (void)
+{
+ smpi_bench_end();
+ double now = SIMIX_get_clock();
+
+ unsigned long long sec = (unsigned long long)now;
+ unsigned long long pre = (now - sec) * smpi_rastro_resolution();
+ smpi_bench_begin();
+ return (unsigned long long)sec * smpi_rastro_resolution() + pre;
+}
+
+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_homogeneous(free);
+ }
+ 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, NULL);
+ 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);