コード例 #1
0
ファイル: host_primitives.c プロジェクト: coduin/epiphany-bsp
void retrieve_data() {
    int packets;
    int accum_bytes;
    int tagsize;

    ebsp_qsize(&packets, &accum_bytes);
    tagsize = ebsp_get_tagsize();

    printf("Queue contains %d bytes in %d packet(s), tagsize %d\n", accum_bytes,
           packets, tagsize);

    void* tag = malloc(tagsize);
    int status;

    for (int i = 0; i < packets; i++) {
        ebsp_get_tag(&status, tag);
        if (status == -1) {
            printf("bsp_get_tag failed");
            break;
        }
        int ntag = *(int*)tag;
        if (ntag == 1) {
            float value;
            ebsp_move(&value, sizeof(float));
            printf("Result 1: square sum is %f\n", value);
        } else if (ntag == 2) {
            int value;
            ebsp_move(&value, sizeof(int));
            printf("Result 2: memory allocation errors: %d\n", value);
        } else if (ntag == 3) {
            float value;
            ebsp_move(&value, sizeof(float));
            printf("Result 3: total squaresum time of all cores: %e\n", value);
        } else if (ntag >= 100 && ntag <= 200) {
            float value;
            ebsp_move(&value, sizeof(float));
            printf("Result 4: memory allocation time for core %d: %e\n",
                   ntag - 100, value);
        } else {
            printf("Received %d bytes with tag %d:\n", status, ntag);
        }
    }
    free(tag);
}
コード例 #2
0
int main(int argc, char** argv) {
    bsp_init("e_bsp_vertical_mp.srec", argc, argv);
    bsp_begin(bsp_nprocs());

    int n = bsp_nprocs();

    int tagsize = sizeof(int);
    ebsp_set_tagsize(&tagsize);

    int tag = 0;
    int payload = 0;
    for (int s = 0; s < n; ++s) {
        tag = 0;
        payload = 1000 + s;
        ebsp_send_down(s, &tag, &payload, sizeof(int));

        tag = 1;
        payload = 1234;
        ebsp_send_down(s, &tag, &payload, sizeof(int));
    }

    ebsp_spmd();

    int packets = 0;
    int accum_bytes = 0;
    ebsp_qsize(&packets, &accum_bytes);

    printf("packets: %i\n", packets);
    // FIXME nprocs
    // expect: (packets: 32)

    int* payloads = malloc(2 * n * sizeof(int));
    int payload_size = 0;
    int tag_in = 0;
    for (int i = 0; i < packets; ++i) {
        ebsp_get_tag(&payload_size, &tag_in);
        ebsp_move(&payloads[tag_in], sizeof(int));
    }

    for (int i = 0; i < n; ++i) {
        printf("$%02d: %i\n", i, payloads[i]);
        // expect_for_pid: (2000 + pid)
    }

    for (int i = n; i < 2 * n; ++i) {
        printf("$%02d: %i\n", i - bsp_nprocs(), payloads[i]);
        // expect_for_pid: (3)
    }

    free(payloads);

    bsp_end();

    return 0;
}
コード例 #3
0
int main(int argc, char **argv)
{
    bsp_init("e_dot_product.srec", argc, argv);
    bsp_begin(bsp_nprocs());

    // allocate two random vectors of length 512
    int l = 512;
    int* a = (int*)malloc(sizeof(int) * l);
    int* b = (int*)malloc(sizeof(int) * l);
    for (int i = 0; i < l; ++i) {
        a[i] = i;
        b[i] = 2*i;
    }

    // partition and write to processors
    int chunk = l / bsp_nprocs();
    printf("chunk: %i\n", chunk);

    int tag;
    int tagsize = sizeof(int);
    ebsp_set_tagsize(&tagsize);
    for (int pid = 0; pid < bsp_nprocs(); pid++)
    {
        tag = 1;
        ebsp_send_down(pid, &tag, &chunk, sizeof(int));
        tag = 2;
        ebsp_send_down(pid, &tag, &a[pid*chunk], sizeof(int)*chunk);
        tag = 3;
        ebsp_send_down(pid, &tag, &b[pid*chunk], sizeof(int)*chunk);
    }
    
    // enable memory inspector
    //ebsp_inspector_enable();

    // run dotproduct
    ebsp_spmd();

    // read output
    int packets, accum_bytes;
    ebsp_qsize(&packets, &accum_bytes);

    int status;
    int result;
    int sum = 0;
    printf("proc \t partial_sum\n");
    printf("---- \t -----------\n");
    for (int i = 0; i < packets; i++)
    {
        ebsp_get_tag(&status, &tag);
        ebsp_move(&result, sizeof(int));
        printf("%i: \t %i\n", tag, result);
        sum += result;
    }

    printf("SUM: %i\n", sum);

    free(a);
    free(b);

    // finalize
    bsp_end();

    return 0;
}