Beispiel #1
0
static inline void gettest(int me, int iterations, int T, int S, int P)
{

    int i;

    if (me == 1) {
        pre_op_check(__func__, target[T], iterations, 1);

        shmem_int_p(&source[S], iterations, 0);
        shmem_fence();

        for (i = 0; i < iterations; i++)
            target[T] = shmem_int_g(&source[S], 0);

        shmem_int_p(&sync_pes[P], iterations, 0);

        post_op_check("get", target[T], iterations, 1);

    } else
        wait_until(&sync_pes[P], iterations, 0);

    if (verbose) {
        if (me == 0)
            printf("SHMEM %s finished\n", __func__);
    }
}
Beispiel #2
0
static int binary_search(int key) {
    int low, mid, high;

    low = 0;
    high = shmem_n_pes()*N_PER_PE;

    while(low < high) {
        int val;

        mid = low + (high-low)/2;
        val = shmem_int_g(&keys[mid%N_PER_PE], mid/N_PER_PE);

        if(val == key) {
            return mid;
        } else if(val < key) {
            low = mid;
        } else {
            high = mid;
        }
    }

    return -1;
}
int
main(int argc, char **argv)
{
  int i,j;
  int nextpe;
  int me, npes;
  int success1,success2,success3, success4, success5, success6, success7, success8;

  short dest1[N];
  int dest2[N];
  long dest3[N];
  long double dest4[N];
  long long dest5[N];
  double dest6[N];
  float dest7[N];
  char *dest8;
  short dest9;
  int dest10;
  long dest11;
  double dest12;
  float dest13;

  short *src1;
  int *src2;
  long *src3;
  long double *src4;
  long long *src5;
  double *src6;
  float *src7;
  char *src8;
  short *src9;
  int *src10;
  long *src11;
  double *src12;
  float *src13;


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

  if(npes>1){

    success1 =0;
    success2 =0;
    success3 =0;
    success4 =0;
    success5 =0;
    success6 =0;
    success7 =0;
    success8 =0;
    dest8 = (char *)malloc(N*sizeof(char));

    for (i = 0; i < N; i += 1) {
      dest1[i] = -9;
      dest2[i] = -9;
      dest3[i] = -9;
      dest4[i] = -9;
      dest5[i] = -9;
      dest6[i] = -9;
      dest7[i] = -9.0;
      dest8[i] = -9;
    }
    dest9 = -9;
    dest10 = -9;
    dest11 = -9;
    dest12 = -9;
    dest13 = -9;


    src1 = (short *)shmalloc( N * sizeof(*src1) );
    src2 = (int *)shmalloc( N * sizeof(*src2) );
    src3 = (long *)shmalloc( N * sizeof(*src3) );
    src4 = (long double *)shmalloc( N * sizeof(*src4) );
    src5 = (long long*)shmalloc( N * sizeof(*src5) );
    src6 = (double *)shmalloc( N * sizeof(*src6) );
    src7 = (float *)shmalloc( N * sizeof(*src7) );
    src8 = (char *)shmalloc( 4 * sizeof(*src8) );
    src9 = (short *)shmalloc( sizeof(*src9) );
    src10 = (int *)shmalloc( sizeof(*src10) );
    src11 = (long *)shmalloc( sizeof(*src11) );
    src12 = (double *)shmalloc( sizeof(*src12) );
    src13 = (float *)shmalloc( sizeof(*src13) );

    for (i = 0; i < N; i += 1) {
      src1[i] = (short)me;
      src2[i] = me;
      src3[i] = (long)me;
      src4[i] = (long double)me;
      src5[i] = (long long)me;
      src6[i] = (double)me;
      src7[i] = (float)me;
      src8[i] = (char)me;
    }
    *src9 = (short)me;
    *src10 = me;
    *src11 = (long)me;
    *src12 = (double)me;
    *src13 = (float)me;



    nextpe = (me + 1) % npes;

    /*Testing shmem_short_get, shmem_short_get, shmem_int_get, shmem_long_get, shmem_longdouble_get, shmem_longlong_get, shmem_double_get, shmem_float_get, shmem_getmem*/
    shmem_barrier_all();

    shmem_short_get(dest1, src1, N, nextpe);
    shmem_int_get(dest2, src2, N, nextpe);
    shmem_long_get(dest3, src3, N, nextpe);
    shmem_longdouble_get(dest4, src4, N, nextpe);
    shmem_longlong_get(dest5, src5, N, nextpe);
    shmem_double_get(dest6, src6, N, nextpe);
    shmem_float_get(dest7, src7, N, nextpe);
    shmem_getmem(dest8, src8, N*sizeof(char), nextpe);

    shmem_barrier_all();

    if(me == 0){
      for (i = 0; i < N; i += 1) {
        if(dest1[i] != ( 1)){
          success1=1;
        }
        if(dest2[i] != ( 1)){
          success2=1;
        }
        if(dest3[i] != ( 1)){
          success3=1;
        }
        if(dest4[i] != ( 1)){
          success4=1;
        }
        if(dest5[i] != ( 1)){
          success5=1;
        }
        if(dest6[i] != ( 1)){
          success6=1;
        }
        if(dest7[i] != ( 1)){
          success7=1;
        }
        if(dest8[i] != ( 1)){
          success8=1;
        }
      }

      if(success1==0)
        printf("Test shmem_short_get: Passed\n");  
      else
        printf("Test shmem_short_get: Failed\n");
      if(success2==0)
        printf("Test shmem_int_get: Passed\n");  
      else
        printf("Test shmem_int_get: Failed\n");
      if(success3==0)
        printf("Test shmem_long_get: Passed\n");  
      else
        printf("Test shmem_long_get: Failed\n");
      if(success4==0)
        printf("Test shmem_longdouble_get: Passed\n");  
      else
        printf("Test shmem_longdouble_get: Failed\n");
      if(success5==0)
        printf("Test shmem_longlong_get: Passed\n");  
      else
        printf("Test shmem_longlong_get: Failed\n");
      if(success6==0)
        printf("Test shmem_double_get: Passed\n");  
      else
        printf("Test shmem_double_get: Failed\n");
      if(success7==0)
        printf("Test shmem_float_get: Passed\n");  
      else
        printf("Test shmem_float_get: Failed\n");
      if(success8==0)
        printf("Test shmem_getmem: Passed\n");  
      else
        printf("Test shmem_getmem: Failed\n");

    }
    shmem_barrier_all();

    /*Testing shmem_get32, shmem_get64, shmem_get128 */
    if(sizeof(int)==4){
      for (i = 0; i < N; i += 1) {
        dest2[i] = -9;
        dest3[i] = -9;
        dest4[i] = -9;
      }
      success2 = 0;
      success3 = 0;
      success4 = 0;

      shmem_barrier_all();

      shmem_get32(dest2, src2, N, nextpe);
      shmem_get64(dest3, src3, N, nextpe);
      shmem_get128(dest4, src4, N, nextpe);

      shmem_barrier_all();

      if(me == 0){
        for (i = 0; i < N; i += 1) {
          if(dest2[i] != ( 1)){
            success2=1;
          }
          if(dest3[i] != ( 1)){
            success3=1;
          }
          if(dest4[i] != ( 1)){
            success4=1;
          }
        }
        if(success2==0)
          printf("Test shmem_get32: Passed\n");  
        else
          printf("Test shmem_get32: Failed\n");

        if(success3==0)
          printf("Test shmem_get64: Passed\n");  
        else
          printf("Test shmem_get64: Failed\n");

        if(success4==0)
          printf("Test shmem_get128: Passed\n");  
        else
          printf("Test shmem_get128: Failed\n");
      }
    }
    else if(sizeof(int)==8){
      for (i = 0; i < N; i += 1) {
        dest1[i] = -9;
        dest2[i] = -9;
        dest3[i] = -9;
      }
      success1 = 0;
      success2 = 0;
      success3 = 0;

      shmem_barrier_all();

      shmem_get32(dest1, src1, N, nextpe);
      shmem_get64(dest2, src2, N, nextpe);
      shmem_get128(dest3, src3, N, nextpe);

      shmem_barrier_all();

      if(me == 0){
        for (i = 0; i < N; i += 1) {
          if(dest1[i] != ( 1)){
            success1=1;
          }
          if(dest2[i] != ( 1)){
            success2=1;
          }
          if(dest3[i] != ( 1)){
            success3=1;
          }

        }
        if(success1==0)
          printf("Test shmem_get32: Passed\n");  
        else
          printf("Test shmem_get32: Failed\n");
        if(success2==0)
          printf("Test shmem_get64: Passed\n");  
        else
          printf("Test shmem_get64: Failed\n");

        if(success3==0)
          printf("Test shmem_get128: Passed\n");  
        else
          printf("Test shmem_get128: Failed\n");	
      }
    }	
	
	/* Testing shmem_iget32, shmem_iget64, shmem_iget128 */
	shmem_barrier_all();
	if(sizeof(int)==4){
      for (i = 0; i < N; i += 1) {
        dest2[i] = -9;
        dest3[i] = -9;
        dest4[i] = -9;
      }
      success2 = 0;
      success3 = 0;
      success4 = 0;

      shmem_barrier_all();

      shmem_iget32(dest2, src2, 1, 2, N/2, npes-1);
      shmem_iget64(dest3, src3, 1, 2, N/2, npes-1);
      shmem_iget128(dest4, src4, 1, 2, N/2, npes-1);

      shmem_barrier_all();

      if(me == 0){
        for (i = 0; i < N/2; i += 1) {
          if(dest2[i] != (npes-1)){
            success2=1;
          }
          if(dest3[i] != (npes-1)){
            success3=1;
          }
          if(dest4[i] != (npes-1)){
            success4=1;
          }
        }
        if(success2==0)
          printf("Test shmem_iget32: Passed\n");  
        else
          printf("Test shmem_iget32: Failed\n");

        if(success3==0)
          printf("Test shmem_iget64: Passed\n");  
        else
          printf("Test shmem_iget64: Failed\n");

        if(success4==0)
          printf("Test shmem_iget128: Passed\n");  
        else
          printf("Test shmem_iget128: Failed\n");
      }
    }
    else if(sizeof(int)==8){
      for (i = 0; i < N; i += 1) {
        dest1[i] = -9;
        dest2[i] = -9;
        dest3[i] = -9;
      }
      success1 = 0;
      success2 = 0;
      success3 = 0;

      shmem_barrier_all();

      shmem_iget32(dest1, src1, 1, 2, N/2, npes-1);
      shmem_iget64(dest2, src2, 1, 2, N/2, npes-1);
      shmem_iget128(dest3, src3, 1, 2, N/2, npes-1);

      shmem_barrier_all();

      if(me == 0){
        for (i = 0; i < N/2; i += 1) {
          if(dest1[i] != (npes-1)){
            success1=1;
          }
          if(dest2[i] != (npes-1)){
            success2=1;
          }
          if(dest3[i] != (npes-1)){
            success3=1;
          }

        }
        if(success1==0)
          printf("Test shmem_iget32: Passed\n");  
        else
          printf("Test shmem_iget32: Failed\n");
        if(success2==0)
          printf("Test shmem_iget64: Passed\n");  
        else
          printf("Test shmem_iget64: Failed\n");

        if(success3==0)
          printf("Test shmem_iget128: Passed\n");  
        else
          printf("Test shmem_iget128: Failed\n");	
      }
    }	
	
	/*Testing shmem_short_iget, shmem_int_iget, shmem_long_iget, shmem_double_iget, shmem_float_iget */
	for (i = 0; i < N; i += 1) {
	    dest1[i] = -9;
        dest2[i] = -9;
        dest3[i] = -9;
        dest6[i] = -9;
		dest7[i] = -9;
      }
      success1 = 0;
      success2 = 0;
      success3 = 0;
	  success6 = 0;
      success7 = 0;
      
    shmem_barrier_all();

    shmem_short_iget(dest1, src1, 1, 2, N/2, npes-1);
    shmem_int_iget(dest2, src2, 1, 2, N/2, npes-1);
    shmem_long_iget(dest3, src3, 1, 2, N/2, npes-1);
    shmem_double_iget(dest6, src6, 1, 2, N/2, npes-1);
    shmem_float_iget(dest7, src7, 1, 2, N/2, npes-1);
    
    shmem_barrier_all();

    if(me == 0){
      for (i = 0; i < N/2; i += 1) {
        if(dest1[i] != (npes-1)){
          success1=1;
        }
        if(dest2[i] != (npes-1)){
          success2=1;
        }
        if(dest3[i] != (npes-1)){
          success3=1;
        }
        if(dest6[i] != (npes-1)){
          success6=1;
        }
        if(dest7[i] != (npes-1)){
          success7=1;
        }
      }

      if(success1==0)
        printf("Test shmem_short_iget: Passed\n");  
      else
        printf("Test shmem_short_iget: Failed\n");
      if(success2==0)
        printf("Test shmem_int_iget: Passed\n");  
      else
        printf("Test shmem_int_iget: Failed\n");
      if(success3==0)
        printf("Test shmem_long_iget: Passed\n");  
      else
        printf("Test shmem_long_iget: Failed\n");
      if(success6==0)
        printf("Test shmem_double_iget: Passed\n");  
      else
        printf("Test shmem_double_iget: Failed\n");
      if(success7==0)
        printf("Test shmem_float_iget: Passed\n");  
      else
        printf("Test shmem_float_iget: Failed\n");
      
    }
   


    /* Testing shmem_double_g, shmem_float_g, shmem_int_g, shmem_long_g, shmem_short_g */
    shmem_barrier_all();

    dest9 = shmem_short_g(src9, nextpe);
    dest10 = shmem_int_g(src10, nextpe);
    dest11 = shmem_long_g(src11, nextpe);
    dest12 = shmem_double_g(src12, nextpe);
    dest13 = shmem_float_g(src13, nextpe);

    shmem_barrier_all();

    if(me == 0){
      if(dest9 == 1)
        printf("Test shmem_short_g: Passed\n");  
      else
        printf("Test shmem_short_g: Failed\n");
      if(dest10 == 1)
        printf("Test shmem_int_g: Passed\n");  
      else
        printf("Test shmem_int_g: Failed\n");
      if(dest11 == 1)
        printf("Test shmem_long_g: Passed\n");  
      else
        printf("Test shmem_long_g: Failed\n");
      if(dest12 == 1)
        printf("Test shmem_double_g: Passed\n");  
      else
        printf("Test shmem_double_g: Failed\n");
      if(dest13 == 1)
        printf("Test shmem_float_g: Passed\n");  
      else
        printf("Test shmem_float_g: Failed\n");


    }

    shmem_barrier_all();


    shfree(src1);
    shfree(src2);
    shfree(src3);
    shfree(src4);
    shfree(src5);
    shfree(src6);
    shfree(src7);
    shfree(src8);
  }
  else{
    printf("Number of PEs must be > 1 to test shmem get, test skipped\n");
  }
  return 0;
}
Beispiel #4
0
int main(int argc, char **argv)
{
  int j;
  int my_pe,n_pes;
  int one;
  char value_char;
  short value_short;
  int value_int;
  long value_long;
  float value_float;
  double value_double;
  long long value_longlong;
#ifdef HAVE_LONG_DOUBLE
  long double value_longdouble;
#endif

  shmem_init();
  my_pe = shmem_my_pe();
  n_pes = shmem_n_pes();
  one  = 1;

/*  fail if trying to use odd number of processors  */
  if ( (n_pes % 2) != 0 ){
        fprintf(stderr, "FAIL - test requires even number of PEs\n");
        exit(1);
  }

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

/*  shmem_char_g test   */

  if(my_pe == 0)
    fprintf(stderr,"shmem_char_g\n");
  if ( (my_pe % 2) == 0 )
      value_char = (char) my_pe;
  else
      targ_char = (char) my_pe;
  shmem_barrier_all();
  if ( (my_pe % 2) == 0 ) {
    value_char = shmem_char_g(&targ_char,my_pe+1);
    if ( value_char != (char)(my_pe+1) )
        fprintf(stderr, "FAIL: PE [%d] value_char=%d my_pe+1=%d\n",
                               my_pe,value_char,my_pe+1);
  }

/*  shmem_short_g test   */

  if(my_pe == 0)
    fprintf(stderr,"shmem_short_g\n");
  if ( (my_pe % 2) == 0 )
      value_short = (short) my_pe;
  else
      targ_short = (short) my_pe;
  shmem_barrier_all();
  if ( (my_pe % 2) == 0 ) {
    value_short = shmem_short_g(&targ_short,my_pe+1);
    if ( value_short != (short)(my_pe+1) )
        fprintf(stderr, "FAIL: PE [%d] value_short=%d my_pe+1=%d\n",
                               my_pe,value_short,my_pe+1);
  }

/*  shmem_int_g test   */
  if(my_pe == 0)
    fprintf(stderr,"shmem_int_g\n");
  if ( (my_pe % 2) == 0 )
      value_int = (int) my_pe;
  else
      targ_int = (int) my_pe;
  shmem_barrier_all();
  if ( (my_pe % 2) == 0 ) {
    value_int = shmem_int_g(&targ_int,my_pe+1);
    if ( value_int != (int)(my_pe+1) )
	fprintf(stderr, "FAIL: PE [%d] value_int=%d my_pe+1=%d\n",
                               my_pe,value_int,my_pe+1);
  }
  
/*  shmem_long_g test   */
  if(my_pe == 0)
    fprintf(stderr,"shmem_long_g\n");
  if ( (my_pe % 2) == 0 )
      value_long = (long) my_pe;
  else
      targ_long = (long) my_pe;
  shmem_barrier_all();
  if ( (my_pe % 2) == 0 ) {
    value_long = shmem_long_g(&targ_long,my_pe+1);
    if ( value_long != (long)(my_pe+1) )
        fprintf(stderr, "FAIL: PE [%d] value_long=%d my_pe+1=%d\n",
                               my_pe,value_long,my_pe+1);
  }

/*  shmem_longlong_g test   */
  if(my_pe == 0)
    fprintf(stderr,"shmem_longlong_g\n");
  if ( (my_pe % 2) == 0 )
      value_longlong = (long long) my_pe;
  else
      targ_longlong = (long long) my_pe;
  shmem_barrier_all();
  if ( (my_pe % 2) == 0 ) {
    value_longlong = shmem_longlong_g(&targ_longlong,my_pe+1);
    if ( value_longlong != (long long)(my_pe+1) )
        fprintf(stderr, "FAIL: PE [%d] value_longlong=%d my_pe+1=%d\n",
                               my_pe,value_longlong,my_pe+1);
  }

/*  shmem_float_g test   */
  if(my_pe == 0)
    fprintf(stderr,"shmem_float_g\n");
  if ( (my_pe % 2) == 0 )
      value_float = (float) my_pe;
  else
      targ_float = (float) my_pe;
  shmem_barrier_all();
  if ( (my_pe % 2) == 0 ) {
    value_float = shmem_float_g(&targ_float,my_pe+1);
    if ( value_float != (float)(my_pe+1) )
        fprintf(stderr, "FAIL: PE [%d] value_float=%10.2f my_pe+1=%d\n",
                               my_pe,value_float,my_pe+1);
  }

/*  shmem_double_g test   */
  if(my_pe == 0)
    fprintf(stderr,"shmem_double_g\n");
  if ( (my_pe % 2) == 0 )
      value_double = (double) my_pe;
  else
      targ_double = (double) my_pe;
  shmem_barrier_all();
  if ( (my_pe % 2) == 0 ) {
    value_double = shmem_double_g(&targ_double,my_pe+1);
    if ( value_double != (double)(my_pe+1) )
        fprintf(stderr, "FAIL: PE [%d] value_double=%10.2f my_pe+1=%d\n",
                               my_pe,value_double,my_pe+1);
  }

/*  shmem_longdouble_g test   */
#ifdef HAVE_LONG_DOUBLE
  if(my_pe == 0)
    fprintf(stderr,"shmem_longdouble_g\n");
  if ( (my_pe % 2) == 0 )
      value_longdouble = (long double) my_pe;
  else
      targ_longdouble = (long double) my_pe;
  shmem_barrier_all();
  if ( (my_pe % 2) == 0 ) {
    value_longdouble =shmem_longdouble_g(&targ_longdouble,my_pe+1);
    if ( value_longdouble != (long double)(my_pe+1) )
        fprintf(stderr, "FAIL: PE [%d] value_longdouble=%10.2f my_pe+1=%d\n",
                               my_pe,value_longdouble,my_pe+1);
  }
#endif

#ifdef NEEDS_FINALIZE
  shmem_finalize(); 
#endif
  return 0;
}
Beispiel #5
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 #6
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;
}
int
main ()
{
    int me, npes;

    int *dest1;
    float *dest2;
    long *dest3;
    double *dest4;
    long long *dest5;

    int swapped_val1, new_val1;
    float swapped_val2, new_val2;
    long swapped_val3, new_val3;
    double swapped_val4, new_val4;
    long long swapped_val5, new_val5;

    int success = 1;
    int success1_p1;
    int success2_p1;
    int success3_p1;
    int success4_p1;
    int success5_p1;

    int *fail_count;
    int fail_count_remote;

    shmem_init ();
    me = shmem_my_pe ();
    npes = shmem_n_pes ();

    shmem_barrier_all ();

    /* Checks if there are atleast 2 executing PEs */

    if (npes > 1) {

        dest1 = (int *) shmem_malloc (sizeof (*dest1));
        dest2 = (float *) shmem_malloc (sizeof (*dest2));
        dest3 = (long *) shmem_malloc (sizeof (*dest3));
        dest4 = (double *) shmem_malloc (sizeof (*dest4));
        dest5 = (long long *) shmem_malloc (sizeof (*dest5));

        fail_count = (int *) shmem_malloc (sizeof (int));
        *fail_count = 0;

        *dest1 = *dest2 = *dest3 = *dest4 = *dest5 = me;
        new_val1 = new_val2 = new_val3 = new_val4 = new_val5 = me;
        success1_p1 = success1_p2 = success2_p1 = success2_p2 = success3_p1 =
            success3_p2 = success4_p1 = success4_p2 = success5_p1 =
            success5_p2 = -1;

        shmem_barrier_all ();

        swapped_val1 = shmem_int_swap (dest1, new_val1, (me + 1) % npes);
        swapped_val2 = shmem_float_swap (dest2, new_val2, (me + 1) % npes);
        swapped_val3 = shmem_long_swap (dest3, new_val3, (me + 1) % npes);
        swapped_val4 = shmem_double_swap (dest4, new_val4, (me + 1) % npes);
        swapped_val5 = shmem_longlong_swap (dest5, new_val5, (me + 1) % npes);


        /* To validate the working of swap we need to check the value received
           at the PE that initiated the swap as well as the dest PE */

        if (me == 0) {
            if (swapped_val1 == 1) {
                success1_p1 = 1;
            }
            if (swapped_val2 == 1) {
                success2_p1 = 1;
            }
            if (swapped_val3 == 1) {
                success3_p1 = 1;
            }
            if (swapped_val4 == 1) {
                success4_p1 = 1;
            }
            if (swapped_val5 == 1) {
                success5_p1 = 1;
            }
        }

        if (me == 1) {
            if (*dest1 == 0) {
                shmem_int_put (&success1_p2, &success, 1, 0);
            }
            if (*dest2 == 0) {
                shmem_int_put (&success2_p2, &success, 1, 0);
            }
            if (*dest3 == 0) {
                shmem_int_put (&success3_p2, &success, 1, 0);
            }
            if (*dest4 == 0) {
                shmem_int_put (&success4_p2, &success, 1, 0);
            }
            if (*dest5 == 0) {
                shmem_int_put (&success5_p2, &success, 1, 0);
            }
        }

        shmem_barrier_all ();

        if (me == 0) {
            if (success1_p1 && success1_p2) {
                printf ("Test shmem_int_swap: Passed\n");
            }
            else {
                printf ("Test shmem_int_swap: Failed\n");
                (*fail_count)++;
            }

            if (success2_p1 && success2_p2) {
                printf ("Test shmem_float_swap: Passed\n");
            }
            else {
                printf ("Test shmem_float_swap: Failed\n");
                (*fail_count)++;
            }

            if (success3_p1 && success3_p2) {
                printf ("Test shmem_long_swap: Passed\n");
            }
            else {
                printf ("Test shmem_long_swap: Failed\n");
                (*fail_count)++;
            }

            if (success4_p1 && success4_p2) {
                printf ("Test shmem_double_swap: Passed\n");
            }
            else {
                printf ("Test shmem_double_swap: Failed\n");
                (*fail_count)++;
            }

            if (success5_p1 && success5_p2) {
                printf ("Test shmem_longlong_swap: Passed\n");
            }
            else {
                printf ("Test shmem_longlong_swap: Failed\n");
                (*fail_count)++;
            }

        }
        shmem_barrier_all ();



        /* Test conditional swaps shmem_longlong_cswap, shmem_long_cswap,
           shmem_int_cswap, */

        *dest1 = *dest3 = *dest5 = me;
        new_val1 = new_val3 = new_val5 = me;
        success1_p1 = success1_p2 = success3_p1 = success3_p2 = success5_p1 =
            success5_p2 = -1;

        shmem_barrier_all ();

        swapped_val1 = shmem_int_cswap (dest1, me + 1, (long) me, 1);
        swapped_val3 = shmem_long_cswap (dest3, me + 1, (long) me, 1);
        swapped_val5 = shmem_longlong_cswap (dest5, me + 1, (long) me, 1);


        /* To validate the working of conditionalswap we need to check the
           value received at the PE that initiated the conditional swap as
           well as the dest PE */

        if (me == 0) {
            if (swapped_val1 == 1) {
                success1_p1 = 1;
            }

            if (swapped_val3 == 1) {
                success3_p1 = 1;
            }

            if (swapped_val5 == 1) {
                success5_p1 = 1;
            }
        }

        if (me == 1) {
            if (*dest1 == 0) {
                shmem_int_put (&success1_p2, &success, 1, 0);
            }

            if (*dest3 == 0) {
                shmem_int_put (&success3_p2, &success, 1, 0);
            }

            if (*dest5 == 0) {
                shmem_int_put (&success5_p2, &success, 1, 0);
            }
        }

        shmem_barrier_all ();

        if (me == 0) {
            if (success1_p1 && success1_p2) {
                printf ("Test shmem_int_cswap: Passed\n");
            }
            else {
                printf ("Test shmem_int_cswap: Failed\n");
                (*fail_count)++;
            }

            if (success3_p1 && success3_p2) {
                printf ("Test shmem_long_cswap: Passed\n");
            }
            else {
                printf ("Test shmem_long_cswap: Failed\n");
                (*fail_count)++;
            }

            if (success5_p1 && success5_p2) {
                printf ("Test shmem_longlong_cswap: Passed\n");
            }
            else {
                printf ("Test shmem_longlong_cswap: Failed\n");
                (*fail_count)++;
            }

        }
        shmem_barrier_all ();

        /* Test shmem_long_fadd, shmem_int_fadd, shmem_longlong_fadd */

        *dest1 = *dest3 = *dest5 = me;
        new_val1 = new_val3 = new_val5 = me;
        success1_p1 = success1_p2 = success3_p1 = success3_p2 = success5_p1 =
            success5_p2 = -1;

        shmem_barrier_all ();

        swapped_val1 = shmem_int_fadd (dest1, 1, 0);
        swapped_val3 = shmem_long_fadd (dest3, 1, 0);
        swapped_val5 = shmem_longlong_fadd (dest5, 1, 0);


        /* To validate the working of fetch and add we need to check the old
           value received at the PE that initiated the fetch and increment as
           well as the new value on the dest PE */

        if (me != 0) {
            if (swapped_val1 == 0) {
                success1_p1 = 1;
            }

            if (swapped_val3 == 0) {
                success3_p1 = 1;
            }

            if (swapped_val5 == 0) {
                success5_p1 = 1;
            }
        }

        if (me == 0) {
            if (*dest1 == npes - 1) {
                shmem_int_put (&success1_p2, &success, 1, npes - 1);
            }

            if (*dest3 == npes - 1) {
                shmem_int_put (&success3_p2, &success, 1, npes - 1);
            }

            if (*dest5 == npes - 1) {
                shmem_int_put (&success5_p2, &success, 1, npes - 1);
            }
        }

        shmem_barrier_all ();

        if (me == npes - 1) {
            if (success1_p1 && success1_p2) {
                printf ("Test shmem_int_fadd: Passed\n");
            }
            else {
                printf ("Test shmem_int_fadd: Failed\n");
                (*fail_count)++;
            }

            if (success3_p1 && success3_p2) {
                printf ("Test shmem_long_fadd: Passed\n");
            }
            else {
                printf ("Test shmem_long_fadd: Failed\n");
                (*fail_count)++;
            }

            if (success5_p1 && success5_p2) {
                printf ("Test shmem_longlong_fadd: Passed\n");
            }
            else {
                printf ("Test shmem_longlong_fadd: Failed\n");
                (*fail_count)++;
            }

        }
        shmem_barrier_all ();

        /* Test shmem_long_finc, shmem_int_finc, shmem_longlong_finc */

        *dest1 = *dest3 = *dest5 = me;
        new_val1 = new_val3 = new_val5 = me;
        success1_p1 = success1_p2 = success3_p1 = success3_p2 = success5_p1 =
            success5_p2 = -1;

        shmem_barrier_all ();

        swapped_val1 = shmem_int_finc (dest1, 0);
        swapped_val3 = shmem_long_finc (dest3, 0);
        swapped_val5 = shmem_longlong_finc (dest5, 0);


        /* To validate the working of fetch and increment we need to check the
           old value received at the PE that initiated the fetch and increment
           as well as the new value on the dest PE */

        if (me != 0) {
            if (swapped_val1 == 0) {
                success1_p1 = 1;
            }

            if (swapped_val3 == 0) {
                success3_p1 = 1;
            }

            if (swapped_val5 == 0) {
                success5_p1 = 1;
            }
        }

        if (me == 0) {
            if (*dest1 == npes - 1) {
                shmem_int_put (&success1_p2, &success, 1, npes - 1);
            }

            if (*dest3 == npes - 1) {
                shmem_int_put (&success3_p2, &success, 1, npes - 1);
            }

            if (*dest5 == npes - 1) {
                shmem_int_put (&success5_p2, &success, 1, npes - 1);
            }
        }

        shmem_barrier_all ();

        if (me == npes - 1) {
            if (success1_p1 && success1_p2) {
                printf ("Test shmem_int_finc: Passed\n");
            }
            else {
                printf ("Test shmem_int_finc: Failed\n");
                (*fail_count)++;
            }

            if (success3_p1 && success3_p2) {
                printf ("Test shmem_long_finc: Passed\n");
            }
            else {
                printf ("Test shmem_long_finc: Failed\n");
                (*fail_count)++;
            }

            if (success5_p1 && success5_p2) {
                printf ("Test shmem_longlong_finc: Passed\n");
            }
            else {
                printf ("Test shmem_longlong_finc: Failed\n");
                (*fail_count)++;
            }
        }

        fflush(NULL); /* Ensure pass/fail status is last message on stdout */
        shmem_barrier_all ();

        if (me == 0) {
            fail_count_remote = shmem_int_g(fail_count, npes - 1);

            *fail_count += fail_count_remote;

            if (*fail_count == 0)
                printf("All Tests Passed\n");
            else
                printf("%d Tests Failed\n", *fail_count);
        }

        shmem_barrier_all();

        shmem_free (dest1);
        shmem_free (dest2);
        shmem_free (dest3);
        shmem_free (dest4);
        shmem_free (dest5);
        shmem_free (fail_count);

    }
    else {
        printf
            ("Number of PEs must be > 1 to test shmem atomics, test skipped\n");
    }

    shmem_finalize ();

    return 0;
}
int
main (int argc, char **argv)
{
    int i;
    int nextpe;
    int me, npes;
    int success1, success2, success3, success4, success5, success6, success7,
        success8;

    short dest1[N];
    int dest2[N];
    long dest3[N];
    long double dest4[N];
    long long dest5[N];
    double dest6[N];
    float dest7[N];
    char *dest8;
    short dest9;
    int dest10;
    long dest11;
    double dest12;
    float dest13;

    int fail_count = 0;

    shmem_init ();
    me = shmem_my_pe ();
    npes = shmem_n_pes ();

    if (npes > 1) {

        success1 = 0;
        success2 = 0;
        success3 = 0;
        success4 = 0;
        success5 = 0;
        success6 = 0;
        success7 = 0;
        success8 = 0;
        dest8 = (char *) malloc (N * sizeof (char));

        for (i = 0; i < N; i += 1) {
            dest1[i] = -9;
            dest2[i] = -9;
            dest3[i] = -9;
            dest4[i] = -9;
            dest5[i] = -9;
            dest6[i] = -9;
            dest7[i] = -9.0;
            dest8[i] = -9;
        }
        dest9 = -9;
        dest10 = -9;
        dest11 = -9;
        dest12 = -9;
        dest13 = -9;

        for (i = 0; i < N; i += 1) {
            src1[i] = (short) me;
            src2[i] = me;
            src3[i] = (long) me;
            src4[i] = (long double) me;
            src5[i] = (long long) me;
            src6[i] = (double) me;
            src7[i] = (float) me;
            src8[i] = (char) me;
        }
        src9 = (short) me;
        src10 = me;
        src11 = (long) me;
        src12 = (double) me;
        src13 = (float) me;



        nextpe = (me + 1) % npes;

        /* Testing shmem_short_get, shmem_short_get, shmem_int_get,
           shmem_long_get, shmem_longdouble_get, shmem_longlong_get,
           shmem_double_get, shmem_float_get, shmem_getmem */
        shmem_barrier_all ();

        shmem_short_get (dest1, src1, N, nextpe);
        shmem_int_get (dest2, src2, N, nextpe);
        shmem_long_get (dest3, src3, N, nextpe);
        shmem_longdouble_get (dest4, src4, N, nextpe);
        shmem_longlong_get (dest5, src5, N, nextpe);
        shmem_double_get (dest6, src6, N, nextpe);
        shmem_float_get (dest7, src7, N, nextpe);
        shmem_getmem (dest8, src8, N * sizeof (char), nextpe);

        shmem_barrier_all ();

        if (me == 0) {
            for (i = 0; i < N; i += 1) {
                if (dest1[i] != (1)) {
                    success1 = 1;
                }
                if (dest2[i] != (1)) {
                    success2 = 1;
                }
                if (dest3[i] != (1)) {
                    success3 = 1;
                }
                if (dest4[i] != (1)) {
                    success4 = 1;
                }
                if (dest5[i] != (1)) {
                    success5 = 1;
                }
                if (dest6[i] != (1)) {
                    success6 = 1;
                }
                if (dest7[i] != (1)) {
                    success7 = 1;
                }
                if (dest8[i] != (1)) {
                    success8 = 1;
                }
            }

            if (success1 == 0)
                printf ("Test shmem_short_get: Passed\n");
            else {
                printf ("Test shmem_short_get: Failed\n");
		fail_count++;
	    }
            if (success2 == 0)
                printf ("Test shmem_int_get: Passed\n");
            else {
                printf ("Test shmem_int_get: Failed\n");
		fail_count++;
	    }
            if (success3 == 0)
                printf ("Test shmem_long_get: Passed\n");
            else {
                printf ("Test shmem_long_get: Failed\n");
		fail_count++;
	    }
            if (success4 == 0)
                printf ("Test shmem_longdouble_get: Passed\n");
            else {
                printf ("Test shmem_longdouble_get: Failed\n");
		fail_count++;
	    }
            if (success5 == 0)
                printf ("Test shmem_longlong_get: Passed\n");
            else {
                printf ("Test shmem_longlong_get: Failed\n");
		fail_count++;
	    }
            if (success6 == 0)
                printf ("Test shmem_double_get: Passed\n");
            else {
                printf ("Test shmem_double_get: Failed\n");
		fail_count++;
	    }
            if (success7 == 0)
                printf ("Test shmem_float_get: Passed\n");
            else {
                printf ("Test shmem_float_get: Failed\n");
		fail_count++;
	    }
            if (success8 == 0)
                printf ("Test shmem_getmem: Passed\n");
            else {
                printf ("Test shmem_getmem: Failed\n");
		fail_count++;
	    }
        }
        shmem_barrier_all ();

        /* Testing shmem_get32, shmem_get64, shmem_get128 */
        if (sizeof (int) == 4) {
            for (i = 0; i < N; i += 1) {
                dest2[i] = -9;
                dest3[i] = -9;
                dest4[i] = -9;
            }
            success2 = 0;
            success3 = 0;
            success4 = 0;

            shmem_barrier_all ();

            shmem_get32 (dest2, src2, N, nextpe);
            shmem_get64 (dest3, src3, N, nextpe);
            shmem_get128 (dest4, src4, N, nextpe);

            shmem_barrier_all ();

            if (me == 0) {
                for (i = 0; i < N; i += 1) {
                    if (dest2[i] != (1)) {
                        success2 = 1;
                    }
                    if (dest3[i] != (1)) {
                        success3 = 1;
                    }
                    if (dest4[i] != (1)) {
                        success4 = 1;
                    }
                }
                if (success2 == 0)
                    printf ("Test shmem_get32: Passed\n");
                else {
                    printf ("Test shmem_get32: Failed\n");
		    fail_count++;
		}

                if (success3 == 0)
                    printf ("Test shmem_get64: Passed\n");
                else {
                    printf ("Test shmem_get64: Failed\n");
		    fail_count++;
		}

                if (success4 == 0)
                    printf ("Test shmem_get128: Passed\n");
                else {
                    printf ("Test shmem_get128: Failed\n");
		    fail_count++;
		}
            }
        }
        else if (sizeof (int) == 8) {
            for (i = 0; i < N; i += 1) {
                dest1[i] = -9;
                dest2[i] = -9;
                dest3[i] = -9;
            }
            success1 = 0;
            success2 = 0;
            success3 = 0;

            shmem_barrier_all ();

            shmem_get32 (dest1, src1, N, nextpe);
            shmem_get64 (dest2, src2, N, nextpe);
            shmem_get128 (dest3, src3, N, nextpe);

            shmem_barrier_all ();

            if (me == 0) {
                for (i = 0; i < N; i += 1) {
                    if (dest1[i] != (1)) {
                        success1 = 1;
                    }
                    if (dest2[i] != (1)) {
                        success2 = 1;
                    }
                    if (dest3[i] != (1)) {
                        success3 = 1;
                    }

                }
                if (success1 == 0)
                    printf ("Test shmem_get32: Passed\n");
                else {
                    printf ("Test shmem_get32: Failed\n");
		    fail_count++;
		}

                if (success2 == 0)
                    printf ("Test shmem_get64: Passed\n");
                else {
                    printf ("Test shmem_get64: Failed\n");
		    fail_count++;
		}

                if (success3 == 0)
                    printf ("Test shmem_get128: Passed\n");
                else {
                    printf ("Test shmem_get128: Failed\n");
		    fail_count++;
		}
            }
        }
        /* Testing shmem_iget32, shmem_iget64, shmem_iget128 */
        shmem_barrier_all ();
        if (sizeof (int) == 4) {
            for (i = 0; i < N; i += 1) {
                dest2[i] = -9;
                dest3[i] = -9;
                dest4[i] = -9;
            }
            success2 = 0;
            success3 = 0;
            success4 = 0;

            shmem_barrier_all ();

            shmem_iget32 (dest2, src2, 1, 2, N / 2, npes - 1);
            shmem_iget64 (dest3, src3, 1, 2, N / 2, npes - 1);
            shmem_iget128 (dest4, src4, 1, 2, N / 2, npes - 1);

            shmem_barrier_all ();

            if (me == 0) {
                for (i = 0; i < N / 2; i += 1) {
                    if (dest2[i] != (npes - 1)) {
                        success2 = 1;
                    }
                    if (dest3[i] != (npes - 1)) {
                        success3 = 1;
                    }
                    if (dest4[i] != (npes - 1)) {
                        success4 = 1;
                    }
                }
                if (success2 == 0)
                    printf ("Test shmem_iget32: Passed\n");
                else {
                    printf ("Test shmem_iget32: Failed\n");
		    fail_count++;
		}

                if (success3 == 0)
                    printf ("Test shmem_iget64: Passed\n");
                else {
                    printf ("Test shmem_iget64: Failed\n");
		    fail_count++;
		}

                if (success4 == 0)
                    printf ("Test shmem_iget128: Passed\n");
                else {
                    printf ("Test shmem_iget128: Failed\n");
		    fail_count++;
		}
            }
        }
        else if (sizeof (int) == 8) {
            for (i = 0; i < N; i += 1) {
                dest1[i] = -9;
                dest2[i] = -9;
                dest3[i] = -9;
            }
            success1 = 0;
            success2 = 0;
            success3 = 0;

            shmem_barrier_all ();

            shmem_iget32 (dest1, src1, 1, 2, N / 2, npes - 1);
            shmem_iget64 (dest2, src2, 1, 2, N / 2, npes - 1);
            shmem_iget128 (dest3, src3, 1, 2, N / 2, npes - 1);

            shmem_barrier_all ();

            if (me == 0) {
                for (i = 0; i < N / 2; i += 1) {
                    if (dest1[i] != (npes - 1)) {
                        success1 = 1;
                    }
                    if (dest2[i] != (npes - 1)) {
                        success2 = 1;
                    }
                    if (dest3[i] != (npes - 1)) {
                        success3 = 1;
                    }

                }
                if (success1 == 0)
                    printf ("Test shmem_iget32: Passed\n");
                else {
                    printf ("Test shmem_iget32: Failed\n");
		    fail_count++;
		}

                if (success2 == 0)
                    printf ("Test shmem_iget64: Passed\n");
                else {
                    printf ("Test shmem_iget64: Failed\n");
		    fail_count++;
		}

                if (success3 == 0)
                    printf ("Test shmem_iget128: Passed\n");
                else {
                    printf ("Test shmem_iget128: Failed\n");
		    fail_count++;
		}
            }
        }

        /* Testing shmem_short_iget, shmem_int_iget, shmem_long_iget,
           shmem_double_iget, shmem_float_iget */
        for (i = 0; i < N; i += 1) {
            dest1[i] = -9;
            dest2[i] = -9;
            dest3[i] = -9;
            dest6[i] = -9;
            dest7[i] = -9;
        }
        success1 = 0;
        success2 = 0;
        success3 = 0;
        success6 = 0;
        success7 = 0;

        shmem_barrier_all ();

        shmem_short_iget (dest1, src1, 1, 2, N / 2, npes - 1);
        shmem_int_iget (dest2, src2, 1, 2, N / 2, npes - 1);
        shmem_long_iget (dest3, src3, 1, 2, N / 2, npes - 1);
        shmem_double_iget (dest6, src6, 1, 2, N / 2, npes - 1);
        shmem_float_iget (dest7, src7, 1, 2, N / 2, npes - 1);

        shmem_barrier_all ();

        if (me == 0) {
            for (i = 0; i < N / 2; i += 1) {
                if (dest1[i] != (npes - 1)) {
                    success1 = 1;
                }
                if (dest2[i] != (npes - 1)) {
                    success2 = 1;
                }
                if (dest3[i] != (npes - 1)) {
                    success3 = 1;
                }
                if (dest6[i] != (npes - 1)) {
                    success6 = 1;
                }
                if (dest7[i] != (npes - 1)) {
                    success7 = 1;
                }
            }

            if (success1 == 0)
                printf ("Test shmem_short_iget: Passed\n");
            else {
                printf ("Test shmem_short_iget: Failed\n");
		fail_count++;
	    }
            if (success2 == 0)
                printf ("Test shmem_int_iget: Passed\n");
            else {
                printf ("Test shmem_int_iget: Failed\n");
		fail_count++;
	    }
            if (success3 == 0)
                printf ("Test shmem_long_iget: Passed\n");
            else {
                printf ("Test shmem_long_iget: Failed\n");
		fail_count++;
	    }
            if (success6 == 0)
                printf ("Test shmem_double_iget: Passed\n");
            else {
                printf ("Test shmem_double_iget: Failed\n");
		fail_count++;
	    }
            if (success7 == 0)
                printf ("Test shmem_float_iget: Passed\n");
            else {
                printf ("Test shmem_float_iget: Failed\n");
		fail_count++;
	    }
        }

        /* Testing shmem_double_g, shmem_float_g, shmem_int_g, shmem_long_g,
           shmem_short_g */
        shmem_barrier_all ();

        dest9 = shmem_short_g (&src9, nextpe);
        dest10 = shmem_int_g (&src10, nextpe);
        dest11 = shmem_long_g (&src11, nextpe);
        dest12 = shmem_double_g (&src12, nextpe);
        dest13 = shmem_float_g (&src13, nextpe);

        shmem_barrier_all ();

        if (me == 0) {
            if (dest9 == 1)
                printf ("Test shmem_short_g: Passed\n");
            else {
                printf ("Test shmem_short_g: Failed\n");
		fail_count++;
	    }
            if (dest10 == 1)
                printf ("Test shmem_int_g: Passed\n");
            else {
                printf ("Test shmem_int_g: Failed\n");
		fail_count++;
	    }
            if (dest11 == 1)
                printf ("Test shmem_long_g: Passed\n");
            else {
                printf ("Test shmem_long_g: Failed\n");
		fail_count++;
	    }
            if (dest12 == 1)
                printf ("Test shmem_double_g: Passed\n");
            else {
                printf ("Test shmem_double_g: Failed\n");
		fail_count++;
	    }
            if (dest13 == 1)
                printf ("Test shmem_float_g: Passed\n");
            else {
                printf ("Test shmem_float_g: Failed\n");
		fail_count++;
	    }
        }

        shmem_barrier_all ();

        if (me == 0) {
	    if (fail_count == 0)
	        printf("All Tests Passed\n");
	    else
	        printf("%d Tests Failed\n", fail_count);
	}
    }
    else {
        printf ("Number of PEs must be > 1 to test shmem get, test skipped\n");
    }

    shmem_finalize ();

    return 0;
}
Beispiel #9
0
int
main(int argc, char **argv)
{
     int me, npes;
     struct timeval now;
     long t_start, t_end;

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

     if (npes < 4) {
          if (me==0)
               fprintf(stderr,"ERR: test requires 4 or more PEs\n");
          return 1;
     }
     shmem_barrier_all();

     gettimeofday(&now, NULL);
     t_start = (now.tv_sec * 1000000.0) + now.tv_usec;

     switch (me) {
     case 0:
          while (pe_escape) {
               double pi, pi2, pi3;
               int j;

               for (j=1; j <= 5000; j++) {
                    pi = (22.0 / 7.0) + (double) j;
                    pi2 = pi * (double) j;
                    pi3 = (pi2 * pi) / 1.2;
               }
               mb();
          }
          gettimeofday(&now, NULL);
          t_end = ((now.tv_sec * 1000000.0) + now.tv_usec) - t_start;
          break;

     case 1:
          shmem_int_inc(&A, 0);
          gettimeofday(&now, NULL);
          t_end = ((now.tv_sec * 1000000.0) + now.tv_usec) - t_start;
          break;

     case 2:
          while (1 != shmem_int_g(&A, 0)) { ; }
          shmem_int_inc(&A, 0);
          gettimeofday(&now, NULL);
          t_end = ((now.tv_sec * 1000000.0) + now.tv_usec) - t_start;
          break;

     case 3:
          while (2 != shmem_int_g(&A, 0)) { ; }
          shmem_int_p((int*) &pe_escape, 0, 0);  // release PE0.
          if (npes > 4) {
               int i;

               for(i=4; i < npes; i++)
                    shmem_int_p((int*)&pe_escape, 0, i);  // release PE0.
          }
          gettimeofday(&now, NULL);
          t_end = ((now.tv_sec * 1000000.0) + now.tv_usec) - t_start;
          break;

     default:
          /* spin until released, A will never == 99, generate PE-0 traffic */
          while (99 != shmem_int_g(&A, 0) && pe_escape) {
               mb();
          }
          gettimeofday(&now, NULL);
          t_end = ((now.tv_sec * 1000000.0) + now.tv_usec) - t_start;
          break;
     }

     if (me < 4)
          fprintf(stderr,"[%d] elapsed usecs %ld A %d\n",me,t_end,A);

     shmem_barrier_all();

     return 0;
}