libxmp/libxmpf in Omni Compiler  1.3.4
xmp_sort.c File Reference
#include <stdlib.h>
#include <string.h>
#include "xmp_internal.h"
Include dependency graph for xmp_sort.c:

Macros

#define THRESHOLD_BSEARCH   8
 
#define THRESHOLD_2WAY   32
 
#define THRESHOLD_KWAY   THRESHOLD_2WAY*2
 
#define COMPARE_UP(_type)
 
#define COMPARE_DOWN(_type)
 
#define PIVOT(_type)
 

Functions

void dbg_printf (char *fmt,...)
 
void xmp_sort_up (_XMP_array_t *a_desc, _XMP_array_t *b_desc)
 
void xmp_sort_down (_XMP_array_t *a_desc, _XMP_array_t *b_desc)
 
void _XMP_sort (_XMP_array_t *a_desc, _XMP_array_t *b_desc, int is_up)
 
void xmpc_gmv_g_alloc (_XMP_gmv_desc_t **gmv_desc, _XMP_array_t *ap)
 
void xmpc_gmv_g_dim_info (_XMP_gmv_desc_t *gp, int i, int kind, int lb, int len, int st)
 
void xmpc_gmv_dealloc (_XMP_gmv_desc_t *gp)
 
void xmpc_gmv_do (_XMP_gmv_desc_t *gmv_desc_leftp, _XMP_gmv_desc_t *gmv_desc_rightp, int mode)
 

Variables

int(* compare_func )(const void *a, const void *b)
 
void(* get_rotate_pivot )(void *p, const void *a, const int an, const void *b, const int bn)
 
size_t datasize
 
MPI_Datatype mpi_type
 

Macro Definition Documentation

◆ COMPARE_DOWN

#define COMPARE_DOWN (   _type)
Value:
(const void *a, const void *b){ \
if (*(_type *)a > *(_type *)b){ \
return -1; \
} \
else if(*(_type *)a == *(_type *)b){ \
return 0; \
} \
return 1; \
}

◆ COMPARE_UP

#define COMPARE_UP (   _type)
Value:
(const void *a, const void *b){ \
if (*(_type *)a < *(_type *)b){ \
return -1; \
} \
else if(*(_type *)a == *(_type *)b){ \
return 0; \
} \
return 1; \
}

◆ PIVOT

#define PIVOT (   _type)
Value:
(void *p, const void *a, const int an, \
const void *b, const int bn){ \
_type am = 0, bm = 0; \
if (an > 0){ \
if (an % 2 == 0) \
am = (((_type *)a)[an / 2] + ((_type *)a)[an / 2 - 1]) / 2; \
else \
am = ((_type *)a)[an / 2]; \
} \
if (bn > 0){ \
if (bn % 2 == 0) \
bm = (((_type *)b)[bn / 2] + ((_type *)b)[bn / 2 - 1]) / 2; \
else \
bm = ((_type *)b)[bn / 2]; \
} \
_type tmp; \
if (an > 0 && bn > 0) tmp = (am + bm) / 2; \
else if (an > 0 && bn == 0) tmp = am; \
else if (an == 0 && bn > 0) tmp = bm; \
memcpy(p, &tmp, datasize); \
}

◆ THRESHOLD_2WAY

#define THRESHOLD_2WAY   32

◆ THRESHOLD_BSEARCH

#define THRESHOLD_BSEARCH   8

◆ THRESHOLD_KWAY

#define THRESHOLD_KWAY   THRESHOLD_2WAY*2

Function Documentation

◆ _XMP_sort()

