22#ifndef MADNESS_TENSOR_MTXMQ_H__INCLUDED
23#define MADNESS_TENSOR_MTXMQ_H__INCLUDED
33#if !defined(MADNESS_RESTRICT)
34# if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
35# define MADNESS_RESTRICT __restrict__
37# define MADNESS_RESTRICT
43namespace mTxmq_detail {
57 template <
typename T>
struct Scratch { std::vector<T>
buf; };
61 static ::madness::detail::thread_specific<Scratch<T>> pool;
68 if (s.buf.size() < need) s.buf.resize(need);
82template <
typename aT,
typename bT,
typename cT>
88 if (ldb == -1) ldb = dimj;
92 if (dimi <= 0 || dimj <= 0)
return;
94 for (
long i = 0; i < dimi * dimj; ++i)
c[i] = cT(0);
97 for (
long i = 0; i < dimi; ++i,
c += dimj, ++
a) {
98 for (
long j = 0; j < dimj; ++j)
c[j] = cT(0);
99 const aT *aik_ptr =
a;
100 for (
long k = 0;
k < dimk; ++
k, aik_ptr += dimi) {
102 for (
long j = 0; j < dimj; ++j) {
103 c[j] += aki *
b[
k * ldb + j];
115void mTxmq(
long dimi,
long dimj,
long dimk,
123void mTxmq(
long dimi,
long dimj,
long dimk,
130void mTxmq(
long dimi,
long dimj,
long dimk,
137void mTxmq(
long dimi,
long dimj,
long dimk,
139 const std::complex<double>*
a,
140 const std::complex<double>*
b,
144void mTxmq(
long dimi,
long dimj,
long dimk,
146 const std::complex<float>*
a,
147 const std::complex<float>*
b,
154inline void mTxmq(
long dimi,
long dimj,
long dimk,
156 const std::complex<T>*
a,
159 if (ldb == -1) ldb = dimj;
161 if (dimi <= 0 || dimj <= 0)
return;
163 for (
long i = 0; i < dimi * dimj; ++i) c[i] = std::complex<T>(0, 0);
167 const long c_sz = dimi * dimj;
168 const long a_sz = dimi * dimk;
170 T* Ra = mTxmq_detail::scratch<T>(
static_cast<std::size_t
>(2 * a_sz + 2 * c_sz));
175 const T* a_raw =
reinterpret_cast<const T*
>(
a);
176 for (
long i = 0; i < a_sz; ++i) {
177 Ra[i] = a_raw[2 * i];
178 Ia[i] = a_raw[2 * i + 1];
181 mTxmq(dimi, dimj, dimk, Rc, Ra,
b, ldb);
182 mTxmq(dimi, dimj, dimk, Ic, Ia,
b, ldb);
184 T* c_raw =
reinterpret_cast<T*
>(
c);
185 for (
long i = 0; i < c_sz; ++i) {
186 c_raw[2 * i] = Rc[i];
187 c_raw[2 * i + 1] = Ic[i];
193inline void mTxmq(
long dimi,
long dimj,
long dimk,
201template <
typename aT,
typename bT,
typename cT>
202inline void mTxmq(
long dimi,
long dimj,
long dimk,
Definition thread_specific.h:82
#define MADNESS_RESTRICT
Definition mTxmq.h:37
Macros and tools pertaining to the configuration of MADNESS.
Defines madness::MadnessException for exception handling.
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:182
constexpr long MAX_DIMI
Definition mTxmq.h:44
::madness::detail::thread_specific< Scratch< T > > & scratch_pool()
Definition mTxmq.h:60
T * scratch(std::size_t need)
Definition mTxmq.h:66
constexpr long MAX_DIMJ
Definition mTxmq.h:45
constexpr long MAX_DIMK
Definition mTxmq.h:46
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
void print_mtxmq_profile()
Print call profile and shape statistics for mTxmq (automatically called at exit)
Definition mTxmq.cc:546
void mTxmq_init()
Definition mTxmq.cc:548
void mTxmq_scratch_clear()
Free every thread's mTxmq scratch buffers. Call only at a quiescent point.
Definition mTxmq.h:75
void mTxmq_reference(long dimi, long dimj, long dimk, cT *MADNESS_RESTRICT c, const aT *a, const bT *b, long ldb=-1)
Reference implementation for verification / fallback.
Definition mTxmq.h:83
void reset_mtxmq_profile()
Reset profiling statistics counters.
Definition mTxmq.cc:547
void mTxmq(long dimi, long dimj, long dimk, double *MADNESS_RESTRICT c, const double *a, const double *b, long ldb)
Explicit template specializations for homogeneous types (implemented in mTxmq.cc)
Definition mTxmq.cc:551
static const double b
Definition nonlinschro.cc:119
static const double a
Definition nonlinschro.cc:118
static const double c
Definition relops.cc:10
static const long k
Definition rk.cc:44
std::vector< T > buf
Definition mTxmq.h:57
Reclaimable thread-specific storage (a thread_local you can free).