codes-workload.c 9.21 KB
Newer Older
1 2 3 4 5 6
/*
 * Copyright (C) 2013 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

7
#include <assert.h>
8 9 10 11 12

#include "ross.h"
#include "codes/codes-workload.h"
#include "codes-workload-method.h"

13
/* list of available methods.  These are statically compiled for now, but we
14 15
 * could make generators optional via autoconf tests etc. if needed
 */
16
extern struct codes_workload_method test_workload_method;
17
extern struct codes_workload_method bgp_io_workload_method;
18 19 20 21
extern struct codes_workload_method scala_trace_workload_method;
#ifdef USE_DUMPI
extern struct codes_workload_method dumpi_trace_workload_method;
#endif
22
#ifdef USE_DARSHAN
23
extern struct codes_workload_method darshan_io_workload_method;
24
#endif
25 26 27
#ifdef USE_RECORDER
extern struct codes_workload_method recorder_io_workload_method;
#endif
28

29
static struct codes_workload_method *method_array[] =
30 31 32
{
    &test_workload_method,
    &bgp_io_workload_method,
33 34 35 36
    &scala_trace_workload_method,
#ifdef USE_DUMPI
    &dumpi_trace_workload_method,
#endif
37 38
#ifdef USE_DARSHAN
    &darshan_io_workload_method,
39 40 41
#endif
#ifdef USE_RECORDER
    &recorder_io_workload_method,
42 43
#endif
    NULL};
44

Philip Carns's avatar
Philip Carns committed
45 46 47 48 49
/* This shim layer is responsible for queueing up reversed operations and
 * re-issuing them so that the underlying workload generator method doesn't
 * have to worry about reverse events.
 *
 * NOTE: we could make this faster with a smarter data structure.  For now
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
 * we just have a linked list of rank_queue structs, one per rank that has
 * opened the workload.  We then have a linked list off of each of those
 * to hold a lifo queue of operations that have been reversed for that rank.
 */

/* holds an operation that has been reversed */
struct rc_op
{
    struct codes_workload_op op;
    struct rc_op* next;
};

/* tracks lifo queue of reversed operations for a given rank */
struct rank_queue
{
    int rank;
    struct rc_op *lifo;
    struct rank_queue *next;
};

static struct rank_queue *ranks = NULL;

72 73
int codes_workload_load(const char* type, const char* params, int rank)
{
74 75
    int i;
    int ret;
76
    struct rank_queue *tmp;
77 78 79 80 81

    for(i=0; method_array[i] != NULL; i++)
    {
        if(strcmp(method_array[i]->method_name, type) == 0)
        {
82
            /* load appropriate workload generator */
83 84 85 86 87
            ret = method_array[i]->codes_workload_load(params, rank);
            if(ret < 0)
            {
                return(-1);
            }
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

            /* are we tracking information for this rank yet? */
            tmp = ranks;
            while(tmp)
            {
                if(tmp->rank == rank)
                    break;
                tmp = tmp->next;
            }
            if(tmp == NULL)
            {
                tmp = malloc(sizeof(*tmp));
                assert(tmp);
                tmp->rank = rank;
                tmp->lifo = NULL;
                tmp->next = ranks;
                ranks = tmp;
            }

107 108 109 110 111
            return(i);
        }
    }

    fprintf(stderr, "Error: failed to find workload generator %s\n", type);
112 113 114
    return(-1);
}

115
void codes_workload_get_next(int wkld_id, int rank, struct codes_workload_op *op)
116
{
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    struct rank_queue *tmp;
    struct rc_op *tmp_op;

    /* first look to see if we have a reversed operation that we can
     * re-issue
     */
    tmp = ranks;
    while(tmp)
    {
        if(tmp->rank == rank)
            break;
        tmp = tmp->next;
    }
    assert(tmp);
    if(tmp->lifo)
    {
        tmp_op = tmp->lifo;
134
        tmp->lifo = tmp_op->next;
135 136 137

        *op = tmp_op->op;
        free(tmp_op);
138
        //printf("codes_workload_get_next re-issuing reversed operation.\n");
139 140 141 142
        return;
    }

    /* ask generator for the next operation */
143
    //printf("codes_workload_get_next issuing new operation.\n");
144 145
    method_array[wkld_id]->codes_workload_get_next(rank, op);

146 147 148
    return;
}

149
void codes_workload_get_next_rc(int wkld_id, int rank, const struct codes_workload_op *op)
150
{
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    struct rank_queue *tmp;
    struct rc_op *tmp_op;

    tmp = ranks;
    while(tmp)
    {
        if(tmp->rank == rank)
            break;
        tmp = tmp->next;
    }
    assert(tmp);

    tmp_op = malloc(sizeof(*tmp_op));
    assert(tmp_op);
    tmp_op->op = *op;
    tmp_op->next = tmp->lifo;
    tmp->lifo = tmp_op;
168

169 170 171
    return;
}

172
int codes_workload_get_rank_cnt(const char* type, const char* params)
173
{
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    int i;
    int rank_cnt;

    for(i=0; method_array[i] != NULL; i++)
    {
        if(strcmp(method_array[i]->method_name, type) == 0)
        {
            rank_cnt = method_array[i]->codes_workload_get_rank_cnt(params);
            assert(rank_cnt > 0);
            return(rank_cnt);
        }
    }

    fprintf(stderr, "Error: failed to find workload generator %s\n", type);
    return(-1);
189 190
}

