コード例 #1
0
/*
 * lsm_lp_init
 *   - initialize the lsm model
 *   - sets the disk to be idle now
 */
static void lsm_lp_init (lsm_state_t *ns, tw_lp *lp)
{
    memset(ns, 0, sizeof(*ns));

    ns->next_idle = tw_now(lp);

    // set the correct model
    const char *anno = codes_mapping_get_annotation_by_lpid(lp->gid);
    if (anno == NULL)
        ns->model = &model_unanno;
    else {
        int id = configuration_get_annotation_index(anno, anno_map);
        ns->model = &models_anno[id];
    }

    // initialize the scheduler if need be
    ns->use_sched = ns->model->use_sched > 0;
    if (ns->use_sched) {
        ns->sched.num_prios = ns->model->use_sched;
        ns->sched.active_count = 0;
        rc_stack_create(&ns->sched.freelist);
        ns->sched.queues =
            malloc(ns->sched.num_prios * sizeof(*ns->sched.queues));
        for (int i = 0; i < ns->sched.num_prios; i++)
            INIT_QLIST_HEAD(&ns->sched.queues[i]);
    }

    return;
}
コード例 #2
0
ファイル: torus.orig.c プロジェクト: dkparker/REUproject
/*Initialize the torus model, this initialization part is borrowed from Ning's torus model */
static void torus_init( nodes_state * s,
                        tw_lp * lp )
{
    int i, j;
    char anno[MAX_NAME_LENGTH];

    codes_mapping_get_lp_info(lp->gid, grp_name, &mapping_grp_id, NULL, &mapping_type_id, anno, &mapping_rep_id, &mapping_offset);
    if (anno[0] == '\0') {
        s->anno = NULL;
        s->params = &all_params[num_params-1];
    }
    else {
        s->anno = strdup(anno);
        int id = configuration_get_annotation_index(anno, anno_map);
        s->params = &all_params[id];
    }

    // shorthand
    const torus_param *p = s->params;

    s->neighbour_minus_lpID = (int*)malloc(p->n_dims * sizeof(int));
    s->neighbour_plus_lpID = (int*)malloc(p->n_dims * sizeof(int));
    s->dim_position = (int*)malloc(p->n_dims * sizeof(int));
    s->buffer = (int**)malloc(2*p->n_dims * sizeof(int*));
    s->next_link_available_time =
        (tw_stime**)malloc(2*p->n_dims * sizeof(tw_stime*));
    s->next_credit_available_time =
        (tw_stime**)malloc(2*p->n_dims * sizeof(tw_stime*));
    s->next_flit_generate_time =
        (tw_stime**)malloc(2*p->n_dims*sizeof(tw_stime*));

    for(i=0; i < 2*p->n_dims; i++)
    {
        s->buffer[i] = (int*)malloc(p->num_vc * sizeof(int));
        s->next_link_available_time[i] =
            (tw_stime*)malloc(p->num_vc * sizeof(tw_stime));
        s->next_credit_available_time[i] =
            (tw_stime*)malloc(p->num_vc * sizeof(tw_stime));
        s->next_flit_generate_time[i] =
            (tw_stime*)malloc(p->num_vc * sizeof(tw_stime));
    }

    // calculate my torus coords
    to_dim_id(codes_mapping_get_lp_relative_id(lp->gid, 0, 1),
              s->params->n_dims, s->params->dim_length, s->dim_position);
    /* DEBUG
    printf("%lu: my coords:", lp->gid);
    for (i = 0; i < p->n_dims; i++)
        printf(" %d", s->dim_position[i]);
    printf("\n");
    */

    int temp_dim_pos[ p->n_dims ];
    for ( i = 0; i < p->n_dims; i++ )
        temp_dim_pos[ i ] = s->dim_position[ i ];

    // calculate minus neighbour's lpID
    for ( j = 0; j < p->n_dims; j++ )
    {
        temp_dim_pos[ j ] = (s->dim_position[ j ] -1 + p->dim_length[ j ]) %
                            p->dim_length[ j ];

        s->neighbour_minus_lpID[j] =
            to_flat_id(p->n_dims, p->dim_length, temp_dim_pos);

        /* DEBUG
        printf(" minus neighbor: flat:%d lpid:%lu\n",
                s->neighbour_minus_lpID[j],
                codes_mapping_get_lpid_from_relative(s->neighbour_minus_lpID[j],
                        NULL, LP_CONFIG_NM, s->anno, 1));
        */

        temp_dim_pos[ j ] = s->dim_position[ j ];
    }
    // calculate plus neighbour's lpID
    for ( j = 0; j < p->n_dims; j++ )
    {
        temp_dim_pos[ j ] = ( s->dim_position[ j ] + 1 + p->dim_length[ j ]) %
                            p->dim_length[ j ];

        s->neighbour_plus_lpID[j] =
            to_flat_id(p->n_dims, p->dim_length, temp_dim_pos);

        /* DEBUG
        printf(" plus neighbor: flat:%d lpid:%lu\n",
                s->neighbour_plus_lpID[j],
                codes_mapping_get_lpid_from_relative(s->neighbour_plus_lpID[j],
                        NULL, LP_CONFIG_NM, s->anno, 1));
        */

        temp_dim_pos[ j ] = s->dim_position[ j ];
    }

    //printf("\n");
    for( j=0; j < 2 * p->n_dims; j++ )
    {
        for( i = 0; i < p->num_vc; i++ )
        {
            s->buffer[ j ][ i ] = 0;
            s->next_link_available_time[ j ][ i ] = 0.0;
            s->next_credit_available_time[j][i] = 0.0;
        }
    }
    // record LP time
    s->packet_counter = 0;
    torus_collective_init(s, lp);
}