int main(int argc, char *argv[]) {
    int n = 100;
    // int n1=101;
    start_pes(0);
    int nn = (n-1) / _num_pes();
    int n_local0 = 1 + _my_pe() * nn;
    int n_local1 = 1 + (_my_pe()+1) * nn;
    // allocate only local part + ghost zone of the arrays x,y
    float *x, *y;

  
    x = (float*) malloc((n_local1 - n_local0 + 2)*sizeof(float));
    y = (float*) malloc((n_local1 - n_local0 + 2)*sizeof(float));  // forgot shmalloc

    shmem_barrier_all();

    //... // fill x, y

    // fill ghost zone
    if (_my_pe() > 0)
	shmem_float_get(x,y,n1,1); // extra code
    shmem_float_put(y,x, 1, _my_pe()-1);

    shmem_barrier_all();

    // do computation
    float e = 0;
    int i;
    for (i=n_local0; i<n_local1; ++i) {
	x[i] += ( y[i+1] + y[i-1] )*.5;
	e += y[i] * y[i];
    }

    static float work[_SHMEM_REDUCE_SYNC_SIZE];
    static long sync[_SHMEM_REDUCE_SYNC_SIZE];
    static float el, es;
    el = e;
    shmem_float_sum_to_all(&es, &el, 1,
			   0, 0, _num_pes(), work, sync);
    e = es;

    // ... // output x, e

    x += (n_local0 - 1);
    y += (n_local0 - 1);
    shfree(x);
    shfree(y);
    return 0;
}
示例#2
0
/*
 * _glio_group_init
 *
 * Initialize a group based on the type of program we're called from.
 */
void
_glio_group_init(glio_group_t *gg)
{
	int	groupsz, myrank;

	if (gg->grtype != GR_DEFAULT) 
		return;

	switch (_glio_progtype()) {
		case GR_SHMEM:
			gg->grtype	= GR_SHMEM;
			gg->groupsz	= _num_pes();
			gg->myrank	= _my_pe();
			gg->u.shmem.group	= SHMEM_GROUP_WORLD;
			break;

		case GR_MPI:
			gg->grtype	= GR_MPI;

			ckMPIerr( MPI_Comm_size(MPI_COMM_WORLD, &groupsz) );
			gg->groupsz	= groupsz;

			ckMPIerr( MPI_Comm_rank(MPI_COMM_WORLD, &myrank) );
			gg->myrank	= myrank;

			gg->u.MPI.comm	= MPI_COMM_WORLD;
			break;

		default:
			gg->grtype	= GR_ONE;
			gg->groupsz	= 1;
			gg->myrank	= 0;
			break;
	}
}
示例#3
0
int shmem_pe_accessible(int pe)
{
    RUNTIME_CHECK_INIT();

    /* Assume that everything between 0 and num_pes() is reachable. */
    return 0 <= pe && pe < _num_pes() ? 1 : 0;
}
示例#4
0
int oshmem_shmem_preconnect_all(void)
{
    int rc = OSHMEM_SUCCESS;

    /* force qp creation and rkey exchange for memheap. Does not force exchange of static vars */
    if (oshmem_preconnect_all) {
        long val;
        int nproc = 0;
        int i;

        val = 0xdeadbeaf;

        if (!preconnect_value) {
            rc =
                    MCA_MEMHEAP_CALL(private_alloc(sizeof(long), (void **)&preconnect_value));
        }
        if (!preconnect_value || (rc != OSHMEM_SUCCESS)) {
            SHMEM_API_ERROR("shmem_preconnect_all failed");
            return OSHMEM_ERR_OUT_OF_RESOURCE;
        }
        nproc = _num_pes();
        for (i = 0; i < nproc; i++) {
            shmem_long_p(preconnect_value, val, i);
        }
        shmem_fence();
        shmem_barrier_all();
        SHMEM_API_VERBOSE(5, "Preconnected all PEs");
    }

    return OSHMEM_SUCCESS;
}
/* Performance test for shmem_broadcast32 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <shmem.h>
long pSyncA[_SHMEM_BCAST_SYNC_SIZE];
long pSyncB[_SHMEM_BCAST_SYNC_SIZE];

#define N_ELEMENTS 25600/*Data size chosen to be able to capture time required*/
  int
