codes.h 2.75 KB
Newer Older
1
/*
Philip Carns's avatar
Philip Carns committed
2
 * Copyright (C) 2013 University of Chicago.
3
 * See COPYRIGHT notice in top-level directory.
Philip Carns's avatar
Philip Carns committed
4
 *
5 6
 */

Philip Carns's avatar
Philip Carns committed
7

8 9 10
#ifndef CODES_H
#define CODES_H

Jonathan Jenkins's avatar
Jonathan Jenkins committed
11 12 13 14
#ifdef __cplusplus
extern "C" {
#endif

15 16
#include <ross.h>
#include <assert.h>
17 18 19
#include <mpi.h>

extern MPI_Comm MPI_COMM_CODES;
20

Jonathan Jenkins's avatar
Jonathan Jenkins committed
21 22
// for printf conversions: shorthand for cast to long long unsigned format (llu)
#define LLU(x) ((unsigned long long)(x))
23
#define LLD(x) ((long long)(x))
Jonathan Jenkins's avatar
Jonathan Jenkins committed
24

25 26 27 28 29 30 31 32 33 34
// simple deprecation attribute hacking
#if !defined(DEPRECATED)
#  if defined(__GNUC__) || defined(__GNUG__) || defined(__clang__)
#    define DEPRECATED __attribute__((deprecated))
#  else
#    define DEPRECATED
#  endif
#endif

DEPRECATED
35 36 37 38 39 40 41 42 43 44
static inline tw_event * codes_event_new(
    tw_lpid dest_gid, 
    tw_stime offset_ts, 
    tw_lp * sender)
{
    tw_stime abs_ts = offset_ts + tw_now(sender); 
    assert(abs_ts < g_tw_ts_end);
    //printf("codes_event_new() abs_ts: %.9f\n", abs_ts);
    return(tw_event_new(dest_gid, offset_ts, sender));
}
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

static inline tw_event * tw_event_new_bounded(
    tw_lpid dest_gid,
    tw_stime offset_ts,
    tw_lp * sender)
{
    tw_stime ts = offset_ts + tw_now(sender);
    if (ts >= g_tw_ts_end) {
        tw_error(TW_LOC,
                "LP %lu tried to schedule a message for time %0.5e, "
                "%0.5e past the end time\n",
                sender->gid, ts, g_tw_ts_end-ts);
        return NULL;
    }
    else
        return tw_event_new(dest_gid, offset_ts, sender);
}

63 64 65 66 67 68

/* TODO: validate what value we should use here */
/* Modeled latency for communication between local software components and
 * communication between daemons and hardware devices.  Measured in
 * nanoseconds.
 */
69 70 71 72
#define CODES_MIN_LATENCY 0.5
#define CODES_MAX_LATENCY 1.0
#define CODES_LATENCY_RANGE \
    (CODES_MAX_LATENCY-CODES_MIN_LATENCY)
73 74
static inline tw_stime codes_local_latency(tw_lp *lp)
{
75
    int r = g_tw_nRNG_per_lp-1;
76 77
    tw_stime tmp;

78
    tmp = g_tw_lookahead + CODES_MIN_LATENCY +
79 80 81 82 83 84 85
        tw_rand_unif(&lp->rng[r]) * CODES_LATENCY_RANGE;

    if (g_tw_synchronization_protocol == CONSERVATIVE &&
            (tw_now(lp) + g_tw_lookahead) >= (tw_now(lp) + tmp))
        tw_error(TW_LOC,
                "codes_local_latency produced a precision loss "
                "sufficient to fail lookahead check (conservative mode) - "
86 87 88
                "increase CODES_MIN_LATENCY/CODES_MAX_LATENCY. "
                "Now:%0.5le, lookahead:%0.5le, return:%0.5le\n",
                tw_now(lp), g_tw_lookahead, tmp);
89 90 91 92 93 94

    return(tmp);
}

static inline void codes_local_latency_reverse(tw_lp *lp)
{
95 96
    int r = g_tw_nRNG_per_lp-1;
    tw_rand_reverse_unif(&lp->rng[r]);
97 98 99
    return;
}

Jonathan Jenkins's avatar
Jonathan Jenkins committed
100 101 102 103
#ifdef __cplusplus
}
#endif

104 105 106 107 108 109 110 111 112 113
#endif /* CODES_H */

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ft=c ts=8 sts=4 sw=4 expandtab
 */