MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
tensor.h
1//
2// tensor.h --- tensor class that contains an interface to MemoryGrp etc
3//
4// Copyright (C) 2008 Toru Shiozaki
5//
6// Author: Toru Shiozaki <shiozaki.toru@gmail.com>
7// Maintainer: TS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#ifndef _chemistry_qc_ccr12_tensor_h
29#define _chemistry_qc_ccr12_tensor_h
30
31#include <string>
32#include <vector>
33#include <util/misc/compute.h>
34#include <util/group/memory.h>
35#include <util/group/memregion.h>
36#include <util/group/message.h>
37#include <util/group/thread.h>
38#include <math/distarray4/distarray4.h>
39
40// note disk-based algorithm does not support parallel execution so far.
41#define DISK_BASED_SMITH
42
43#ifdef DISK_BASED_SMITH
44#include <fstream>
45#endif
46
47namespace sc {
48
49class Tensor : virtual public RefCount {
50 protected:
51 const Ref<MemoryGrp>& mem_;
52
54 std::string filename_;
55
57 std::map<long,long> hash_table_;
58
61
63#ifndef DISK_BASED_SMITH
65#else
66 std::fstream* file_;
67#endif
68 bool file_allocated_;
69
71 std::vector<long> determine_filesizes();
72
73 public:
74 Tensor(std::string filename,const Ref<MemoryGrp>& mem);
75 ~Tensor();
76
78 std::string filename() const {return filename_;};
79
81#ifndef DISK_BASED_SMITH
82 MemoryGrpRegion* file() const {return file_;};
83#else
84 std::fstream* file() { return file_; };
85#endif
86
88 void set_filesize(long i);
89 long get_filesize() const {return filesize_;};
90
92 void createfile();
93 void deletefile();
94
96 void input_offset(long tag, long offset);
97
99 void get_block(long tag, double* data);
101 void add_block(long tag, double* data);
103 void put_block(long tag, double* data);
105 bool exists(long tag) const;
107 bool is_this_local(long tag);
108
110 void zero();
111
113 void assign(double a);
114
116 double norm() const;
117
119 double ddot(Ref<Tensor>&) const;
120
123
126
128 void daxpy(const Ref<Tensor>&, double);
129
131 void scale(double a);
132
134#ifndef DISK_BASED_SMITH
135 void sync() const { const_cast<MemoryGrpRegion*>(file_)->sync();};
136#else
137 void sync() const {}; // disk-based algorithm does not support parallel runs so far
138#endif
139
141 void print(const std::string& label, std::ostream& os = ExEnv::out0()) const;
142};
143
147double RMS(const Tensor& t);
148
149}
150
151#endif
152
static std::ostream & out0()
Return an ostream that writes from node 0.
The MemoryGrpRegion is a MemoryGrp proxy to a region of a MemoryGrp.
Definition memregion.h:46
The base class for all reference counted objects.
Definition ref.h:192
A template class that maintains references counts.
Definition ref.h:361
Definition tensor.h:49
void set_filesize(long i)
set/get the filesize of the tensor
double ddot(Ref< Tensor > &) const
obtain the ddot of two tensors
void zero()
initialize/clear tensors to zero
std::string filename_
for use in disk-based algorithm
Definition tensor.h:54
void daxpy(const Ref< Tensor > &, double)
perform daxpy of tensors (self+=a*other)
long filesize_
tensor size in double
Definition tensor.h:60
Ref< Tensor > clone() const
return a tensor that have the same hashtable, and is intilaized to zero
void createfile()
create/delete the distributed file for the tensor
bool is_this_local(long tag)
returns if a block associated with long tag resides in a local memory or not
void print(const std::string &label, std::ostream &os=ExEnv::out0()) const
print
bool exists(long tag) const
does this block exist?
std::vector< long > determine_filesizes()
determines the distribution of blocks to nodes
Ref< Tensor > copy() const
return a copy of self
std::fstream * file_
data area
Definition tensor.h:66
void get_block(long tag, double *data)
get a block from the distributed file (non-blocking)
std::fstream * file()
returns MemoryGrpRegion for this tensor
Definition tensor.h:84
void input_offset(long tag, long offset)
input for the hash table
std::string filename() const
returns filename_
Definition tensor.h:78
void assign(double a)
assigns all values to a
void sync() const
sync
Definition tensor.h:137
void scale(double a)
scale self by a
void put_block(long tag, double *data)
put a block to the distributed file (non-blocking)
void add_block(long tag, double *data)
add a block to the distributed file (non-blocking); double* data will be destroyed
double norm() const
obtain the norm of a tensor
std::map< long, long > hash_table_
hash table: hash_table_.insert(key,offset)
Definition tensor.h:57
Contains all MPQC code up to version 3.
Definition mpqcin.h:14
double RMS(const Tensor &t)
Computes the `‘RMS norm’' of the tensor, defined as tensor->norm() divided by the size of the tensor.

Generated at Wed Sep 25 2024 02:45:29 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.