main(void)
{
  int i,j,k;
  int *target;
  int *source;
  int me, npes;
  struct timeval start, end;
  long time_taken,start_time,end_time;

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

  source = (int *) shmalloc( N_ELEMENTS * sizeof(*source) );

  time_taken = 0;

  for (i = 0; i < N_ELEMENTS; i += 1) {
    source[i] = i + 1;
  }
  target = (int *) shmalloc( N_ELEMENTS * sizeof(*target) );
  for (i = 0; i < N_ELEMENTS; i += 1) {
    target[i] = -90;
  }
  for (i = 0; i < _SHMEM_BCAST_SYNC_SIZE; i += 1) {
    pSyncA[i] = _SHMEM_SYNC_VALUE;
    pSyncB[i] = _SHMEM_SYNC_VALUE;
  }
  shmem_barrier_all();

  for(i=0;i<10000;i++){
    gettimeofday(&start, NULL);

    start_time = (start.tv_sec * 1000000.0) + start.tv_usec;

    /* alternate between 2 pSync arrays to synchronize
     * consequent collectives of even and odd iterations */
    if(i % 2)
     shmem_broadcast32(target, source, N_ELEMENTS, 0, 0, 0, npes, pSyncA);
    else
     shmem_broadcast32(target, source, N_ELEMENTS, 0, 0, 0, npes, pSyncB);

    gettimeofday(&end, NULL);

    end_time = (end.tv_sec * 1000000.0) + end.tv_usec;
    if(me==0){
      time_taken = time_taken + (end_time - start_time);
    }

  }
  if(me == 0)
    printf("Time required for a broadcast of 100 Kbytes of data, with %d PEs is %ld microseconds\n",npes,time_taken/10000);

  shmem_barrier_all();

  shfree(target);
  shfree(source);
  return 0;
  }
