19   std::fill(lens, lens+logn, 2);
    23                   [](
double a, 
double b){ 
return a <= b ? a : 
b; },
    26                   [](
double a, 
double b){ 
return a*
b; });
    32   V.write(np, inds, data);
    43   int lens2[] = {2, 2, 2};
    44   Tensor<> swap_up_down(3, lens2, dw, smin);
    46     double vals[] = {1.,1.,-1.,-1.,-1.,-1.,1.,1.};
    47     int64_t inds[] = {0,1,2,3,4,5,6,7};
    48     swap_up_down.
write(8, inds, vals);
    49   } 
else { swap_up_down.
write(0, NULL, NULL); }
    52   Matrix<> fix_sign_up_down(2, 2, dw, smin);
    54     double vals[] = {1.,-1.,-1.,1.};
    55     int64_t inds[] = {0,1,2,3};
    56     fix_sign_up_down.
write(4, inds, vals);
    57   } 
else { fix_sign_up_down.
write(0, NULL, NULL); }
    62     double vals[] = {1.,1.,-1.,-1.};
    63     int64_t inds[] = {0, 1, 2, 3};
    64     swap_up.
write(4, inds, vals);
    65   } 
else { swap_up.
write(0, NULL, NULL); }
    70     double vals[] = {1.,-1.};
    71     int64_t inds[] = {0,1};
    72     fix_sign_up.
write(2, inds, vals);
    73   } 
else { fix_sign_up.
write(0, NULL, NULL); }
    77   for (
int i=0; i<logn; i++){
    83   for (
int i=0; i<logn-1; i++){
    85     char up_down_idx = 
'a'+i+1; 
    87     for (
int j=i; j>=0; j--){
    89       char swap_idx[] = {
'z', idx[j], up_down_idx};
    90       char fix_sign[] = {idx[j], up_down_idx};
    91       V[idx] = swap_up_down[swap_idx]*V[idx_z];
    92       V[idx] = fix_sign_up_down[fix_sign]*V[idx];
    98   for (
int j=logn-1; j>=0; j--){
   100     char swap_idx[] = {
'z', idx[j]};
   101     V[idx] = swap_up[swap_idx]*V[idx_z];
   102     V[idx] = fix_sign_up[&(idx[j])]*V[idx];
   108   V.get_local_data(&np, &inds, &data);
   109   v.
write(np, inds, data);
   125   double data[1<<logn];
   130   for (
int i=1; i<1<<logn; i++){
   131     if (data[i] < data[i-1]) pass = 0;
   135       printf(
"{ bitonic sort via tensor contractions } passed \n");
   137       printf(
"{ bitonic sort via tensor contractions } failed \n");
   147   char ** itr = std::find(begin, end, option);
   148   if (itr != end && ++itr != end){
   155 int main(
int argc, 
char ** argv){
   157   int const in_num = argc;
   158   char ** input_str = argv;
   160   MPI_Init(&argc, &argv);
   161   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   162   MPI_Comm_size(MPI_COMM_WORLD, &np);
   164   if (
getCmdOption(input_str, input_str+in_num, 
"-logn")){
   165     logn = atoi(
getCmdOption(input_str, input_str+in_num, 
"-logn"));
   166     if (logn < 0) logn = 4;
   171     World dw(argc, argv);
   174       printf(
"Running bitonic sort on random dimension %d vector\n",1<<logn);
 
Matrix class which encapsulates a 2D tensor. 
Semiring is a Monoid with an addition multiplicaton function addition must have an identity and be as...
Vector class which encapsulates a 1D tensor. 
void read_all(int64_t *npair, dtype **data, bool unpack=false)
collects the entire tensor data on each process (not memory scalable) 
an instance of the CTF library (world) on a MPI communicator 
void fill_random(dtype rmin, dtype rmax)
fills local unique tensor elements to random values in the range [min,max] works only for dtype in {f...
int rank
rank of local processor 
int bitonic(int logn, World &dw)
void get_local_data(int64_t *npair, int64_t **global_idx, dtype **data, bool nonzeros_only=false, bool unpack_sym=false) const 
Gives the global indices and values associated with the local data. 
int main(int argc, char **argv)
void bitonic_sort(Vector<> &v, int logn, World &dw)
an instance of a tensor within a CTF world 
char * getCmdOption(char **begin, char **end, const std::string &option)
void write(int64_t npair, int64_t const *global_idx, dtype const *data)
writes in values associated with any set of indices The sparse data is defined in coordinate format...