示例#1
0
int
main (int argc, char **argv)
{
  int me;
  int slp;

  start_pes (0);
  me = shmem_my_pe ();
  slp = 1;

  shmem_barrier_all ();

  if (me == 1)
    {
      sleep (3);
    }

  shmem_set_lock (&L);

  printf ("%d: sleeping %d second%s...\n", me, slp, slp == 1 ? "" : "s");
  sleep (slp);
  printf ("%d: sleeping...done\n", me);

  shmem_clear_lock (&L);

  shmem_barrier_all ();

  return 0;
}
示例#2
0
/*
 * from a given PE, I want to update index "idx", which might be
 * stored somewhere else
 */
void
table_update (int nv, int idx)
{
  const int q = OWNER (idx);	/* PE that owns this index */
  const int off = OFFSET (idx);	/* local table offset */

  shmem_set_lock (& lock[idx]);

  shmem_int_p (& table[off], nv, q);

  shmem_clear_lock (& lock[idx]);
}
/****************************************************************************
 * Place for Test Item functions
 ***************************************************************************/
static int test_item1(void)
{
    int rc = TC_PASS;
    long* shmem_addr = NULL;
    int my_proc = 0;
    int root = 0;
    int i = 0, j = 0;
    long original_value, prev_value, new_value, check_value;
    long *lock_value = 0;

    my_proc = _my_pe();

    shmem_addr = shmalloc(sizeof(*shmem_addr));
    lock_value = shmalloc(sizeof(*lock_value));
    *lock_value = 0;

    shmem_barrier_all();
    if (my_proc < (int)sizeof(long))
    {
        for (i = 0; ((i < COUNT_VALUE) && (rc == TC_PASS)); i++)
        {
            shmem_long_get(&original_value, shmem_addr, 1, root);
            shmem_set_lock(lock_value);
            new_value = my_proc;
            prev_value = shmem_long_cswap(shmem_addr, original_value, new_value, root);
            for (j = 0; j < CHECK_COUNT_VALUE; j++)
            {
                shmem_long_get(&check_value, shmem_addr, 1, root);

                if (check_value != new_value && check_value != prev_value)
                {
                    rc = TC_FAIL;
                    break;
                }
            }
            shmem_clear_lock(lock_value);
        }
    }

    if (shmem_addr)
    {
        shfree(shmem_addr);
    }

    shfree(lock_value);

    return rc;
}
示例#4
0
/****************************************************************************
 * Test Case processing procedure
 ***************************************************************************/
int osh_lock_tc2(const TE_NODE *node, int argc, const char *argv[])
{
    //This is a stress test which makes sure the distributed locking is not hanging
    long *test_variable = shmalloc(sizeof(long));
    int number_of_iterations = 10;
    int i = 0;

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

    *test_variable = 0;
    shmem_barrier_all();
    for (i = 0; i < number_of_iterations; i++)
    {
        shmem_set_lock(test_variable);
        shmem_clear_lock(test_variable);
    }
    shmem_barrier_all();

    shfree(test_variable);

    return TC_PASS;
}
示例#5
0
void FORTRANIFY (shmem_set_lock) (long *lock)
{
    shmem_set_lock (lock);
}
int main(int argc, char **argv)
{
  int i,j;
  long modj,oldj,oldxmodj,newcount;
  int my_pe,n_pes;
  size_t max_elements_bytes;
  static long *x;

  shmem_init();
  my_pe = shmem_my_pe();
  n_pes = shmem_n_pes();
#ifdef HAVE_SET_CACHE_INV
  shmem_set_cache_inv();
#endif

/*  fail if trying to use only one processor  */
  if ( n_pes  <= 1 ){
        fprintf(stderr, "FAIL - test requires at least two PEs\n");
        exit(1);
  }

  if(my_pe == 0)
    fprintf(stderr, "shmem_lock_set_clear(%s) n_pes=%d\n", argv[0],n_pes);

/*  shmalloc x on all pes (only use the one on PE 0)  */

  max_elements_bytes = (size_t) (sizeof(long) * n_pes);
  x = shmem_malloc( max_elements_bytes );
  for(i=0; i<n_pes; i++)
    x[i] = 0;
  count = 0;
  shmem_barrier_all();

  for(i=0; i<ITER; i++) {
    if (my_pe != 0) {
      /* emulate  oldj = shmem_long_finc(&count, 0); */
      shmem_set_lock(&lock);
      shmem_long_get(&oldj,&count,1,0);   /* get oldj from PE 0's count */
      newcount = oldj+1;
      shmem_long_put(&count,&newcount,1,0);  /* update count on PE 0 */
      shmem_quiet;                        /* insure that write completes */
      shmem_clear_lock(&lock);
      /* end of emulation */
      modj = (oldj % (n_pes-1));  /* PE 0 is just the counter/checker */
        /* increment value in x[modj] */
      oldxmodj = shmem_long_finc(&x[modj], 0); 
      /* printf("PE=%d,oldj=%ld,modj=%ld,oldxmodj=%ld\n",my_pe,oldj,modj,oldxmodj); */
    }
  }
  shmem_barrier_all();

  if (my_pe == 0) {         /* check x[j] array on PE 0 */
    for(j=1 ; j<n_pes; j++) {
      if (x[j-1] != (long) ITER)
        fprintf(stderr, "FAIL PE %d of %d: x[%d] = %ld expected = %ld\n", 
                         my_pe, n_pes, j-1, x[j-1], (long) ITER);
    }
  }

  shmem_barrier_all();
#ifdef NEEDS_FINALIZE
  shmem_finalize(); 
#endif
  return 0;
}