示例#6
0
/* platform specific initialization */
void vt_pform_init() {
  struct timeval tp;
  static ApTeam_t app;
  int i;

#if TIMER == TIMER_RTC
  vt_ticks_per_sec = (uint64_t)sysconf(_SC_SV2_USER_TIME_RATE);
# pragma omp parallel
  {
    gettimeofday(&tp, 0);
    vt_rtc_base = _rtc();
  }
#elif TIMER == TIMER_GETTIMEOFDAY
  gettimeofday(&tp, 0);
  vt_time_base = tp.tv_sec - (tp.tv_sec & 0xFFFF);
#elif TIMER == TIMER_PAPI_REAL_USEC
  vt_time_base = vt_metric_real_usec();
#endif

  if (apteamctl(ApTeam_Status, 0, 0, &app) == 1) {
    vt_mspmode = (app.flags & APTEAM_MSP);
    app.pes = (ApPe_t*)malloc(app.pecount * sizeof(ApPe_t));
    if (apteamctl(ApTeam_Status, 0, 0, &app) == 1) {
      for (i=0; i<_num_pes(); i++) {
        if (_my_pe() == app.pes[i].lpe) vt_nodeid = (long)app.pes[i].place;
      }
    }
  }
}
static int test_item2(void)
{
    int rc = TC_PASS;
    TYPE_VALUE* shmem_addr = NULL;
    TYPE_VALUE my_value = 0;
    TYPE_VALUE peer_value = 0;
    TYPE_VALUE expect_value = 0;
    int num_proc = 0;
    int my_proc = 0;
    int peer_proc = 0;

    num_proc = _num_pes();
    my_proc = _my_pe();

    shmem_addr = shmalloc(sizeof(*shmem_addr));
    if (shmem_addr)
    {
        TYPE_VALUE value = -1;

        /* Set my value */
        my_value = (-1);
        *shmem_addr = my_value;

        /* Define peer and it value */
        peer_proc = (my_proc + 1) % num_proc;
        peer_value = (TYPE_VALUE)my_proc;

        /* Define expected value */
        expect_value = (TYPE_VALUE)(my_proc ? (my_proc - 1) : (num_proc - 1));

        /* This guarantees that PE set initial value before peer change one */
        shmem_barrier_all();

        /* Write value to peer */
        FUNC_VALUE(shmem_addr, peer_value, peer_proc);

        /* Get value put by peer:
         * These routines start the remote transfer and may return before the data
         * is delivered to the remote PE
         */
        wait_for_put_completion(peer_proc,10 /* wait for 10 secs */);
        value = *shmem_addr;

        rc = (sys_fcompare(expect_value, value) ? TC_PASS : TC_FAIL);

        log_debug(OSH_TC, "my(#%d:%Lf) peer(#%d:%Lf) expected = %Lf vs got = %Lf\n",
                           my_proc, (long double)my_value, peer_proc, (long double)peer_value, (long double)expect_value, (long double)value);
    }
    else
    {
        rc = TC_SETUP_FAIL;
    }

    if (shmem_addr)
    {
        shfree(shmem_addr);
    }

    return rc;
}
示例#8
0
int main(int argc, char * argv[])
{
	/* Get PE information */
	shmem_init();
	me = _my_pe();
	npes = _num_pes();

	/* Initialize and send on PE 0 */
	if (me == 0) {
		for (i = 0; i < 8; i++)
			src[i] = i + 1;
		/* Put source date at PE 0 to dest at PE 1+ */
		for (i = 1; i < npes; i++)
			shmem_put64(dest, src, 8 * sizeof(int) / 8, i);
	}

	/* Make sure the transfer is complete */
	shmem_barrier_all();

	/* Print from PE 1+ */
	if (me > 0) {
		printf("PE %d: %d", me, dest[0]);
		for (i = 1; i < 8; i++)
			printf(",%d", dest[i]);
		printf("\n");
	}
	shmem_finalize();

	return 0;
}
示例#9
0
int
main(int argc, char* argv[])
{
    int i, Verbose=0;
    char *pgm;

    if ((pgm=strrchr(argv[0],'/')))
        pgm++;
    else
        pgm = argv[0];

	if (argc > 1) {
        if (strncmp(argv[1],"-v",3) == 0)
            Verbose=1;
        else if (strncmp(argv[1],"-h",3) == 0) {
            fprintf(stderr,"usage: %s {v(verbose)|h(help)}\n",pgm);
            exit(1);
        }
    }

    for (i = 0; i < _SHMEM_REDUCE_SYNC_SIZE; i += 1) {
        pSync[i] = _SHMEM_SYNC_VALUE;
    }

    start_pes(0);

    for (i = 0; i < N; i += 1) {
        src[i] = _my_pe() + i;
    }
    shmem_barrier_all();

    shmem_long_max_to_all(dst, src, N, 0, 0, _num_pes(), pWrk, pSync);

    if (Verbose) {
        printf("%d/%d	dst =", _my_pe(), _num_pes() );
        for (i = 0; i < N; i+= 1) {
            printf(" %ld", dst[i]);
        }
        printf("\n");
    }

    for (i = 0; i < N; i+= 1) {
        if (dst[i] != _num_pes() - 1 + i) return 1;
    }

    return 0;
}
示例#10
0
int osh_coll_tc3(const TE_NODE *node, int argc, const char *argv[])
{
    /* General initialisations            */

    int ii, numprocs, master;
    static int32_t source[10] = { 1, 2, 3, 4, 5,
                                  6, 7, 8, 9, 10
                                };
    static int32_t target[10];

    int nlong;
    long *pSync = 0;

    int status = TC_PASS;

    UNREFERENCED_PARAMETER(node);
    UNREFERENCED_PARAMETER(argc);
    UNREFERENCED_PARAMETER(argv);

    numprocs = _num_pes();

    master = 1;
    nlong = 10;

    if (numprocs == 1)
    {
        log_debug(OSH_TC, "Using more than 1 CPU makes the tests of this program more interesting\n");
        return TC_SETUP_FAIL;
    }

    for (ii = 0; ii < nlong; ii++)
        target[ii] = 0;

    pSync = NULL;

    pSync = shmalloc(sizeof(long) *_SHMEM_COLLECT_SYNC_SIZE);

    for (ii=0; ii < _SHMEM_COLLECT_SYNC_SIZE; ii++) {
        pSync[ii] = _SHMEM_SYNC_VALUE;
    }

    shmem_barrier_all();      /* Wait for all CPUs to initialize pSync */

    /* Broadcast function             */

    if (_my_pe()%2 == 1)
        shmem_broadcast32(target, source, nlong, 0, 1, 1,
                          numprocs/2, pSync);     /* local master CPU = 0 */

    if ((_my_pe()%2 == 1) && (_my_pe() != master))
        for (ii = 0; ii < nlong; ii++)
            if (target[ii] != (ii + 1))
                status = TC_FAIL;

    if (pSync) {
        shfree(pSync);
    }
    return status;
}
static int test_item2(void)
{
    int rc = TC_PASS;
    TYPE_VALUE* shmem_addr = NULL;
    TYPE_VALUE my_value = 0;
    TYPE_VALUE expect_value = 0;
    int num_proc = 0;
    int my_proc = 0;
    int peer_proc = 0;
    int i = 0;

    num_proc = _num_pes();
    my_proc = _my_pe();

    shmem_addr = shmalloc(sizeof(*shmem_addr));
    if (shmem_addr)
    {
        TYPE_VALUE value = 0;

        /* Store my value */
        my_value = (TYPE_VALUE)my_proc;
        *shmem_addr = 0;

        /* Define peer */
        peer_proc = (my_proc + 1) % num_proc;

        /* Define expected value */
        expect_value = ( my_proc == 0 ? (num_proc - 1) * __cycle_count : (my_proc - 1) * __cycle_count);

        shmem_barrier_all();
        for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++)
        {
            value = FUNC_VALUE(shmem_addr, my_value, peer_proc);
            if (value != (my_value * i))
            {
                break;
            }
        }
        shmem_barrier_all();

        value = *shmem_addr;
        rc = (expect_value == value ? TC_PASS : TC_FAIL);

        log_debug(OSH_TC, "my(#%d:%lld) expected = %lld vs got = %lld\n",
                           my_proc, (INT64_TYPE)my_value, (INT64_TYPE)expect_value, (INT64_TYPE)value);
    }
    else
    {
        rc = TC_SETUP_FAIL;
    }

    if (shmem_addr)
    {
        shfree(shmem_addr);
    }

    return rc;
}
/****************************************************************************
 * Place for Test Item functions
 ***************************************************************************/
