3 #define MAX_PHASE 16384     6 #include "../shared/util.h"     7 #include "../tensor/untyped_tensor.h"     8 #include "../summation/sum_tsr.h"    47         printf(
"phase should never be zero! map type = %d\n",this->
type);
   126       map->
np = tot_phase/(map->
np*my_phase);
   128       ASSERT(tot_phase%my_phase == 0);
   129       map->
np = tot_phase/my_phase;
   136       map->
np = tot_phase/my_phase;
   160           map_B->
cdt  != map_A->
cdt ||
   161           map_B->
np   != map_A->
np){
   182           map_B->
np != map_A->
np) {
   194     for (i=0; i<order; i++){
   195       mapping_B[i].
clear();
   196       mapping_B[i] = 
mapping(mapping_A[i]);
   217     int i, order_tot, iA, iB;
   223             &order_tot, &idx_arr);
   225     for (i=0; i<order_tot; i++){
   232           mapping_B[iB].
np = 1;
   235       } 
else if (iB != -1){
   236         mapping_B[iB].
clear();
   246                  int const * tsr_edge_len,
   247                  int const * tsr_sym_table,
   250                  int const * comm_idx,
   253     int i,j,max_dim,max_len,phase,ret;
   257     ret = 
map_symtsr(tsr_order, tsr_sym_table, tsr_edge_map);
   261     for (i=0; i<num_phys_dims; i++){
   264       for (j=0; j<tsr_order; j++){
   272                 (fill && ((comm_idx == NULL && tsr_edge_map[j].
cdt == i-1) ||
   273                 (comm_idx != NULL && tsr_edge_map[j].
cdt == comm_idx[i]-1)))){
   286       map   = &(tsr_edge_map[max_dim]);
   291         phase   = phys_comm[i].
np;
   293           if (phys_comm[i].
np != map->
np){
   294             phase     = 
lcm(map->
np, phys_comm[i].
np);
   295             if ((phase < map->
np || phase < phys_comm[i].
np) || phase >= 
MAX_PHASE)
   297             if (phase/phys_comm[i].np != 1){
   314       map->
np   = phys_comm[i].
np;
   315       map->
cdt  = (comm_idx == NULL) ? i : comm_idx[i];
   317         restricted[max_dim] = 1;
   318       ret = 
map_symtsr(tsr_order, tsr_sym_table, tsr_edge_map);
   321     for (i=0; i<tsr_order; i++){
   324         tsr_edge_map[i].
np        = 1;
   333                          int const *    idx_map){
   334     int i, j, pass, iR, max_idx;
   340     for (i=0; i<tsr->
order; i++){
   341       if (idx_map[i] > max_idx) max_idx = idx_map[i];
   346     std::fill(idx_arr, idx_arr+max_idx, -1);
   349     for (i=0; i<tsr->
order; i++){
   361             if (map2->
cdt != map1->
cdt+1) 
   364               DPRINTF(3,
"failed confirmation here i=%d\n",i);
   369         for (j=i+1; j<tsr->
order; j++){
   372             if (map1->
cdt == map2->
cdt) pass = 0;
   374               DPRINTF(3,
"failed confirmation here i=%d j=%d\n",i,j);
   389       for (i=tsr->
order-1; i>=0; i--){
   390         iR = idx_arr[idx_map[i]];
   411             DPRINTF(3,
"failed confirmation here i=%d iR=%d\n",i,iR);
   416         idx_arr[idx_map[i]] = i;
   424                        int const *    idx_map){
   425     int iR, max_idx, i, ret, npp;
   426     int * idx_arr, * stable;
   430     for (i=0; i<tsr->
order; i++){
   431       if (idx_map[i] > max_idx) max_idx = idx_map[i];
   440     std::fill(idx_arr, idx_arr+max_idx, -1);
   444     for (i=0; i<tsr->
order; i++){
   445       iR = idx_arr[idx_map[i]];
   447         stable[iR*tsr->
order+i] = 1;
   448         stable[i*tsr->
order+iR] = 1;
   457       idx_arr[idx_map[i]] = i;
   471                  int const * tsr_sym_table,
   473     int i,j,phase,adj,loop,sym_phase,lcm_phase;
   486       for (i=0; i<tsr_order; i++){
   488           map   = &tsr_edge_map[i];
   490           for (j=0; j<tsr_order; j++){
   491             if (i!=j && tsr_sym_table[i*tsr_order+j] == 1){
   492               sym_map   = &(tsr_edge_map[j]);
   495               if (sym_phase != phase) adj = 1;
   497               lcm_phase   = 
lcm(sym_phase, phase);
   498               if ((lcm_phase < sym_phase || lcm_phase < phase) || lcm_phase >= 
MAX_PHASE)
   503                 sym_map->
np   = lcm_phase;
   505               } 
else if (sym_phase != lcm_phase) { 
   508                   sym_map->
np = sym_map->
np*(lcm_phase/sym_phase);
   515                   sym_map->
child->
np        = lcm_phase/sym_phase;
   520               if (lcm_phase > phase){
   523                   map->
np = map->
np*(lcm_phase/phase);
   530                   map->
child->
np        = lcm_phase/phase;
   547     for (i=0; i<order; i++){
   555           map->
child->
np    = stretch_factor;
   559         map->
np = map->
np * stretch_factor;
   562         map->
np   = stretch_factor;
 
int calc_phys_rank(topology const *topo) const 
compute the physical rank of a mapping 
int map_tensor(int num_phys_dims, int tsr_order, int const *tsr_edge_len, int const *tsr_sym_table, int *restricted, CommData *phys_comm, int const *comm_idx, int fill, mapping *tsr_edge_map)
map a tensor 
int calc_phase() const 
compute the phase of a mapping 
void aug_phys(topology const *topo, int idim)
adds a physical mapping to this mapping 
int calc_phys_phase() const 
compute the physical phase of a mapping 
void inv_idx(int order_A, int const *idx_A, int order_B, int const *idx_B, int order_C, int const *idx_C, int *order_tot, int **idx_arr)
invert index map 
#define DEBUG_PRINTF(...)
void copy_mapping(int order, mapping const *mapping_A, mapping *mapping_B)
copies mapping A to B 
int order
number of tensor dimensions 
int alloc_ptr(int64_t len, void **const ptr)
alloc abstraction 
int comp_dim_map(mapping const *map_A, mapping const *map_B)
compares two mappings 
mapping * edge_map
mappings of each tensor dimension onto topology dimensions 
int * sym_table
order-by-order table of dimensional symmetry relations 
int map_symtsr(int tsr_order, int const *tsr_sym_table, mapping *tsr_edge_map)
adjust a mapping to maintan symmetry 
int check_self_mapping(tensor const *tsr, int const *idx_map)
checks mapping in preparation for tensors scale, summ or contract 
int cdealloc(void *ptr)
free abstraction 
internal distributed tensor class 
mapping & operator=(mapping const &other)
int map_self_indices(tensor const *tsr, int const *idx_map)
create virtual mapping for idx_maps that have repeating indices 
void aug_virt(int tot_phase)
augments mapping to have sufficient virtualization so that the total phas is exactly tot_phase (assum...
int stretch_virt(int order, int stretch_factor, mapping *maps)
stretch virtualization by a factor 
void clear()
resets mapping to NOT_MAPPED