1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/* Ergo, version 3.8, a program for linear scaling electronic structure
* calculations.
* Copyright (C) 2019 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
* and Anastasia Kruchinina.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Primary academic reference:
* Ergo: An open-source program for linear-scaling electronic structure
* calculations,
* Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
* Kruchinina,
* SoftwareX 7, 107 (2018),
* <http://dx.doi.org/10.1016/j.softx.2018.03.005>
*
* For further information about Ergo, see <http://www.ergoscf.org>.
*/
/** @file matInclude.h
*
* Copyright(c) Emanuel Rubensson 2006
*
* @author Emanuel Rubensson @a responsible @a author
* @date October 2006
*
*/
#ifndef MAT_MATINCLUDE
#define MAT_MATINCLUDE
#include <iostream>
#include <vector>
#include <fstream>
#include <ios>
#include <cassert>
#include <ctime>
#include <limits>
#include <stdexcept>
#ifdef _OPENMP
#include <omp.h>
#endif
/* We need to include config.h to get the PRECISION_QUAD_FLT128 and USE_SSE_INTRINSICS flags. */
#include "config.h"
#include "template_blas_num_limits.h"
#include "Failure.h"
#include "DebugPolicies.h"
#include "SizesAndBlocks.h"
#include "Memory_buffer_thread.h"
#ifdef _OPENMP
#define MAT_OMP_INIT enum omp_failType {noFail = 0, standardFail, runtimeFail, matFail}; \
volatile omp_failType omp_fail = noFail; \
std::exception omp_exce; \
std::runtime_error omp_runtime(""); \
Failure omp_matFail; \
omp_set_nested(true);
// if (omp_fail == noFail) {
#define MAT_OMP_START try {
#define MAT_OMP_END } \
catch(Failure & omp_fail_caught) { \
omp_fail = matFail; omp_matFail = omp_fail_caught; } \
catch(std::runtime_error & omp_runtime_caught) { \
omp_fail = runtimeFail; omp_runtime = omp_runtime_caught; } \
catch(std::exception & omp_exce_caught) { \
omp_fail = standardFail; omp_exce = omp_exce_caught; \
}
#define MAT_OMP_FINALIZE if(omp_fail) \
{ std::cerr<<"Exception was thrown in OpenMP parallel region\n"; \
switch (omp_fail) { \
case standardFail: throw omp_exce; break; \
case runtimeFail: throw omp_runtime; break; \
case matFail: throw omp_matFail; break; \
default: throw Failure("Odd error in omp parallel loop\n");} \
}
#else
#define MAT_OMP_INIT
#define MAT_OMP_START
#define MAT_OMP_END
#define MAT_OMP_FINALIZE
#endif
namespace mat{
class Params {
protected:
#ifdef _OPENMP
static unsigned int nProcs;
static unsigned int matrixParallelLevel;
#endif
public:
static unsigned int getNProcs() {
#ifdef _OPENMP
if (nProcs == 0)
throw Failure("mat::Params::getNProcs(): nProcs == 0 Forgot to call setNProcs()?");
return nProcs;
#else
return 1;
#endif
}
static void setNProcs(unsigned int const nP) {
#ifdef _OPENMP
nProcs = nP;
#ifdef USE_SSE_INTRINSICS
Memory_buffer_thread::instance().init_buffers(nProcs);
#endif
#endif
}
static unsigned int getMatrixParallelLevel() {
#ifdef _OPENMP
if (matrixParallelLevel == 0)
throw Failure("mat::Params::getMatrixParallelLevel(): matrixParallelLevel == 0 Forgot to call setMatrixParallelLevel()?");
return matrixParallelLevel;
#else
return 0;
#endif
}
static void setMatrixParallelLevel(unsigned int const mPL) {
#ifdef _OPENMP
matrixParallelLevel = mPL;
#endif
}
};
enum property {zero, ful};
enum normType {frobNorm, euclNorm, mixedNorm};
normType getNormType(const char* normStr);
std::string getNormTypeString(normType nType);
/* getMachineEpsilon(): function for getting the machine epsilon (the
difference between 1 and the least value greater than 1 that is
representable) for the given floating-point type. */
template<typename Treal>
inline static Treal getMachineEpsilon() {
return template_blas_get_machine_epsilon<Treal>();
}
template<typename Treal>
inline static Treal getRelPrecision() {
return getMachineEpsilon<Treal>();
}
class Time {
static double get_wall_seconds();
double ticTime;
public:
Time();
void tic();
float toc();
};
class MemUsage {
private:
static int getNumberFromBuffer(const char* buffer, const char* s);
public:
struct Values {
float res;
float virt;
float peak;
Values() : res(0), virt(0), peak(0) { }
};
static void getMemUsage(Values & values);
};
} /* end namespace mat */
#endif
|