Beispiel #1
0
void update_ghostcells ( int **buffer, int height, int width, int fhlimit,int localheight, int heightoffset )
{

    int i, j, k;

    shmem_barrier_all() ;

    if ( size < 2 ) {
        /* Nothing to be done */
        return;
    }

    if ( rank != 0 ) {
        if ( shmem_addr_accessible(&buffer[0][0], rank-1)) {
            if ( (rank - 1 ) == 0 )
            {
                for ( i = 0; i < 2; i++ ) shmem_int_get ( &(buffer[i][0]), &(buffer[i+(localheight-2)][0]), width, rank-1);
            }
            else {
                for ( i = 0; i < 2; i++ ) shmem_int_get ( &(buffer[i][0]), &(buffer[i+(localheight)][0]), width, rank-1);
            }
        }
        else {
            printf("Not_Accessible_Error_01");
        }

        if ( shmem_addr_accessible(&buffer[0][0], rank-1)) {
            if ( (rank - 1 ) == 0 )
            {
                for ( i = 0; i < 2; i++ ) shmem_int_put ( &(buffer[i+(localheight)][0]), &(buffer[i+heightoffset][0]), width, rank-1);
            }
            else {
                for ( i = 0; i < 2; i++ ) shmem_int_put ( &(buffer[i+(localheight)+2][0]), &(buffer[i+heightoffset][0]), width, rank-1);
            }
        }
        else {
            printf("Not_Accessible_Error_02");
        }
    }

    shmem_barrier_all ();
    return;
}
Beispiel #2
0
int FORTRANIFY (shmem_addr_accessible) (void *addr, int *pe)
{
    return shmem_addr_accessible (addr, *pe);
}
Beispiel #3
0
/* main function */
int main(int argc, char **argv)
{
    int localheight=0;
    int realheight=0;
    int height, width,i, j, k, heightoffset;
    int **labels=NULL;
    FILE *fpa;

    /* initializing shmem values */
    start_pes (0);
    size = _num_pes ();
    rank = _my_pe ();

    /* determining inputs */
    if (argc != 5 ) {
        printf("usage: %s <inputfile> <outputfile> <height> <width>\n", argv[0]);
        exit(0);
    }
    height = atoi ( argv[3]);
    width  = atoi ( argv[4]);

    /* creating symmetric memory */
    labels = (int **) shmalloc (height*sizeof(int *));
    for ( i = 0; i < height; i++ )
    {
        labels[i] = (int*) shmalloc (width*sizeof(int*));
    }

    allocate_2D_int_matrix ( &labels, height, width );

    /* reading from the input file */
    if ( rank == 0 )
    {
        fpa = fopen ( argv[1], "rb");
        fread ( &(labels[0][0]), sizeof(int), height*width, fpa);
        fclose ( fpa );
    }

    /* datapartitioning between the processes */
    localheight = height/size;
    realheight  = localheight + 4 ;
    heightoffset = 2;
    if ( rank == 0 ) {
        realheight -= 2 ;
        heightoffset = 0;
    }
    if ( rank == (size -1) )  {
        realheight -= 2;
    }

    shmem_barrier_all ();
    /* distributing input datum to all the symmetric variables */
    for ( i=1; i<size; i++ ) {
        if ( rank == i )
            if ( shmem_addr_accessible(&labels[0][0], 0)) {
                if ( rank == ( size -1 ) ) {
                    k = 0;
                }
                else {
                    k = 2;
                }
                for ( j = 0; j < localheight+k; j++ ) {
                    shmem_int_get(&labels[j+heightoffset][0], &labels[j+(localheight*rank)][0], width, 0);
                }
            }
            else {
                printf("Not_accessible_Error_00");
            }
    }

    /* gray erode calculation */
    shmem_barrier_all();
    gettimeofday(&start, NULL);
    gray_erode(labels, height, width, FILTERHEIGHT,FILTERWIDTH, ITERATIONS, SEGMENTS, localheight, heightoffset );
    gettimeofday(&end, NULL);

    /* calculating and displaying time taken */
    if( rank == 0 )
    {
        t = (double) ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)) / 1000000.0;
        printf("Total Time%f \n",t);
    }

    /* transferring datum back to root */
    shmem_barrier_all ();
    for ( k = 0; k < size; k++) {
        if ( rank == k ) {
            for ( i = 0; i < localheight; i++ ) {
                shmem_int_put(&labels[i+(localheight*rank)][0], &labels[i+heightoffset][0], width, 0);
            }
        }
    }

    shmem_barrier_all ();
    /* creating output file */
    if(rank == 0)	{
        fpa = fopen ( argv[2], "wb");
        fwrite( &(labels[0][0]), sizeof(int), height*width, fpa );
        fclose( fpa );
    }

    free_2D_int_matrix ( &labels);
    return 0;
}
Beispiel #4
0
int
main(int argc, char* argv[])
{
    int me, num_procs, l, j;
    int Verbose = 0;

    start_pes(0);
    me = _my_pe();
    num_procs = _num_pes();
    if ( num_procs < 2 ) {
        if (me ==0)
            printf("PE[0] requires 2 or more PEs?\n");
        return 1;
    }

    for (l = 0 ; l < loops ; ++l) {

        if ((src_int = shmalloc(2*num_procs*sizeof(int))) == NULL) {
            printf("PE-%d int shmalloc() failed?\n", me);
            exit(1);
        }
        dst_int = &src_int[num_procs];
        for(j=0; j < num_procs; j++) {
            src_int[j] = 4;
            dst_int[j] = 0;
        }

        if ((src_float = shmalloc(2*num_procs*sizeof(float))) == NULL) {
            printf("PE-%d float shmalloc() failed?\n", me);
            exit(1);
        }
        dst_float = &src_float[num_procs];
        for(j=0; j < num_procs; j++) {
            src_float[j] = 4.0;
            dst_float[j] = 0.0;
        }

        if ((src_double = shmalloc(2*num_procs*sizeof(double))) == NULL) {
            printf("PE-%d double shmalloc() failed?\n", me);
            exit(1);
        }
        dst_double = &src_double[num_procs];
        for(j=0; j < num_procs; j++) {
            src_double[j] = 8.0;
            dst_double[j] = 0.0;
        }

        if ((src_long = shmalloc(2*num_procs*sizeof(long))) == NULL) {
            printf("PE-%d long shmalloc() failed?\n", me);
            exit(1);
        }
        dst_long = &src_long[num_procs];
        for(j=0; j < num_procs; j++) {
            src_long[j] = 8;
            dst_long[j] = 0;
        }

        if ((src_llong = shmalloc(2*num_procs*sizeof(long long))) == NULL) {
            printf("PE-%d long shmalloc() failed?\n", me);
            exit(1);
        }
        dst_llong = &src_llong[num_procs];
        for(j=0; j < num_procs; j++) {
            src_llong[j] = 16;
            dst_llong[j] = 0;
        }

        shmem_barrier_all();

        if ( me != 0 ) {
            /* is 'src_*' accessible from PE0? should be. */
            if (!shmem_addr_accessible(src_int,0)) {
                printf("PE-%d local src_int %p not accessible from PE-%d?\n",
                       me, (void*)src_int, 0);
                exit(1);
            }
            if (!shmem_addr_accessible(src_float,0)) {
                printf("PE-%d local src_float %p not accessible from PE-%d?\n",
                       me, (void*)src_float, 0);
                exit(1);
            }
            if (!shmem_addr_accessible(src_double,0)) {
                printf("PE-%d local src_double %p not accessible from PE-%d?\n",
                       me, (void*)src_double, 0);
                exit(1);
            }
            if (!shmem_addr_accessible(src_long,0)) {
                printf("PE-%d local src_long %p not accessible from PE-%d?\n",
                       me, (void*)src_long, 0);
                exit(1);
            }
            if (!shmem_addr_accessible(src_llong,0)) {
                printf("PE-%d local src_llong %p not accessible from PE-%d?\n",
                       me, (void*)src_llong, 0);
                exit(1);
            }
        }
        shmem_barrier_all();

        if ( me == 0 ) {
            shmem_quiet();
            for(j=1; j < num_procs; j++) {
                dst_int[j] = shmem_int_swap(src_int+j,0,j);
                if (dst_int[j] != 4) {
                    printf("PE-%d dst_int[%d] %d != 4?\n",me,j,dst_int[j]);
                    exit(1);
                }
            }
            shmem_barrier_all();

            /* verify remote data */
            for(j=1; j < num_procs; j++) {
                itmp = shmem_int_g(src_int+j,j);
                if (itmp != 0) {
                    printf("PE-0 int PE[%d] rem(%d) != 0?\n",j,itmp);
                    exit(1);
                }

                /* swap back */
                dst_int[j] = shmem_int_swap(src_int+j,dst_int[j],j);
                if (dst_int[j] != 0) {
                    printf("PE-0 dst_int[%d] %d != 0?\n",j,dst_int[j]);
                    exit(1);
                }

                itmp = shmem_int_g(src_int+j,j);
                if (itmp != 4) {
                    printf("PE-0 PE[%d] rem %d != 4?\n",j,itmp);
                    exit(1);
                }
            }

            for(j=1; j < num_procs; j++) {
                dst_float[j] = shmem_float_swap(src_float+j,0.0,j);
                if (dst_float[j] != 4.0) {
                    printf("PE-0 dst_float[%d] %f != 4.0?\n",j,dst_float[j]);
                    exit(1);
                }

                /* verify remote data */
                ftmp = shmem_float_g(src_float+j,j);
                if (ftmp != 0.0) {
                    printf("PE-0 float rem(%f) != 0.0?\n",ftmp);
                    exit(1);
                }
                /* swap back */
                dst_float[j] = shmem_float_swap(src_float+j,dst_float[j],j);
                if (dst_float[j] != 0.0) {
                    printf("PE-0 dst_float[%d] %f != 0.0?\n",j,dst_float[j]);
                    exit(1);
                }
                ftmp = shmem_float_g(src_float+j,j);
                if (ftmp != 4.0) {
                    printf("PE-%d float rem(%f) != 4.0?\n",me,ftmp);
                    exit(1);
                }
            }

            for(j=1; j < num_procs; j++) {
                dst_double[j] = shmem_double_swap(src_double+j,0.0,j);
                if (dst_double[j] != 8.0) {
                    printf("PE-0 dst_double[%d] %f != 8.0?\n",j,dst_double[j]);
                    exit(1);
                }
                /* verify remote data */
                dtmp = shmem_double_g(src_double+j,j);
                if (dtmp != 0.0) {
                    printf("PE-0 float rem(%f) != 0.0?\n",dtmp);
                    exit(1);
                }
                dst_double[j] = shmem_double_swap(src_double+j,dst_double[j],j);
                if (dst_double[j] != 0.0) {
                    printf("PE-0 dst_double[%d] %f != 0.0?\n",j,dst_double[j]);
                    exit(1);
                }
                dtmp = shmem_double_g(src_double+j,j);
                if (dtmp != 8.0) {
                    printf("PE-0 double rem(%f) != 8.0?\n",dtmp);
                    exit(1);
                }
            }

            for(j=1; j < num_procs; j++) {
                dst_long[j] = shmem_long_swap(src_long+j,0,j);
                if (dst_long[j] != 8) {
                    printf("PE-0 dst_long[%d] %ld != 8?\n",j,dst_long[j]);
                    exit(1);
                }
            }
            shmem_barrier_all();

            /* verify remote data */
            for(j=1; j < num_procs; j++) {
                ltmp = shmem_long_g(src_long+j,j);
                if (ltmp != 0) {
                    printf("PE-0 PE[%d]long rem(%ld) != 0?\n",j,ltmp);
                    exit(1);
                }
                /* swap back */
                dst_long[j] = shmem_long_swap(src_long+j,dst_long[j],j);
                if (dst_long[j] != 0) {
                    printf("PE-%d dst_long[%d] %ld != 0?\n",me,j,dst_long[j]);
                    exit(1);
                }
                ltmp = shmem_long_g(src_long+j,j);
                if (ltmp != 8) {
                    printf("PE-%d long rem(%ld) != 8?\n",me,ltmp);
                    exit(1);
                }
            }

            for(j=1; j < num_procs; j++) {
                dst_llong[j] = shmem_longlong_swap(src_llong+j,0,j);
                if (dst_llong[j] != 16) {
                    printf("PE-%d dst_llong[%d] %lld != 16?\n",me,j,dst_llong[j]);
                    exit(1);
                }
            }
            shmem_barrier_all();

            /* verify remote data */
            for(j=1; j < num_procs; j++) {
                lltmp = shmem_longlong_g(src_llong+j,j);
                if (lltmp != 0) {
                    printf("PE-%d long long rem(%lld) != 0?\n",me,lltmp);
                    exit(1);
                }
                /* swap back */
                dst_llong[j] = shmem_longlong_swap(src_llong+j,dst_llong[j],j);
                if (dst_llong[j] != 0) {
                    printf("PE-%d  dst_llong[%d] %lld != 0?\n", me,j,dst_llong[j]);
                    exit(1);
                }
                lltmp = shmem_longlong_g(src_llong+j,j);
                if (lltmp != 16) {
                    printf("PE-%d longlong rem(%lld) != 16?\n",me,lltmp);
                    exit(1);
                }
            }
        }
        else {
            shmem_int_wait_until(&src_int[me],SHMEM_CMP_EQ,0);
            shmem_barrier_all();

            shmem_long_wait_until(&src_long[me],SHMEM_CMP_EQ,0);
            shmem_barrier_all();

            shmem_longlong_wait_until(&src_llong[me],SHMEM_CMP_EQ,0);
            shmem_barrier_all();
        }

        shmem_barrier_all();

        shfree(src_int);
        shfree(src_float);
        shfree(src_double);
        shfree(src_long);
        shfree(src_llong);
    }

    if (Verbose)
        fprintf(stderr,"[%d] exit\n",_my_pe());

    return 0;
}
Beispiel #5
0
int
main(int argc, char* argv[])
{
    int me, num_pes, l, pe;
    int Verbose = 0;

    start_pes(0);
    me = _my_pe();
    num_pes = _num_pes();

    for (l = 0 ; l < loops ; ++l) {

        if ((src_int = shmalloc(sizeof(int))) == NULL) {
            printf("PE-%d int shmalloc() failed?\n", me);
            exit(1);
        }
        *src_int = 4;
        dst_int = itmp = 0;

        if ((src_long = shmalloc(sizeof(long))) == NULL) {
            printf("PE-%d long shmalloc() failed?\n", me);
            exit(1);
        }
        *src_long = 8;
        dst_long = ltmp = 0;

        if ((src_llong = shmalloc(sizeof(long long))) == NULL) {
            printf("PE-%d long long shmalloc() failed?\n", me);
            exit(1);
        }
        *src_llong = 16;
        dst_llong = lltmp = 0;

        //printf("PE-%d malloc()s done.\n",me);
        shmem_barrier_all();

        if ( me == 0 ) {
            /* integer swap */
            itmp = shmem_int_g(src_int,1);
            Vprintf("PE-0 Initial Conditions(int) local %d rem(%d)\n",
                    dst_int,itmp);

            dst_int = shmem_int_cswap(src_int,*src_int,0,1);
            if (dst_int != 4) {
                printf("PE-%d dst_int %d != 4?\n",me,dst_int);
                exit(1);
            }
            /* verify remote data */
            itmp = shmem_int_g(src_int,1);
            if (itmp != 0) {
                printf("PE-%d rem %d != 0?\n",me,itmp);
                exit(1);
            }
            Vprintf("PE-0 1st int_cswap done: local %d rem(%d)\n",dst_int,itmp);

            dst_int = shmem_int_cswap(src_int,0,dst_int,1);
            if (dst_int != 0) {
                printf("PE-%d dst_int %d != 0?\n",me,dst_int);
                exit(1);
            }
            /* verify remote data */
            itmp = shmem_int_g(src_int,1);
            if (itmp != 4) {
                printf("PE-%d rem %d != 4?\n",me,itmp);
                exit(1);
            }
            Vprintf("PE-0 2nd int_swap done: local %d rem(%d)\n",dst_int,itmp);

            /* cswap() should not swap as cond(0) != remote(4) */
            dst_int = shmem_int_cswap(src_int,0,0,1);
            if (dst_int != 4) {
                printf("PE-%d int no-swap returned dst_int %d != 4?\n",
                        me,dst_int);
                exit(1);
            }
            /* verify previous cswap() did not swap */
            itmp = shmem_int_g(src_int,1);
            if (itmp != 4) {
                printf("PE-%d failed cond int_cswap() swapped? rem(%d) != 4?\n",
                        me,itmp);
                exit(1);
            }

            /* long swap */
            ltmp = shmem_long_g(src_long,1);
            Vprintf("PE-0 Initial Conditions(long) local %ld rem(%ld)\n",
                    dst_long,ltmp);

            dst_long = shmem_long_cswap(src_long,*src_long,0,1);
            if (dst_long != 8) {
                printf("PE-%d dst_long %ld != 8?\n",me,dst_long);
                exit(1);
            }
            /* verify remote data */
            ltmp = shmem_long_g(src_long,1);
            if (ltmp != 0) {
                printf("PE-%d long rem(%ld) != 0?\n",me,ltmp);
                exit(1);
            }
            Vprintf("PE-0 1st long_cswap done: local %ld rem(%ld)\n",
                    dst_long,ltmp);

            dst_long = shmem_long_cswap(src_long,0,dst_long,1);
            if (dst_long != 0) {
                printf("PE-%d dst_long %ld != 0?\n",me,dst_long);
                exit(1);
            }
            /* verify remote data */
            ltmp = shmem_long_g(src_long,1);
            if (ltmp != 8) {
                printf("PE-%d long rem(%ld) != 8?\n",me,ltmp);
                exit(1);
            }
            Vprintf("PE-0 2nd long_swap done: local %ld rem(%ld)\n",
                    dst_long,ltmp);

            /* cswap() should not swap as cond(0) != remote(8) */
            dst_long = shmem_long_cswap(src_long,0,0,1);
            if (dst_long != 8) {
                printf("PE-%d long no-swap returned dst_long %ld != 8?\n",
                        me,dst_long);
                exit(1);
            }
            /* verify previous cswap() did not swap */
            ltmp = shmem_long_g(src_long,1);
            if (ltmp != 8) {
                printf("PE-%d failed cond long_cswap() swapped? rem(%ld) != 8?\n",
                        me,ltmp);
                exit(1);
            }

            /* long long swap */
            lltmp = shmem_longlong_g(src_llong,1);
            Vprintf("PE-0 Initial Conditions(long long) local %lld rem(%lld)\n",
                    dst_llong,lltmp);

            dst_llong = shmem_longlong_cswap(src_llong,*src_llong,0,1);
            if (dst_llong != 16) {
                printf("PE-%d dst_llong %lld != 16?\n",me,dst_llong);
                exit(1);
            }
            /* verify remote data */
            lltmp = shmem_longlong_g(src_llong,1);
            if (lltmp != 0) {
                printf("PE-%d longlong rem(%lld) != 0?\n",me,lltmp);
                exit(1);
            }
            Vprintf("PE-0 1st longlong_cswap done: local %lld rem(%lld)\n",
                    dst_llong, lltmp);

            dst_llong = shmem_longlong_cswap(src_llong,0,dst_llong,1);
            if (dst_llong != 0) {
                printf("PE-%d dst_llong %lld != 0?\n",me,dst_llong);
                exit(1);
            }
            /* verify remote data */
            lltmp = shmem_longlong_g(src_llong,1);
            if (lltmp != 16) {
                printf("PE-%d long long rem(%lld) != 16?\n",me,lltmp);
                exit(1);
            }
            Vprintf("PE-0 2nd longlong_swap done: local %lld rem(%lld)\n",
                    dst_llong,lltmp);

            /* cswap() should not swap as cond(0) != remote(8) */
            dst_llong = shmem_longlong_cswap(src_llong,0,0,1);
            if (dst_llong != 16) {
                printf("PE-%d longlong no-swap returned dst_llong %lld != 16?\n",
                        me,dst_llong);
                exit(1);
            }
            /* verify previous cswap() did not swap */
            lltmp = shmem_longlong_g(src_llong,1);
            if (lltmp != 16) {
                printf("PE-0 failed cond longlong_cswap() swapped? rem(%lld) != 16?\n",
                        lltmp);
                exit(1);
            }
        }
        else {
            if (!shmem_addr_accessible(src_int,0)) {
                printf("PE-%d local src_int %p not accessible from PE-%d?\n",
                        me, (void*)src_int, 0);
                exit(1);
            }
            if (!shmem_addr_accessible(src_long,0)) {
                printf("PE-%d local src_long %p not accessible from PE-%d?\n",
                        me, (void*)src_long, 0);
                exit(1);
            }
            if (!shmem_addr_accessible(src_llong,0)) {
                printf("PE-%d local src_llong %p not accessible from PE-%d?\n",
                        me, (void*)src_llong, 0);
                exit(1);
            }
        }
        shmem_barrier_all();

        /* shmem_*fadd() exercise */

        if (me == 0) {
            itmp = 0;
            ltmp = 0;
            lltmp = 0;
            *src_int = 0;
            *src_long = 0;
            *src_llong = 0;
        }
        shmem_barrier_all();

        (void)shmem_int_fadd( &itmp, me+1, 0 );
        (void)shmem_long_fadd( &ltmp, me+1, 0 );
        (void)shmem_longlong_fadd( &lltmp, me+1, 0 );

        shmem_barrier_all();

        if (me == 0) {
            int tot;

            for(pe=0,tot=0; pe < num_pes; pe++)
                tot += pe+1;

            if ( itmp != tot )
                printf("fadd() total %d != expected %d?\n",itmp,tot);

            if ( ltmp != (long)tot )
                printf("fadd() total %ld != expected %d?\n",ltmp,tot);

            if ( lltmp != (long long)tot )
                printf("fadd() total %lld != expected %d?\n",lltmp,tot);
        }
        shmem_barrier_all();

        (void)shmem_int_finc(src_int,0);
        (void)shmem_long_finc(src_long,0);
        (void)shmem_longlong_finc(src_llong,0);

        shmem_barrier_all();

        if (me == 0) {
            int tot = num_pes;

            if ( *src_int != tot )
                printf("finc() total %d != expected %d?\n",*src_int,tot);

            if ( *src_long != (long)tot )
                printf("finc() total %ld != expected %d?\n",*src_long,tot);

            if ( *src_llong != (long long)tot )
                printf("finc() total %lld != expected %d?\n",*src_llong,tot);
        }
        shmem_barrier_all();

        shfree(src_int);
        shfree(src_long);
        shfree(src_llong);
    }

    if (Verbose)
        fprintf(stderr,"[%d] exit\n",_my_pe());

    return 0;
}
static int
check_it (void *addr)
{
    return shmem_addr_accessible (addr, 1);
}