Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
monoid.cxx
Go to the documentation of this file.
1 #include "../sparse_formats/csr.h"
2 #include "set.h"
3 #include "../shared/blas_symbs.h"
4 #include "../shared/mkl_symbs.h"
5 #include "../shared/util.h"
6 using namespace CTF_int;
7 namespace CTF {
8 /* template <>
9  void Monoid<float,1>::csr_add(int64_t m, int64_t n, char const * a, int const * ja, int const * ia, char const * b, int const * jb, int const * ib, char *& c, int *& jc, int *& ic){
10  if (fadd != default_add<float>){
11  printf("CTF error: support for CSR addition for this type unavailable\n");
12  assert(0);
13  }
14  alloc(sizeof(int)*(m+1), (void**)&ic);
15  bool tA = 'N';
16  bool tB = 'N';
17  int job = 1;
18  int sort = 1;
19  float mlid = 1.0;
20  int info;
21  MKL_SCSRADD(tA, tB, &job, &sort, m, n, (float*)a, ja, ia, &mlid, (float*)b, jb, ib, NULL, NULL, ic, NULL, &info);
22  alloc(sizeof(int)*ic[m], (void**)&jc);
23  alloc(sizeof(float)*ic[m], (void**)&c);
24  int job = 2;
25  MKL_SCSRADD(tA, tB, &job, &sort, m, n, (float*)a, ja, ia, &mlid, (float*)b, jb, ib, (float*)c, jc, ic, NULL, &info);
26  }*/
27 
28  template <>
29  char * CTF::Monoid<double,1>::csr_add(char * cA, char * cB) const {
30 #if USE_MKL
31  TAU_FSTART(mkl_csr_add)
32  if (fadd != &default_add<double>){
33  return CTF_int::algstrct::csr_add(cA, cB);
34  }
35  CSR_Matrix A(cA);
36  CSR_Matrix B(cB);
37  int * ic;
38  int m = A.nrow();
39  int n = A.ncol();
40  alloc_ptr(sizeof(int)*(m+1), (void**)&ic);
41  char tA = 'N';
42  int job = 1;
43  int sort = 1;
44  double mlid = 1.0;
45  int info;
46  CTF_BLAS::MKL_DCSRADD(&tA, &job, &sort, &m, &n, (double*)A.vals(), A.JA(), A.IA(), &mlid, (double*)B.vals(), B.JA(), B.IA(), NULL, NULL, ic, NULL, &info);
47  CSR_Matrix C(ic[m]-1, m, n, this);
48  memcpy(C.IA(), ic, sizeof(int)*(m+1));
49  cdealloc(ic);
50  job = 2;
51  CTF_BLAS::MKL_DCSRADD(&tA, &job, &sort, &m, &n, (double*)A.vals(), A.JA(), A.IA(), &mlid, (double*)B.vals(), B.JA(), B.IA(), (double*)C.vals(), C.JA(), C.IA(), NULL, &info);
52  TAU_FSTOP(mkl_csr_add)
53  return C.all_data;
54 #else
55  return CTF_int::algstrct::csr_add(cA, cB);
56 #endif
57  }
58 
59 }
virtual char * csr_add(char *cA, char *cB) const
adds CSR matrices A (stored in cA) and B (stored in cB) to create matric C (pointer to all_data retur...
Definition: algstrct.cxx:362
int * IA() const
retrieves prefix sum of number of nonzeros for each row (of size nrow()+1) out of all_data ...
Definition: csr.cxx:107
int ncol() const
retrieves number of columns out of all_data
Definition: csr.cxx:97
int * JA() const
retrieves column indices of each value in vals stored in sorted form by row
Definition: csr.cxx:119
char * csr_add(char *cA, char *cB) const
adds CSR matrices A (stored in cA) and B (stored in cB) to create matric C (pointer to all_data retur...
Definition: monoid.h:132
int alloc_ptr(int64_t len, void **const ptr)
alloc abstraction
Definition: memcontrol.cxx:320
abstraction for a serialized sparse matrix stored in column-sparse-row (CSR) layout ...
Definition: csr.h:22
#define TAU_FSTOP(ARG)
Definition: util.h:281
#define TAU_FSTART(ARG)
Definition: util.h:280
int nrow() const
retrieves number of rows out of all_data
Definition: csr.cxx:93
char * vals() const
retrieves array of values out of all_data
Definition: csr.cxx:101
int cdealloc(void *ptr)
free abstraction
Definition: memcontrol.cxx:480
Definition: apsp.cxx:17
void MKL_DCSRADD(char const *transa, int const *job, int const *sort, int const *n, int const *k, double const *a, int const *ja, int const *ia, double const *beta, double const *b, int const *jb, int const *ib, double *c, int *jc, int *ic, int const *nnzmax, int const *ierr)