Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
src/interface/scalar.cxx
Go to the documentation of this file.
1 /*Copyright (c) 2011, Edgar Solomonik, all rights reserved.*/
2 #include "common.h"
3 
4 namespace CTF {
5 
6  template<typename dtype>
7  Scalar<dtype>::Scalar(World & world_, CTF_int::algstrct const & sr_) :
8  Tensor<dtype>(0, 0, NULL, NULL, world_, sr_) {
9 
10  }
11 
12  template<typename dtype>
14  World & world,
15  CTF_int::algstrct const & sr_)
16  : Tensor<dtype>(0, 0, NULL, NULL, world, sr_) {
17  int64_t s;
18  dtype * arr;
19 
20  if (world.cdt.rank == 0){
21  arr = this->get_raw_data(&s);
22  arr[0] = val;
23  }
24  }
25 
26 
27  template<typename dtype>
29  int64_t s;
30  dtype * datap;
31  dtype val;
32  datap = this->get_raw_data(&s);
33  memcpy(&val, datap, sizeof(dtype));
34  MPI_Bcast((char *)&val, sizeof(dtype), MPI_CHAR, 0, this->wrld->comm);
35  return val;
36  }
37 
38  template<typename dtype>
39  void Scalar<dtype>::set_val(dtype const val){
40  int64_t s;
41  dtype * arr;
42  if (this->world->ctf->get_rank() == 0){
43  arr = this->world->ctf->get_raw_data(&s);
44  arr[0] = val;
45  }
46  }
47 
48  template<typename dtype>
51  CTF_int::tensor::init(A.sr, A.order, A.lens, A.sym, A.wrld, 1, A.name, A.profile, A.is_sparse);
52  return *this;
53  }
54 
55 }
CTF_int::CommData cdt
communicator data for MPI comm defining this world
Definition: world.h:32
int * sym
symmetries among tensor dimensions
dtype get_val()
returns scalar value
an instance of the CTF library (world) on a MPI communicator
Definition: world.h:19
bool is_sparse
whether only the non-zero elements of the tensor are stored
int order
number of tensor dimensions
CTF::World * wrld
distributed processor context on which tensor is defined
Scalar class which encapsulates a 0D tensor.
Definition: scalar.h:13
int * lens
unpadded tensor edge lengths
algstrct * sr
algstrct on which tensor elements and operations are defined
Scalar< dtype > & operator=(const Scalar< dtype > &A)
void set_val(dtype val)
sets scalar value
bool profile
whether profiling should be done for contractions/sums involving this tensor
dtype * get_raw_data(int64_t *size) const
gives the raw current local data with padding included
Definition: tensor.cxx:152
algstrct (algebraic structure) defines the elementwise operations computed in each tensor contraction...
Definition: algstrct.h:34
Definition: apsp.cxx:17
an instance of a tensor within a CTF world
Definition: tensor.h:74
void free_self()
destructor
Scalar(World &wrld=get_universe(), CTF_int::algstrct const &sr=Ring< dtype >())
constructor for a scalar
char * name
name given to tensor
void init(algstrct const *sr, int order, int const *edge_len, int const *sym, CTF::World *wrld, bool alloc_data, char const *name, bool profile, bool is_sparse)
initializes tensor data
MPI_Comm comm
set of processors making up this world
Definition: world.h:22