Пример #1
0
int main(int argc, char** argv) {
    bsp_init("e_bsp_streams.srec", argc, argv);
    bsp_begin(bsp_nprocs());

    int chunk_size = sizeof(int) * 4;
    int chunks = 4;

    int** upstreams = (int**)malloc(sizeof(int*) * bsp_nprocs());
    int** upstreamsDouble = (int**)malloc(sizeof(int*) * bsp_nprocs());
    int* downdata = (int*)malloc(chunks * chunk_size);
    int* downdataB = (int*)malloc(chunks * chunk_size);
    int* downdataDouble = (int*)malloc(chunks * chunk_size);

    int c = 0;
    for (int i = chunks * chunk_size / sizeof(int) - 1; i >= 0; --i) {
        downdata[c] = i;
        downdataB[c] = c;
        downdataDouble[c] = 2 * c;
        c++;
    }

    for (int s = 0; s < bsp_nprocs(); ++s) {
        upstreams[s] =
            (int*)ebsp_create_up_stream(s, chunks * chunk_size, chunk_size);
        upstreamsDouble[s] =
            (int*)ebsp_create_up_stream(s, chunks * chunk_size, chunk_size);
        ebsp_create_down_stream(downdata, s, chunks * chunk_size, chunk_size);
        ebsp_create_down_stream(downdataB, s, chunks * chunk_size, chunk_size);
        ebsp_create_down_stream(downdataDouble, s, chunks * chunk_size,
                                chunk_size);
    }

    ebsp_spmd();

    for (int i = 0; i < chunk_size * chunks / sizeof(int); ++i) {
        printf("%i ", upstreams[5][i]);
    }
    printf("\n");
    // expect: (0 1 2 3 11 10 9 8 8 9 10 11 3 2 1 0 )

    for (int i = 0; i < chunk_size * chunks / sizeof(int); ++i) {
        printf("%i ", upstreamsDouble[5][i]);
    }
    // expect: (30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0 )

    // finalize
    bsp_end();

    free(upstreams);
    free(downdata);
    free(downdataB);

    return 0;
}
Пример #2
0
int main(int argc, char** argv) {
    bsp_init("e_streaming.elf", argc, argv);
    bsp_begin(bsp_nprocs());

    int chunk_size = sizeof(char) * 16;
    int chunks = 6;

    char** upstreams = (char**)malloc(sizeof(char*) * bsp_nprocs());
    char* downdata = (char*)malloc(chunks * chunk_size);
    char* downdataB = (char*)malloc(chunks * chunk_size); 

    int c = 0;
    int index1 = 0;
    int index2 = 0;
    for (int i = chunks * chunk_size / sizeof(char) - 1; i >= 0; --i) {
        downdata[c] = string1[index1++];
        downdataB[c] = string2[index2++];
        c++;

        if (index1 >= strlen(string1))
            index1 = 0;
        if (index2 >= strlen(string2))
            index2 = 0;
    }

    for (int s = 0; s < bsp_nprocs(); ++s) {
        upstreams[s] =
            (char*)ebsp_create_up_stream(s, chunks * chunk_size, chunk_size);
    }

    for (int s = 0; s < bsp_nprocs(); ++s) {
        ebsp_create_down_stream(downdata, s, chunks * chunk_size, chunk_size);
    }

    for (int s = 0; s < bsp_nprocs(); ++s) {
        ebsp_create_down_stream(downdataB, s, chunks * chunk_size, chunk_size);
    }

    ebsp_spmd();

    for (int s = 0; s < bsp_nprocs(); ++s) {
        printf("Result of processor: %i\n", s);
        for (int i = 0; i < chunk_size * chunks / sizeof(char); ++i) {
            printf("%c", upstreams[s][i]);
        }
        printf("\n\n");
    }

    // finalize
    bsp_end();

    return 0;
}