void _XMP_sort ( _XMP_array_t a_desc,
_XMP_array_t b_desc,
int  is_up 
)
92  {
93 
94  void *a_adr = a_desc->array_addr_p;
95  int a_lshadow = a_desc->info[0].shadow_size_lo;
96 
97  int a_size = a_desc->info[0].ser_size;
98  int a_ndims = a_desc->dim;
99  int a_type = a_desc->type;
100 
101  int b_size = b_desc->info[0].ser_size;
102  int b_ndims = b_desc->dim;
103  int b_type = b_desc->type;
104 
105  if (a_size != b_size) _XMP_fatal("xmp_sort: different size for array arguments");
106  if (a_ndims != 1 || b_ndims != 1) _XMP_fatal("xmp_sort: array arguments must be one-dimensional");
107  if (a_type != b_type) _XMP_fatal("xmp_sort: different type for array arguments");
108 
109  int lsize = a_desc->info[0].par_size;
110 
111  comm = a_desc->array_nodes->comm;
112  me = a_desc->array_nodes->comm_rank;
113  nprocs = a_desc->array_nodes->comm_size;
114 
115  set_funcs(a_desc, is_up);
116  datasize = a_desc->type_size;
117 
118  do_sort((char *)a_adr + a_lshadow * datasize, lsize, b_desc);
119 
120 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbg_printf()

void dbg_printf ( char *  fmt,
  ... 
)
73  {
74  ;
75 }

◆ xmp_sort_down()

void xmp_sort_down ( _XMP_array_t a_desc,
_XMP_array_t b_desc 
)
87  {
88  _XMP_sort(a_desc, b_desc, 0);
89 }
Here is the call graph for this function:

◆ xmp_sort_up()

void xmp_sort_up ( _XMP_array_t a_desc,
_XMP_array_t b_desc 
)
82  {
83  _XMP_sort(a_desc, b_desc, 1);
84 }
Here is the call graph for this function:

◆ xmpc_gmv_dealloc()

void xmpc_gmv_dealloc ( _XMP_gmv_desc_t gp)
129  {
130 
131  _XMP_free(gp->kind);
132  _XMP_free(gp->lb);
133  _XMP_free(gp->ub);
134  _XMP_free(gp->st);
135 
136  _XMP_free(gp->a_lb);
137  _XMP_free(gp->a_ub);
138 
139  _XMP_free(gp);
140 
141 }
Here is the call graph for this function:

◆ xmpc_gmv_do()

void xmpc_gmv_do ( _XMP_gmv_desc_t gmv_desc_leftp,
_XMP_gmv_desc_t gmv_desc_rightp,
int  mode 
)
165 {
166 
167  _XMP_pack_comm_set = _XMPC_pack_comm_set;
168  _XMP_unpack_comm_set = _XMPC_unpack_comm_set;
169 
170  if (gmv_desc_leftp->is_global && gmv_desc_rightp->is_global){
171  _XMP_gmove_garray_garray(gmv_desc_leftp, gmv_desc_rightp, mode);
172  }
173  else if (gmv_desc_leftp->is_global && !gmv_desc_rightp->is_global){
174  if (gmv_desc_rightp->ndims == 0){
175  _XMP_gmove_garray_scalar(gmv_desc_leftp, gmv_desc_rightp->local_data, mode);
176  }
177  else {
178  _XMP_array_t *a = NULL;
179  _XMPC_larray_alloc(&a, gmv_desc_rightp,
180  gmv_desc_leftp->a_desc->type, gmv_desc_leftp->a_desc->align_template);
181  _XMP_gmove_garray_larray(gmv_desc_leftp, gmv_desc_rightp, mode);
183  }
184  }
185  else if (!gmv_desc_leftp->is_global && gmv_desc_rightp->is_global){
186  if (gmv_desc_leftp->ndims == 0){
187  _XMP_gmove_scalar_garray(gmv_desc_leftp->local_data, gmv_desc_rightp, mode);
188  }
189  else {
190 
191  _XMP_ASSERT(gmv_desc_rightp->a_desc);
192 
193  // create a temporal descriptor for the "non-distributed" LHS array (to be possible used
194  // in _XMP_gmove_1to1)
195  _XMP_array_t *a = NULL;
196  _XMPC_larray_alloc(&a, gmv_desc_leftp,
197  gmv_desc_rightp->a_desc->type, gmv_desc_rightp->a_desc->align_template);
198  _XMP_gmove_larray_garray(gmv_desc_leftp, gmv_desc_rightp, mode);
200 
201  }
202  }
203  else {
204  _XMP_fatal("gmv_do: both sides are local.");
205  }
206 
207 }

◆ xmpc_gmv_g_alloc()

void xmpc_gmv_g_alloc ( _XMP_gmv_desc_t **  gmv_desc,
_XMP_array_t ap 
)
25 {
26  _XMP_gmv_desc_t *gp;
27  int n = ap->dim;
28 
30 
31  gp->kind = (int *)_XMP_alloc(sizeof(int) * n);
32  gp->lb = (int *)_XMP_alloc(sizeof(int) * n);
33  gp->ub = (int *)_XMP_alloc(sizeof(int) * n);
34  gp->st = (int *)_XMP_alloc(sizeof(int) * n);
35 
36  if (!gp || !gp->kind || !gp->lb || !gp->st)
37  _XMP_fatal("gmv_g_alloc: cannot alloc memory");
38 
39  gp->is_global = true;
40  gp->ndims = n;
41  gp->a_desc = ap;
42 
43  gp->local_data = NULL;
44  gp->a_lb = NULL;
45  gp->a_ub = NULL;
46 
47  *gmv_desc = gp;
48 }
Here is the call graph for this function:

◆ xmpc_gmv_g_dim_info()

void xmpc_gmv_g_dim_info ( _XMP_gmv_desc_t gp,
int  i,
int  kind,
int  lb,
int  len,
int  st 
)
54 {
55  gp->kind[i] = kind;
56 
57  switch (kind){
58  case XMP_N_GMOVE_ALL:
59  gp->lb[i] = gp->a_desc->info[i].ser_lower;
60  gp->ub[i] = gp->a_desc->info[i].ser_upper;
61  gp->st[i] = 1;
62  break;
63  case XMP_N_GMOVE_INDEX:
64  case XMP_N_GMOVE_RANGE:
65  gp->lb[i] = lb;
66  gp->ub[i] = lb + st * (len - 1);
67  gp->st[i] = st;
68  break;
69  default:
70  _XMP_fatal("wrong gmove kind");
71  }
72 
73 }
Here is the call graph for this function:

Variable Documentation

◆ compare_func

int(* compare_func) (const void *a, const void *b)

◆ datasize

size_t datasize

◆ get_rotate_pivot

void(* get_rotate_pivot) (void *p, const void *a, const int an, const void *b, const int bn)

◆ mpi_type

MPI_Datatype mpi_type
_XMP_array_type::array_nodes
_XMP_nodes_t * array_nodes
Definition: xmp_data_struct.h:306
_XMP_nodes_type::comm_size
int comm_size
Definition: xmp_data_struct.h:48
_XMP_finalize_array_desc
void _XMP_finalize_array_desc(void *array)
_XMP_alloc
void * _XMP_alloc(size_t size)
Definition: xmp_util.c:21
_XMP_gmv_desc_type::lb
int * lb
Definition: xmp_data_struct.h:398
_XMP_gmv_desc_type::st
int * st
Definition: xmp_data_struct.h:400
_XMP_gmove_garray_larray
void _XMP_gmove_garray_larray(_XMP_gmv_desc_t *gmv_desc_leftp, _XMP_gmv_desc_t *gmv_desc_rightp, int mode)
Definition: xmp_gmove.c:4851
_XMP_array_info_type::ser_upper
int ser_upper
Definition: xmp_data_struct.h:200
_XMP_gmv_desc_type::ub
int * ub
Definition: xmp_data_struct.h:399
XMP_N_GMOVE_INDEX
#define XMP_N_GMOVE_INDEX
Definition: xmp_constant.h:128
_XMP_gmv_desc_type
Definition: xmp_data_struct.h:386
datasize
size_t datasize
Definition: xmp_sort.c:68
_XMP_array_info_type::ser_size
int ser_size
Definition: xmp_data_struct.h:201
_XMP_gmv_desc_type::a_ub
int * a_ub
Definition: xmp_data_struct.h:395
_XMP_nodes_type::comm_rank
int comm_rank
Definition: xmp_data_struct.h:52
_XMP_gmove_garray_garray
void _XMP_gmove_garray_garray(_XMP_gmv_desc_t *gmv_desc_leftp, _XMP_gmv_desc_t *gmv_desc_rightp, int mode)
Definition: xmp_gmove.c:4769
_XMP_array_info_type::shadow_size_lo
int shadow_size_lo
Definition: xmp_data_struct.h:249
_XMP_array_type::align_template
_XMP_template_t * align_template
Definition: xmp_data_struct.h:312
_XMP_gmv_desc_type::kind
int * kind
Definition: xmp_data_struct.h:397
_XMP_sort
void _XMP_sort(_XMP_array_t *a_desc, _XMP_array_t *b_desc, int is_up)
Definition: xmp_sort.c:92
_XMP_array_info_type::ser_lower
int ser_lower
Definition: xmp_data_struct.h:199
_XMP_gmv_desc_type::local_data
void * local_data
Definition: xmp_data_struct.h:393
XMP_N_GMOVE_ALL
#define XMP_N_GMOVE_ALL
Definition: xmp_constant.h:127
_XMP_array_type
Definition: xmp_data_struct.h:266
_XMP_gmv_desc_type::ndims
int ndims
Definition: xmp_data_struct.h:389
_XMP_array_type::type_size
size_t type_size
Definition: xmp_data_struct.h:274
_XMP_array_type::info
_XMP_array_info_t info[1]
Definition: xmp_data_struct.h:313
_XMP_free
void _XMP_free(void *p)
Definition: xmp_util.c:37
_XMP_ASSERT
#define _XMP_ASSERT(_flag)
Definition: xmp_internal.h:34
_XMP_gmv_desc_type::is_global
_Bool is_global
Definition: xmp_data_struct.h:388
_XMP_unpack_comm_set
void(* _XMP_unpack_comm_set)(void *recvbuf, int recvbuf_size, _XMP_array_t *a, _XMP_comm_set_t *comm_set[][_XMP_N_MAX_DIM])
Definition: xmp_gmove.c:25
_XMP_pack_comm_set
void(* _XMP_pack_comm_set)(void *sendbuf, int sendbuf_size, _XMP_array_t *a, _XMP_comm_set_t *comm_set[][_XMP_N_MAX_DIM])
Definition: xmp_gmove.c:23
_XMP_array_type::array_addr_p
void * array_addr_p
Definition: xmp_data_struct.h:279
_XMP_nodes_type::comm
_XMP_comm_t * comm
Definition: xmp_data_struct.h:53
_XMP_array_type::dim
int dim
Definition: xmp_data_struct.h:272
_XMP_fatal
void _XMP_fatal(char *msg)
Definition: xmp_util.c:42
XMP_N_GMOVE_RANGE
#define XMP_N_GMOVE_RANGE
Definition: xmp_constant.h:129
_XMP_gmv_desc_type::a_desc
_XMP_array_t * a_desc
Definition: xmp_data_struct.h:391
_XMP_array_info_type::par_size
int par_size
Definition: xmp_data_struct.h:207
_XMP_gmove_garray_scalar
void _XMP_gmove_garray_scalar(_XMP_gmv_desc_t *gmv_desc_leftp, void *scalar, int mode)
Definition: xmp_gmove.c:4732
_XMP_gmove_scalar_garray
void _XMP_gmove_scalar_garray(void *scalar, _XMP_gmv_desc_t *gmv_desc_rightp, int mode)
Definition: xmp_gmove.c:4704
_XMP_array_type::type
int type
Definition: xmp_data_struct.h:273
_XMP_gmove_larray_garray
void _XMP_gmove_larray_garray(_XMP_gmv_desc_t *gmv_desc_leftp, _XMP_gmv_desc_t *gmv_desc_rightp, int mode)
Definition: xmp_gmove.c:5003
_XMP_gmv_desc_type::a_lb
int * a_lb
Definition: xmp_data_struct.h:394