You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.8 KiB
78 lines
1.8 KiB
// ARRAY.H
|
|
#ifndef ARRAY_H
|
|
#define ARRAY_H
|
|
extern "C" {
|
|
#include "mkl.h"
|
|
}
|
|
#include "../dgtd-performance.hpp"
|
|
|
|
|
|
#ifdef VECTOR_BOUNDS_CHECK
|
|
#include <assert.h>
|
|
#endif
|
|
|
|
template<typename T>
|
|
class ArrayFP {
|
|
public:
|
|
unsigned int N;
|
|
T *entry;
|
|
|
|
explicit ArrayFP (unsigned int = 0);
|
|
~ArrayFP ();
|
|
|
|
void setup (int);
|
|
void addentry (int m, T val) { entry[m] += val; };
|
|
void setentry (int m, T val) { entry[m] = val; };
|
|
T magnitude ();
|
|
void reset () { for (int i = 0; i < N; i ++) entry[i] = 0.0;}
|
|
void addArray (const ArrayFP &);
|
|
T operator* (const ArrayFP &) const;
|
|
T getentry (int) const;
|
|
T* getEntryPtr () {return entry;}
|
|
void print ();
|
|
void print (char*);
|
|
void FreeMemory () { if (entry != NULL) delete [] entry;}
|
|
ArrayFP &operator = (const ArrayFP &);
|
|
void scale(T alpha) { for (int i = 0; i < N; i++) entry[i] = alpha*entry[i];}
|
|
// BLAS level 1 operations
|
|
void ax (T alpha, ArrayFP& x);
|
|
void axpy (T alpha, ArrayFP& x);
|
|
void axpby(T alpha, T beta, ArrayFP& x);
|
|
void xpby (T beta, ArrayFP& x);
|
|
T dotprod(ArrayFP& right);
|
|
|
|
|
|
void WriteToASCII (char* FileName, int& timeStep);
|
|
void ReadFromASCII(char* FileName, int& timeStep);
|
|
void WriteToASCII (char* FileName);
|
|
void ReadFromASCII(char* FileName);
|
|
void WriteToBinary (char* FileName);
|
|
void ReadFromBinary(char* FileName);
|
|
|
|
// indices and access operations
|
|
T& operator()(int i) {
|
|
#ifdef VECTOR_BOUNDS_CHECK
|
|
assert(i < dim_);
|
|
#endif
|
|
return entry[i];
|
|
}
|
|
|
|
const T& operator()(int i) const {
|
|
#ifdef VECTOR_BOUNDS_CHECK
|
|
assert(i < dim_);
|
|
#endif
|
|
return entry[i];
|
|
}
|
|
|
|
T& operator[](int i) {
|
|
#ifdef VECTOR_BOUNDS_CHECK
|
|
assert(i < dim_);
|
|
#endif
|
|
return entry[i];
|
|
}
|
|
|
|
};
|
|
|
|
template class ArrayFP<fp_t>;
|
|
|
|
#endif
|
|
|