191 192 193
void codes_workload_print_op(FILE *f, struct codes_workload_op *op, int rank){
    switch(op->op_type){
        case CODES_WK_END:
194
            fprintf(f, "op: rank:%d type:end\n", rank);
195 196
            break;
        case CODES_WK_DELAY:
197
            fprintf(f, "op: rank:%d type:delay seconds:%lf\n",
198 199 200
                    rank, op->u.delay.seconds);
            break;
        case CODES_WK_BARRIER:
201
            fprintf(f, "op: rank:%d type:barrier count:%d root:%d\n",
202 203 204
                    rank, op->u.barrier.count, op->u.barrier.root);
            break;
        case CODES_WK_OPEN:
205
            fprintf(f, "op: rank:%d type:open file_id:%lu flag:%d\n",
206 207 208
                    rank, op->u.open.file_id, op->u.open.create_flag);
            break;
        case CODES_WK_CLOSE:
209
            fprintf(f, "op: rank:%d type:close file_id:%lu\n",
210 211 212
                    rank, op->u.close.file_id);
            break;
        case CODES_WK_WRITE:
213 214
            fprintf(f, "op: rank:%d type:write "
                       "file_id:%lu off:%lu size:%lu\n",
215
                    rank, op->u.write.file_id, op->u.write.offset,
216 217 218
                    op->u.write.size);
            break;
        case CODES_WK_READ:
219 220
            fprintf(f, "op: rank:%d type:read "
                       "file_id:%lu off:%lu size:%lu\n",
221
                    rank, op->u.read.file_id, op->u.read.offset,
222 223
                    op->u.read.size);
            break;
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
        case CODES_WK_SEND:
            fprintf(f, "op: rank:%d type:send "
                    "src:%d dst:%d bytes:%d type:%d count:%d tag:%d\n",
                    rank,
                    op->u.send.source_rank, op->u.send.dest_rank,
                    op->u.send.num_bytes, op->u.send.data_type,
                    op->u.send.count, op->u.send.tag);
            break;
        case CODES_WK_RECV:
            fprintf(f, "op: rank:%d type:recv "
                    "src:%d dst:%d bytes:%d type:%d count:%d tag:%d\n",
                    rank,
                    op->u.recv.source_rank, op->u.recv.dest_rank,
                    op->u.recv.num_bytes, op->u.recv.data_type,
                    op->u.recv.count, op->u.recv.tag);
            break;
        case CODES_WK_ISEND:
            fprintf(f, "op: rank:%d type:isend "
                    "src:%d dst:%d bytes:%d type:%d count:%d tag:%d\n",
                    rank,
                    op->u.send.source_rank, op->u.send.dest_rank,
                    op->u.send.num_bytes, op->u.send.data_type,
                    op->u.send.count, op->u.send.tag);
            break;
        case CODES_WK_IRECV:
            fprintf(f, "op: rank:%d type:irecv "
                    "src:%d dst:%d bytes:%d type:%d count:%d tag:%d\n",
                    rank,
                    op->u.recv.source_rank, op->u.recv.dest_rank,
                    op->u.recv.num_bytes, op->u.recv.data_type,
                    op->u.recv.count, op->u.recv.tag);
            break;
        case CODES_WK_BCAST:
            fprintf(f, "op: rank:%d type:bcast "
                    "bytes:%d\n", rank, op->u.collective.num_bytes);
            break;
        case CODES_WK_ALLGATHER:
            fprintf(f, "op: rank:%d type:allgather "
                    "bytes:%d\n", rank, op->u.collective.num_bytes);
            break;
        case CODES_WK_ALLGATHERV:
            fprintf(f, "op: rank:%d type:allgatherv "
                    "bytes:%d\n", rank, op->u.collective.num_bytes);
            break;
        case CODES_WK_ALLTOALL:
            fprintf(f, "op: rank:%d type:alltoall "
                    "bytes:%d\n", rank, op->u.collective.num_bytes);
            break;
        case CODES_WK_ALLTOALLV:
            fprintf(f, "op: rank:%d type:alltoallv "
                    "bytes:%d\n", rank, op->u.collective.num_bytes);
            break;
        case CODES_WK_REDUCE:
            fprintf(f, "op: rank:%d type:reduce "
                    "bytes:%d\n", rank, op->u.collective.num_bytes);
            break;
        case CODES_WK_ALLREDUCE:
            fprintf(f, "op: rank:%d type:allreduce "
                    "bytes:%d\n", rank, op->u.collective.num_bytes);
            break;
        case CODES_WK_COL:
            fprintf(f, "op: rank:? type:collective "
                    "bytes:%d\n", op->u.collective.num_bytes);
            break;
Jonathan Jenkins's avatar
Jonathan Jenkins committed
288 289
        case CODES_WK_IGNORE:
            break;
290
        default:
Jonathan Jenkins's avatar
Jonathan Jenkins committed
291 292 293
            fprintf(stderr,
                    "%s:%d: codes_workload_print_op: unrecognized workload type "
                    "(op code %d)\n", __FILE__, __LINE__, op->op_type);
294 295 296
    }
}

297 298 299 300 301 302 303 304
/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ft=c ts=8 sts=4 sw=4 expandtab
 */