Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
set.cxx
Go to the documentation of this file.
1 #include "set.h"
2 #include "../shared/blas_symbs.h"
3 #include "../shared/mkl_symbs.h"
4 #include "../shared/util.h"
5 
6 
7 namespace CTF_int {
8 
9 #ifdef USE_MPI_CPP
10  MPI_Datatype MPI_CTF_BOOL = MPI::BOOL;
11  MPI_Datatype MPI_CTF_DOUBLE_COMPLEX = MPI::DOUBLE_COMPLEX;
12  MPI_Datatype MPI_CTF_LONG_DOUBLE_COMPLEX = MPI::LONG_DOUBLE_COMPLEX;
13 #else
14  MPI_Datatype MPI_CTF_BOOL = MPI_CXX_BOOL;
15  MPI_Datatype MPI_CTF_DOUBLE_COMPLEX = MPI_CXX_DOUBLE_COMPLEX;
16  MPI_Datatype MPI_CTF_LONG_DOUBLE_COMPLEX = MPI_CXX_LONG_DOUBLE_COMPLEX;
17 #endif
18 
19 #if USE_MKL
20  void def_coo_to_csr_fl(int64_t nz, int nrow, float * csr_vs, int * csr_ja, int * csr_ia, float * coo_vs, int * coo_rs, int * coo_cs, bool to_csr){
21  int inz = nz;
22  int info;
23 
24  if (to_csr){
25  int job[8]={2,1,1,0,inz,0,0,0};
26  CTF_BLAS::MKL_SCSRCOO(job, &nrow, csr_vs, csr_ja, csr_ia, &inz, (float*)coo_vs, coo_rs, coo_cs, &info);
27  } else {
28  int job[8]={0,1,1,0,inz,3,0,0};
29  CTF_BLAS::MKL_SCSRCOO(job, &nrow, csr_vs, csr_ja, csr_ia, &inz, (float*)coo_vs, coo_rs, coo_cs, &info);
30  }
31  }
32  void def_coo_to_csr_dbl(int64_t nz, int nrow, double * csr_vs, int * csr_ja, int * csr_ia, double * coo_vs, int * coo_rs, int * coo_cs, bool to_csr){
33  int inz = nz;
34  int info;
35  if (to_csr){
36  TAU_FSTART(MKL_DCOOCSR);
37  int job[8]={2,1,1,0,inz,0,0,0};
38  CTF_BLAS::MKL_DCSRCOO(job, &nrow, csr_vs, csr_ja, csr_ia, &inz, (double*)coo_vs, coo_rs, coo_cs, &info);
39  TAU_FSTOP(MKL_DCOOCSR);
40  } else {
42  int job[8]={0,1,1,0,inz,3,0,0};
43  CTF_BLAS::MKL_DCSRCOO(job, &nrow, csr_vs, csr_ja, csr_ia, &inz, (double*)coo_vs, coo_rs, coo_cs, &info);
44  /*printf("converted %d nonzers to coo\n", inz);
45  for (int i=0; i<inz; i++){
46  printf("i=%d\n",i);
47  printf("vs[i] = %lf\n",coo_vs[i]);
48  printf("rs[i] = %d\n",coo_rs[i]);
49  printf("cs[i] = %d\n",coo_cs[i]);
50  }*/
51  ASSERT(inz == nz);
53  }
54  }
55 
56  void def_coo_to_csr_cdbl(int64_t nz, int nrow, std::complex<double> * csr_vs, int * csr_ja, int * csr_ia, std::complex<double> * coo_vs, int * coo_rs, int * coo_cs, bool to_csr){
57  int inz = nz;
58  int info;
59 
60  if (to_csr){
61  int job[8]={2,1,1,0,inz,0,0,0};
62  CTF_BLAS::MKL_ZCSRCOO(job, &nrow, csr_vs, csr_ja, csr_ia, &inz, (std::complex<double>*)coo_vs, coo_rs, coo_cs, &info);
63  } else {
64  int job[8]={0,1,1,0,inz,3,0,0};
65  CTF_BLAS::MKL_ZCSRCOO(job, &nrow, csr_vs, csr_ja, csr_ia, &inz, (std::complex<double>*)coo_vs, coo_rs, coo_cs, &info);
66  }
67  }
68 #endif
69 
70  bool try_mkl_coo_to_csr(int64_t nz, int nrow, char * csr_vs, int * csr_ja, int * csr_ia, char const * coo_vs, int const * coo_rs, int const * coo_cs, int el_size){
71 #if USE_MKL
72  switch (el_size){
73  case 4:
74  def_coo_to_csr_fl(nz,nrow,(float*)csr_vs,csr_ja,csr_ia,(float*)coo_vs,(int*)coo_rs,(int*)coo_cs,1);
75  return true;
76  break;
77  case 8:
78  def_coo_to_csr_dbl(nz,nrow,(double*)csr_vs,csr_ja,csr_ia,(double*)coo_vs,(int*)coo_rs,(int*)coo_cs,1);
79  return true;
80  break;
81  case 16:
82  def_coo_to_csr_cdbl(nz,nrow,(std::complex<double>*)csr_vs,csr_ja,csr_ia,(std::complex<double>*)coo_vs,(int*)coo_rs,(int*)coo_cs,1);
83  return true;
84  break;
85  }
86 #endif
87  return false;
88  }
89 
90 
91  bool try_mkl_csr_to_coo(int64_t nz, int nrow, char const * csr_vs, int const * csr_ja, int const * csr_ia, char * coo_vs, int * coo_rs, int * coo_cs, int el_size){
92 #if USE_MKL
93  switch (el_size){
94  case 4:
95  def_coo_to_csr_fl(nz,nrow,(float*)csr_vs,(int*)csr_ja,(int*)csr_ia,(float*)coo_vs,coo_rs,coo_cs,0);
96  return true;
97  break;
98  case 8:
99  def_coo_to_csr_dbl(nz,nrow,(double*)csr_vs,(int*)csr_ja,(int*)csr_ia,(double*)coo_vs,coo_rs,coo_cs,0);
100  return true;
101  break;
102  case 16:
103  def_coo_to_csr_cdbl(nz,nrow,(std::complex<double>*)csr_vs,(int*)csr_ja,(int*)csr_ia,(std::complex<double>*)coo_vs,coo_rs,coo_cs,0);
104  return true;
105  break;
106  }
107 #endif
108  return false;
109  }
110 }
111 
112 namespace CTF {
113  template <>
114  void CTF::Set<float,true>::copy(int64_t nn, char const * a, int inc_a, char * b, int inc_b) const {
115  int n = nn;
116  CTF_BLAS::SCOPY(&n, (float const*)a, &inc_a, (float*)b, &inc_b);
117  }
118  template <>
119  void CTF::Set<double,true>::copy(int64_t nn, char const * a, int inc_a, char * b, int inc_b) const {
120  int n = nn;
121  CTF_BLAS::DCOPY(&n, (double const*)a, &inc_a, (double*)b, &inc_b);
122  }
123  template <>
124  void CTF::Set<std::complex<float>,false>::copy(int64_t nn, char const * a, int inc_a, char * b, int inc_b) const {
125  int n = nn;
126  CTF_BLAS::DCOPY(&n, (double const*)a, &inc_a, (double*)b, &inc_b);
127  }
128  template <>
129  void CTF::Set<std::complex<double>,false>::copy(int64_t nn, char const * a, int inc_a, char * b, int inc_b) const {
130  int n = nn;
131  CTF_BLAS::ZCOPY(&n, (std::complex<double> const*)a, &inc_a, (std::complex<double>*)b, &inc_b);
132  }
133 
134 }
Set class defined by a datatype and a min/max function (if it is partially ordered i...
Definition: set.h:280
void MKL_SCSRCOO(int const *job, int *n, float *acsr, int const *ja, int const *ia, int *nnz, float *acoo, int const *rowind, int const *colind, int *info)
bool try_mkl_coo_to_csr(int64_t nz, int nrow, char *csr_vs, int *csr_ja, int *csr_ia, char const *coo_vs, int const *coo_rs, int const *coo_cs, int el_size)
Definition: set.cxx:70
void copy(char *a, char const *b) const
copies element b to element a
Definition: set.h:433
void MKL_ZCSRCOO(int const *job, int *n, std::complex< double > *acsr, int const *ja, int const *ia, int *nnz, std::complex< double > *acoo, int const *rowind, int const *colind, int *info)
void SCOPY(const int *n, const float *dX, const int *incX, float *dY, const int *incY)
#define ASSERT(...)
Definition: util.h:88
#define MKL_DCSRCOO
Definition: mkl_symbs.h:36
void MKL_DCSRCOO(int const *job, int *n, double *acsr, int const *ja, int const *ia, int *nnz, double *acoo, int const *rowind, int const *colind, int *info)
bool try_mkl_csr_to_coo(int64_t nz, int nrow, char const *csr_vs, int const *csr_ja, int const *csr_ia, char *coo_vs, int *coo_rs, int *coo_cs, int el_size)
Definition: set.cxx:91
void DCOPY(const int *n, const double *dX, const int *incX, double *dY, const int *incY)
MPI_Datatype MPI_CTF_LONG_DOUBLE_COMPLEX
Definition: set.cxx:16
#define TAU_FSTOP(ARG)
Definition: util.h:281
#define TAU_FSTART(ARG)
Definition: util.h:280
def copy(tensor, A)
Definition: core.pyx:3583
Definition: apsp.cxx:17
void ZCOPY(const int *n, const std::complex< double > *dX, const int *incX, std::complex< double > *dY, const int *incY)
MPI_Datatype MPI_CTF_BOOL
Definition: set.cxx:14
MPI_Datatype MPI_CTF_DOUBLE_COMPLEX
Definition: set.cxx:15