static int test_item1(void)
{
    int rc = TC_PASS;
    TYPE_VALUE* shmem_addr = NULL;
    TYPE_VALUE my_value = 0;
    TYPE_VALUE expect_value = 0;
    int num_proc = 0;
    int my_proc = 0;
    int peer_proc = 0;
    int i = 0;

    num_proc = _num_pes();
    my_proc = _my_pe();

    shmem_addr = shmalloc(sizeof(*shmem_addr));
    if (shmem_addr)
    {
        TYPE_VALUE value = 0;

        /* Store my value */
        my_value = (TYPE_VALUE)my_proc;
        *shmem_addr = DEFAULT_VALUE;

        /* Define peer */
        peer_proc = (my_proc + 1) % num_proc;

        /* Define expected value */
        expect_value = (TYPE_VALUE)(( my_proc == 0 ? (num_proc - 1) : (my_proc - 1) ) + (__cycle_count - 1));

        shmem_barrier_all();
        for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++)
        {
            value = FUNC_VALUE(shmem_addr, (my_value + i), peer_proc);
            if  ( ((i >0 ) && (!sys_fcompare(value, my_value + i - 1))) || ((i == 0) && (!sys_fcompare(value, DEFAULT_VALUE))) )
            {
                break;
            }
        }
        shmem_barrier_all();

        value = *shmem_addr;
        rc = (sys_fcompare(expect_value, value) ? TC_PASS : TC_FAIL);

        log_debug(OSH_TC, "my(#%d:%Lf) expected = %Lf vs got = %Lf\n",
                           my_proc, (long double)my_value, (long double)expect_value, (long double)value);
    }
    else
    {
        rc = TC_SETUP_FAIL;
    }

    if (shmem_addr)
    {
        shfree(shmem_addr);
    }

    return rc;
}
/* OP to root, allocated */
static int test_item1(void)
{
    int rc = TC_PASS;
    TYPE_VALUE* shmem_addr = NULL;
    TYPE_VALUE my_value = 0;
    TYPE_VALUE expect_value = 0;
    int num_proc = 0;
    int my_proc = 0;
    int root_proc = 0;
    int i;
    int j;

    num_proc = _num_pes();
    my_proc = _my_pe();

    shmem_addr = shmalloc(sizeof(*shmem_addr));
    if (shmem_addr)
    {
        TYPE_VALUE value = 0;

        /* Store my value */
        my_value = (TYPE_VALUE)PROC_VALUE(my_proc);
        *shmem_addr = 0;

        /* Define expected value */
        if (my_proc == root_proc) {
            /* if root proc */
            for (j = 0; j < num_proc; j++) {
                for (i = 0; i < __cycle_count; i++) {
                    expect_value ^= PROC_VALUE(i + j);
                }
            }
        }

        shmem_barrier_all();
        for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++)
        {
            FUNC_VALUE(shmem_addr, PROC_VALUE(i + my_proc), root_proc);
        }
        shmem_barrier_all();

        value = *shmem_addr;
        rc = (expect_value == value ? TC_PASS : TC_FAIL);
        log_debug(OSH_TC, "my(#%d:%lld) expected = %lld vs got = %lld\n",
                           my_proc, (INT64_TYPE)my_value, (INT64_TYPE)expect_value, (INT64_TYPE)value);
    }
    else
    {
        rc = TC_SETUP_FAIL;
    }

    if (shmem_addr)
    {
        shfree(shmem_addr);
    }

    return rc;
}
static int test_item3(void)
{
    int rc = TC_PASS;
    static TYPE_VALUE shmem_value = 0;
    TYPE_VALUE* shmem_addr = &shmem_value;
    TYPE_VALUE my_value = 0;
    TYPE_VALUE expect_value = 0;
    int num_proc = 0;
    int my_proc = 0;
    int peer_proc = 0;
    int i = 0;

    num_proc = _num_pes();
    my_proc = _my_pe();

    {
        TYPE_VALUE value = 0;

        /* Store my value */
        my_value = (TYPE_VALUE)my_proc;
        *shmem_addr = DEFAULT_VALUE;

        /* Define peer */
        peer_proc = (my_proc + 1) % num_proc;

        /* Define expected value */
        expect_value = ( my_proc == 0 ? (num_proc - 1) : (my_proc - 1) ) + (__cycle_count - 1);

        shmem_barrier_all();
        for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++)
        {
            value = num_proc + __cycle_count;
            value = FUNC_VALUE(shmem_addr, value, (my_value + i), peer_proc);
            if  ( ((i > 0 ) && (value != (my_value + i - 1))) || ((i == 0) && (value != DEFAULT_VALUE)) )
            {
                break;
            }

            value = ( i == 0 ? DEFAULT_VALUE : (my_value + i - 1));
            value = FUNC_VALUE(shmem_addr, value, (my_value + i), peer_proc);
            if  ( ((i > 0 ) && (value != (my_value + i - 1))) || ((i == 0) && (value != DEFAULT_VALUE)) )
            {
                break;
            }
        }
        shmem_barrier_all();

        value = *shmem_addr;
        rc = (expect_value == value ? TC_PASS : TC_FAIL);

        log_debug(OSH_TC, "my(#%d:%lld) expected = %lld vs got = %lld\n",
                           my_proc, (INT64_TYPE)my_value, (INT64_TYPE)expect_value, (INT64_TYPE)value);
    }

    return rc;
}
示例#15
0
static int test_item2(void)
{
    int rc = TC_PASS;
    TYPE_VALUE* shmem_addr = NULL;
    TYPE_VALUE my_value = {0, 0};
    TYPE_VALUE peer_value = {0, 0};
    TYPE_VALUE expect_value = {0, 0};
    int num_proc = 0;
    int my_proc = 0;
    int peer_proc = 0;

    num_proc = _num_pes();
    my_proc = _my_pe();

    shmem_addr = shmalloc(sizeof(*shmem_addr));
    if (shmem_addr)
    {
        TYPE_VALUE value = {-1, 0};

        /* Set my value */
        my_value.field1 = my_proc;
        memcpy(shmem_addr, &my_value, sizeof(my_value));

        /* Define peer and it value */
        peer_proc = (my_proc + 1) % num_proc;
        peer_value.field1 = peer_proc;

        /* Define expected value */
        memcpy(&expect_value, &peer_value, sizeof(peer_value));

        /* Wait is set instead of barrier to give some time to all PE for setting their values */
        shmem_barrier_all();

        /* Get value from peer */
        FUNC_VALUE(&value, shmem_addr, 1, peer_proc);

        rc = (compare_buffer((unsigned char*)&expect_value, (unsigned char*)&value, sizeof(value), NULL) ? TC_PASS : TC_FAIL);

        log_debug(OSH_TC, "my(#%d:%lld.%lld) peer(#%d:%lld.%lld) expected = %lld.%lld actual = %lld.%lld\n",
            my_proc, (INT64_TYPE)my_value.field1, (INT64_TYPE)my_value.field2,
            peer_proc, (INT64_TYPE)peer_value.field1, (INT64_TYPE)peer_value.field2,
            (INT64_TYPE)expect_value.field1, (INT64_TYPE)expect_value.field2,
            (INT64_TYPE)value.field1, (INT64_TYPE)value.field2);
    }
    else
    {
        rc = TC_SETUP_FAIL;
    }

    if (shmem_addr)
    {
        shfree(shmem_addr);
    }

    return rc;
}
示例#16
0
static int test_item1(void)
{
    int rc = TC_PASS;
    int num_proc = 0;
    int my_proc = 0;
    int peer;
    int size;
    char *buf;
    int test_byte;
    int max_heap_size_per_proc;

    num_proc = _num_pes();
    my_proc = _my_pe();
    peer = (my_proc + 1) % num_proc;

    max_heap_size_per_proc = 1L << (sys_log2((memheap_size() * HEAP_USAGE_PERCENT)/ num_proc) - 1);
    max_heap_size_per_proc = (max_heap_size_per_proc > MAX_SIZE) ? MAX_SIZE : max_heap_size_per_proc;
    buf = (char *)shmalloc(max_heap_size_per_proc * num_proc);
    if (!buf)
    {
        log_error(OSH_TC, "shmalloc(%d)\n", max_heap_size_per_proc * num_proc);
        return TC_SETUP_FAIL;
    }

    size = 1L << sys_log2(num_proc);
    size = ((size - 2) > 0) ? size : 4;
    log_debug(OSH_TC, "%d: buf = %p size=%d\n", my_proc, buf, size);
    for (; size <= max_heap_size_per_proc; size *=2)
    {
        memset(buf + max_heap_size_per_proc * my_proc, 1 + my_proc % (size - 2), max_heap_size_per_proc);
        log_debug(OSH_TC, "\n%d: b4 barrier size = %d\n", my_proc, size);
        shmem_barrier_all();
        log_debug(OSH_TC, "%d: b4 putmem size = %d  %p -> %p\n", my_proc, size,
                buf+max_heap_size_per_proc*my_proc, buf + max_heap_size_per_proc * my_proc);
        shmem_putmem(buf+max_heap_size_per_proc*my_proc, buf+max_heap_size_per_proc*my_proc, size, peer);
        shmem_fence();
        test_byte = 0;
        log_debug(OSH_TC, "%d: b4 getmem size = %d\n %p <- %p ", my_proc, size,
                &test_byte,
                buf+max_heap_size_per_proc*peer + size - 1
                );
        shmem_getmem(&test_byte, buf+max_heap_size_per_proc*my_proc + size - 1, 1, peer);

        log_debug(OSH_TC, "%d: after getmem size = %d result=%x\n", my_proc, size, test_byte);
        if (test_byte != 1 + my_proc % (size-2))
        {
            log_error(OSH_TC, "fence failed at size %d got = %x expected = %x\n", size, test_byte, 1 + my_proc % (size-2));
            rc = TC_FAIL;
        }

    }

    shfree(buf);
    log_debug(OSH_TC, rc == TC_PASS? "passed" : "failed");
    return rc;
}
/* OP to neighbour, allocated */
static int test_item2(void)
{
    int rc = TC_PASS;
    TYPE_VALUE* shmem_addr = NULL;
    TYPE_VALUE my_value = DEFAULT_VALUE;
    TYPE_VALUE expect_value = DEFAULT_VALUE;
    int num_proc = 0;
    int my_proc = 0;
    int peer_proc = 0;
    int i = 0;

    num_proc = _num_pes();
    my_proc = _my_pe();
    peer_proc = (my_proc + 1) % num_proc;

    shmem_addr = shmalloc(sizeof(*shmem_addr));
    if (shmem_addr)
    {
        TYPE_VALUE value = 0;

        /* Store my value */
        *shmem_addr = DEFAULT_VALUE;

        for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++) {
            my_value &= PROC_VALUE(i + my_proc + 1);
        }

        shmem_barrier_all();
        for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++) {
            value = FUNC_VALUE(shmem_addr, PROC_VALUE(i + peer_proc + 1), peer_proc);
            if (value != expect_value) {
                break;
            }
            expect_value = value & PROC_VALUE(i + peer_proc + 1);
        }
        shmem_barrier_all();

        value = *shmem_addr;
        rc = (my_value == value ? TC_PASS : TC_FAIL);

        log_debug(OSH_TC, "my(#%d:%lld) expected = %lld vs got = %lld\n",
                           my_proc, (INT64_TYPE)my_value, (INT64_TYPE)expect_value, (INT64_TYPE)value);
    }
    else
    {
        rc = TC_SETUP_FAIL;
    }

    if (shmem_addr)
    {
        shfree(shmem_addr);
    }

    return rc;
}
示例#18
0
文件: nc.c 项目: zhangxiaoyu11/mAMBER
static int
NC_init_pe(NC *ncp, int basepe) {
	if (basepe < 0 || basepe >= _num_pes()) {
		return NC_EINVAL; /* invalid base pe */
	}
	/* initialize common values */
	ncp->lock[LOCKNUMREC_VALUE] = 0;
	ncp->lock[LOCKNUMREC_LOCK] = 0;
	ncp->lock[LOCKNUMREC_SERVING] = 0;
	ncp->lock[LOCKNUMREC_BASEPE] =  basepe;
	return NC_NOERR;
}
static int test_item2(void)
{
    int rc = TC_PASS;
    TYPE_VALUE* shmem_addr = NULL;
    TYPE_VALUE my_value = 0;
    TYPE_VALUE peer_value = 0;
    TYPE_VALUE expect_value = 0;
    int num_proc = 0;
    int my_proc = 0;
    int peer_proc = 0;

    num_proc = _num_pes();
    my_proc = _my_pe();

    shmem_addr = shmalloc(sizeof(*shmem_addr));
    if (shmem_addr)
    {
        TYPE_VALUE value = -1;

        /* Set my value */
        my_value = (TYPE_VALUE)my_proc;
        *shmem_addr = my_value;

        /* Define peer and it value */
        peer_proc = (my_proc + 1) % num_proc;
        peer_value = (TYPE_VALUE)peer_proc;

        /* Define expected value */
        expect_value = peer_value;

        /* Wait is set instead of barrier to give some time to all PE for setting their values */
        shmem_barrier_all();

        /* Get value from peer */
        FUNC_VALUE(&value, shmem_addr, 1, peer_proc);

        rc = (sys_fcompare(expect_value, value) ? TC_PASS : TC_FAIL);

        log_debug(OSH_TC, "my(#%d:%Lf) peer(#%d:%Lf) expected = %Lf buffer size = %lld\n",
                           my_proc, (long double)my_value, peer_proc, (long double)peer_value, (long double)expect_value, (INT64_TYPE)1);
    }
    else
    {
        rc = TC_SETUP_FAIL;
    }

    if (shmem_addr)
    {
        shfree(shmem_addr);
    }

    return rc;
}
示例#20
0
int osh_basic_tc7(const TE_NODE *node, int argc, const char *argv[])
{
    int rc = TC_PASS;
    int me = _my_pe();
    int num_of_pes = _num_pes();
    //static int test_variable = 0;
    int value_to_set = 1;

    UNREFERENCED_PARAMETER(node);
    UNREFERENCED_PARAMETER(argc);
    UNREFERENCED_PARAMETER(argv);

    //just in case
    shmem_barrier_all();

    if (num_of_pes < 2)
    {
        rc = TC_SETUP_FAIL;
        goto FreeMemory;
    }

    //This test is for 2 ranks only
    if (me > 1)
    {
        goto FreeMemory;
    }

    if (0 == me)
    {
        int wait_time = 0;
        //wait for pe #1 to change my variable
        //and do some important work in the while
        while (!test_variable && wait_time < 5000000)
        {
            usleep(1000);
            wait_time += 1000;
        }

        if (!test_variable)
        {
            rc = TC_FAIL;
        }
    }
    else
    {
        shmem_int_put(&test_variable, &value_to_set, 1, 0);
    }

FreeMemory:
    shmem_barrier_all();

    return rc;
}
示例#21
0
struct pe_vars
init_openshmem (void)
{
    struct pe_vars v;

    start_pes(0);
    v.me = _my_pe();
    v.npes = _num_pes();
    v.pairs = v.npes / 2;
    v.nxtpe = v.me < v.pairs ? v.me + v.pairs : v.me - v.pairs;

    return v;
}
int oshmem_shmem_preconnect_all(void)
{
    int mca_value = 0;
    int rc = OSHMEM_SUCCESS;

    (void) mca_base_var_register("oshmem",
                                 "runtime",
                                 NULL,
                                 "preconnect_all",
                                 "Whether to force SHMEM processes to fully "
                                 "wire-up the connections between SHMEM "
                                 "processes during "
                                 "initialization (vs. making connections lazily -- "
                                 "upon the first SHMEM traffic between each "
                                 "process peer pair)",
                                 MCA_BASE_VAR_TYPE_INT,
                                 NULL,
                                 0,
                                 MCA_BASE_VAR_FLAG_SETTABLE,
                                 OPAL_INFO_LVL_9,
                                 MCA_BASE_VAR_SCOPE_READONLY,
                                 &mca_value);

    /* force qp creation and rkey exchange for memheap. Does not force exchange of static vars */
    if (mca_value) {
        long val;
        int nproc = 0;
        int i;

        val = 0xdeadbeaf;

        if (!preconnect_value) {
            rc =
                MCA_MEMHEAP_CALL(private_alloc(sizeof(long), (void **)&preconnect_value));
        }
        if (!preconnect_value || (rc != OSHMEM_SUCCESS)) {
            SHMEM_API_ERROR("shmem_preconnect_all failed");
            return OSHMEM_ERR_OUT_OF_RESOURCE;
        }
        nproc = _num_pes();
        for (i = 0; i < nproc; i++) {
            shmem_long_p(preconnect_value, val, i);
        }
        shmem_fence();
        shmem_barrier_all();
        SHMEM_API_VERBOSE(5, "Preconnected all PEs");
    }

    return OSHMEM_SUCCESS;
}
static int test_item3(void)
{
    int rc = TC_PASS;
    static TYPE_VALUE shmem_value = 0;
    TYPE_VALUE* shmem_addr = &shmem_value;
    TYPE_VALUE my_value = 0;
    TYPE_VALUE expect_value = 0;
    int num_proc = 0;
    int my_proc = 0;
    int peer_proc = 0;
    int i = 0;

    num_proc = _num_pes();
    my_proc = _my_pe();

    {
        TYPE_VALUE value = 0;

        /* Store my value */
        my_value = (TYPE_VALUE)1;
        *shmem_addr = 0;

        /* Define peer */
        peer_proc = (my_proc + 1) % num_proc;

        /* Define expected value */
        expect_value = __cycle_count;

        shmem_barrier_all();
        for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++)
        {
            FUNC_VALUE(shmem_addr, peer_proc);
        }
        shmem_barrier_all();

        value = *shmem_addr;
        rc = (expect_value == value ? TC_PASS : TC_FAIL);

        log_debug(OSH_TC, "my(#%d:%lld) expected = %lld vs got = %lld\n",
                           my_proc, (INT64_TYPE)my_value, (INT64_TYPE)expect_value, (INT64_TYPE)value);
    }

    return rc;
}
int main (void)
{
    static int aaa, bbb;
    int num_pes, my_pe, peer;

    start_pes(0);

    num_pes = _num_pes();
    my_pe = _my_pe();

    peer = (my_pe + 1) % num_pes;

    printf("Process %d gets message from %d (%d processes in ring)\n", my_pe, peer, num_pes);
    shmem_int_get(&aaa, &bbb, 1, peer);

    shmem_barrier_all();
    printf("Process %d exiting\n", my_pe);

    return 0;
}
int main(void)
{
   int i, me, npes;

   for (i = 0; i < _SHMEM_BARRIER_SYNC_SIZE; i += 1){
      pSync[i] = _SHMEM_SYNC_VALUE;
   }

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

   if(me % 2 == 0){
      x = 1000 + me;
      /*put to next even PE in a circular fashion*/
      shmem_int_p(&x, 4, (me+2)%npes);
      /*synchronize all even pes*/
      shmem_barrier(0, 1, (npes/2 + npes%2), pSync);
   }
   printf("%d: x = %d\n", me, x);
   return 0;
}
示例#26
0
文件: nc.c 项目: zhangxiaoyu11/mAMBER
/*ARGSUSED*/
int
nc_set_base_pe(int ncid, int pe)
{
#if _CRAYMPP && defined(LOCKNUMREC)
	int status;
	NC *ncp;
	shmem_t numrecs;

	if ((status = NC_check_id(ncid, &ncp)) != NC_NOERR) {
		return status;
	}
	if (pe < 0 || pe >= _num_pes()) {
		return NC_EINVAL; /* invalid base pe */
	}

	numrecs = (shmem_t) NC_get_numrecs(ncp);

	ncp->lock[LOCKNUMREC_VALUE] = (ushmem_t) numrecs;

	/* update serving & lock values for a "smooth" transition */
	/* note that the "real" server will being doing this as well */
	/* as all the rest in the group */
	/* must have syncronization before & after this step */
	shmem_short_get(
		(shmem_t *) ncp->lock + LOCKNUMREC_SERVING,
		(shmem_t *) ncp->lock + LOCKNUMREC_SERVING,
		1, ncp->lock[LOCKNUMREC_BASEPE]);

	shmem_short_get(
		(shmem_t *) ncp->lock + LOCKNUMREC_LOCK,
		(shmem_t *) ncp->lock + LOCKNUMREC_LOCK,
		1, ncp->lock[LOCKNUMREC_BASEPE]);

	/* complete transition */
	ncp->lock[LOCKNUMREC_BASEPE] = (ushmem_t) pe;

#endif /* _CRAYMPP && LOCKNUMREC */
	return NC_NOERR;
}
示例#27
0
int
main(void)
{
   int me, npes;

   setbuf(stdout, NULL);

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

   if (me == 0) {
      int i;
      for (i = 1; i < npes; i += 1) {
         printf("From %d: PE %d is ", me, i);
         printf("%s", shmem_pe_accessible(i) ? "" : "NOT ");
         printf("accessible\n");
      }
   }

   return 0;
}
/* OP to neighbour, static */
static int test_item3(void)
{
    int rc = TC_PASS;
    static TYPE_VALUE shmem_value = 0;
    TYPE_VALUE* shmem_addr = &shmem_value;
    TYPE_VALUE my_value = DEFAULT_VALUE;
    int num_proc = 0;
    int my_proc = 0;
    int peer_proc = 0;
    int i = 0;

    num_proc = _num_pes();
    my_proc = _my_pe();
    peer_proc = (my_proc + 1) % num_proc;

    TYPE_VALUE value = 0;

    /* Store my value */
    *shmem_addr = DEFAULT_VALUE;

    for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++) {
        my_value |= PROC_VALUE(i + my_proc + 1);
    }

    shmem_barrier_all();
    for (i = 0; (i < __cycle_count) && (rc == TC_PASS); i++) {
        FUNC_VALUE(shmem_addr, PROC_VALUE(i + peer_proc + 1), peer_proc);
    }
    shmem_barrier_all();

    value = *shmem_addr;
    rc = (my_value == value ? TC_PASS : TC_FAIL);

    log_debug(OSH_TC, "my(#%d) expected = %lld vs got = %lld\n",
                       my_proc, (INT64_TYPE)my_value, (INT64_TYPE)value);

    return rc;
}
示例#29
0
int
main(int argc, char* argv[])
{
    int me, npes;
    setbuf(stdout, NULL);
    start_pes(0);
    me = _my_pe();
    npes = _num_pes();
    if (me == 0) {
        int i;
        int verbose = (NULL == getenv("MAKELEVEL")) ? 1 : 0;
        for (i = 1; i < npes; i += 1) {
            if (verbose) {
                printf("From %d: PE %d is ", me, i);
                printf("%s", shmem_pe_accessible(i) ? "" : "NOT ");
                printf("accessible\n");
            }
            if (! shmem_pe_accessible(i)) return 1;
        }
    }
 
    return 0;
}
int main(void)
{
   int i, me, npes;
   int *target;

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

   source[0] = me * 2;
   source[1] = me * 2 + 1;
   target = (int *)shmalloc(sizeof(int) * npes * 2);
   for (i=0; i < _SHMEM_COLLECT_SYNC_SIZE; i++) {
      pSync[i] = _SHMEM_SYNC_VALUE;
   }
   shmem_barrier_all(); /* Wait for all PEs to initialize pSync */

   shmem_collect32(target, source, 2, 0, 0, npes, pSync);
   printf("%d: %d", me, target[0]);
   for (i = 1; i < npes * 2; i++)
      printf(", %d", target[i]);
   printf("\n");
   return 0;
}