Exemple #1
0
double normP_GPI(double *vect, int n) 
{
  int i;

  //  (Location B)
  
  double result = 0.0;
  
  double local_result = 0.0;
  
  for ( i = 0; i < n; i++)
    local_result += vect[i] * vect[i];

  //  (Location A)
  assert(MPI_Barrier(MPI_COMM_WORLD) == MPI_SUCCESS);
  
  ASSERT(gaspi_allreduce(&local_result, &result, 1, GASPI_OP_SUM,GASPI_TYPE_DOUBLE,GASPI_GROUP_ALL,GASPI_BLOCK));
  
  //assert(MPI_Allreduce(&local_result, &result, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD) == MPI_SUCCESS);
  
  ASSERT(gaspi_barrier(GASPI_GROUP_ALL,GASPI_BLOCK));

  return  (sqrt(result));
}
Exemple #2
0
INIT_IMPLEM
#undef INIT_TYPE
#define INIT_TYPE uint32_t
INIT_IMPLEM
#undef INIT_TYPE
#define INIT_TYPE float
INIT_IMPLEM
#undef INIT_TYPE
#define INIT_TYPE  double
INIT_IMPLEM
#undef INIT_TYPE
#define INIT_TYPE long
INIT_IMPLEM
#undef INIT_TYPE
#define INIT_TYPE uint64_t
INIT_IMPLEM
#undef INIT_TYPE

#define CHECK_FUN(type) check_##type
#define CHECK_CALL(type, v, n, expected) CHECK_FUN(type)((v), (n), (expected))
#define CHECK_DECL(type) int CHECK_FUN(type)(type *v, gaspi_number_t n, gaspi_operation_t op)
#define CHECK_IMPLEM CHECK_DECL(CHECK_TYPE) { \
    int i;						    \
    CHECK_TYPE expected;				    \
    gaspi_rank_t myrank, nprocs;			    \
    ASSERT(gaspi_proc_rank(&myrank));			    \
    ASSERT(gaspi_proc_num(&nprocs));			    \
    switch(op)						    \
      {							    \
      case GASPI_OP_MIN: expected = 0;			    \
	break;							\
      case GASPI_OP_MAX: expected  = (CHECK_TYPE) nprocs - 1;	\
	break;							\
      case GASPI_OP_SUM:					\
	expected = (nprocs * (nprocs -1)) / 2;			\
	break;							\
      }								\
    for(i = 0; i < n; i++)					\
      if(v[i] != expected)					\
	{							\
	  gaspi_printf("expected %ld %ld\n", expected, v[i]);	\
	  return 0;						\
	}							\
    return 1;							\
  }								\

#define CHECK_TYPE int
CHECK_IMPLEM
#undef CHECK_TYPE
#define CHECK_TYPE uint32_t
CHECK_IMPLEM
#undef CHECK_TYPE
#define CHECK_TYPE float
CHECK_IMPLEM
#undef CHECK_TYPE
#define CHECK_TYPE  double
CHECK_IMPLEM
#undef CHECK_TYPE
#define CHECK_TYPE long
CHECK_IMPLEM
#undef CHECK_TYPE
#define CHECK_TYPE uint64_t
CHECK_IMPLEM


gaspi_return_t testOP(gaspi_operation_t op, gaspi_datatype_t type, gaspi_number_t elems, gaspi_group_t group)
{
  void * send_bf = malloc(elems * typeSize[type]);
  void * recv_bf = malloc(elems * typeSize[type]);

  if (send_bf == NULL || recv_bf == NULL)
    return GASPI_ERROR;

  gaspi_rank_t myrank, nprocs;
  ASSERT(gaspi_proc_rank(&myrank));
  ASSERT(gaspi_proc_num(&nprocs));
  
  //init data
  switch(type)
    {
    case GASPI_TYPE_INT: INIT_CALL(int, send_bf, elems, myrank);
      break;
    case GASPI_TYPE_UINT: INIT_CALL(uint32_t, send_bf, elems, myrank);
      break;
    case GASPI_TYPE_FLOAT: INIT_CALL(float, send_bf, elems, myrank);
      break;
    case GASPI_TYPE_DOUBLE: INIT_CALL(double, send_bf, elems, myrank);
      break;
    case GASPI_TYPE_LONG: INIT_CALL(long, send_bf, elems, myrank);
      break;
    case GASPI_TYPE_ULONG: INIT_CALL(uint64_t, send_bf, elems, myrank);
      break;
    }

  //sync
  ASSERT(gaspi_barrier(group, GASPI_BLOCK));
  
  //allreduce
  ASSERT( gaspi_allreduce(send_bf, recv_bf, elems, op, type, group, GASPI_BLOCK));
  
  //check data
  
  int ret; 
  switch(type)
    {
    case GASPI_TYPE_INT: ret = CHECK_CALL(int, recv_bf, elems, op);
      break;
    case GASPI_TYPE_UINT: ret = CHECK_CALL(uint32_t, recv_bf, elems, op);
      break;
    case GASPI_TYPE_FLOAT: ret = CHECK_CALL(float, recv_bf, elems, op);
      break;
    case GASPI_TYPE_DOUBLE: ret = CHECK_CALL(double, recv_bf, elems, op);
      break;
    case GASPI_TYPE_LONG: ret = CHECK_CALL(long, recv_bf, elems, op);
      break;
    case GASPI_TYPE_ULONG: ret = CHECK_CALL(uint64_t, recv_bf, elems, op);
      break;
    }
  if(ret)
    return GASPI_SUCCESS;
  else
    return GASPI_ERROR;
}