Minor changes, mostly signed comparisons and adding includes for

dependency documentation.
This commit is contained in:
couriersud 2016-04-08 17:02:33 +02:00
parent 50d78ba017
commit 07645b6670
9 changed files with 42 additions and 38 deletions

View File

@ -18,10 +18,10 @@ SRC = ..
CDEFS = -DPSTANDALONE=1 -DPTR64=1 CDEFS = -DPSTANDALONE=1 -DPTR64=1
#-Werror #-Werror
CFLAGS = $(LTO) -g -O3 -std=c++98 -Doverride="" -march=native -msse4.2 -Wall -Wpedantic -Wsign-compare -Wextra -Wno-long-long -Wno-unused-parameter -Wno-unused-result -Wno-variadic-macros -I.. #CFLAGS = $(LTO) -g -O3 -std=c++98 -Doverride="" -march=native -msse4.2 -Wall -Wpedantic -Wsign-compare -Wextra -Wno-long-long -Wno-unused-parameter -Wno-unused-result -Wno-variadic-macros -I..
LDFLAGS = $(LTO) -g -O3 -std=c++98 #LDFLAGS = $(LTO) -g -O3 -std=c++98
#CFLAGS = $(LTO) -g -O3 -std=c++11 -Wall -Wpedantic -Wsign-compare -Wextra -Isrc CFLAGS = $(LTO) -g -O3 -std=c++11 -I.. -Wall -Wpedantic -Wsign-compare -Wextra -Wno-unused-parameter
#LDFLAGS = $(LTO) -g -O3 -std=c++11 LDFLAGS = $(LTO) -g -O3 -std=c++11
CC = @g++-5 CC = @g++-5
LD = @g++-5 LD = @g++-5
@ -66,7 +66,6 @@ NLOBJS := \
$(NLOBJ)/analog/nld_opamps.o \ $(NLOBJ)/analog/nld_opamps.o \
$(NLOBJ)/devices/nld_4020.o \ $(NLOBJ)/devices/nld_4020.o \
$(NLOBJ)/devices/nld_4066.o \ $(NLOBJ)/devices/nld_4066.o \
$(NLOBJ)/devices/nld_7400.o \
$(NLOBJ)/devices/nld_7402.o \ $(NLOBJ)/devices/nld_7402.o \
$(NLOBJ)/devices/nld_7404.o \ $(NLOBJ)/devices/nld_7404.o \
$(NLOBJ)/devices/nld_7408.o \ $(NLOBJ)/devices/nld_7408.o \

View File

@ -126,7 +126,7 @@ public:
int indexof(const _ListClass &elem) const int indexof(const _ListClass &elem) const
{ {
for (int i = 0; i < this->size(); i++) for (unsigned i = 0; i < this->size(); i++)
{ {
if (this->at(i) == elem) if (this->at(i) == elem)
return i; return i;

View File

@ -34,7 +34,7 @@ struct mat_cr_t
while (k < oe) while (k < oe)
{ {
double tmp = 0.0; T tmp = 0.0;
const unsigned e = ia[i+1]; const unsigned e = ia[i+1];
for (; k < e; k++) for (; k < e; k++)
tmp += A[k] * x[ja[k]]; tmp += A[k] * x[ja[k]];
@ -42,7 +42,8 @@ struct mat_cr_t
} }
} }
void incomplete_LU_factorization(const nl_double * RESTRICT A, nl_double * RESTRICT LU) template<typename T>
void incomplete_LU_factorization(const T * RESTRICT A, T * RESTRICT LU)
{ {
/* /*
* incomplete LU Factorization according to http://de.wikipedia.org/wiki/ILU-Zerlegung * incomplete LU Factorization according to http://de.wikipedia.org/wiki/ILU-Zerlegung
@ -64,7 +65,7 @@ struct mat_cr_t
// pk == (i, k) // pk == (i, k)
const unsigned k = ja[pk]; const unsigned k = ja[pk];
const unsigned iak1 = ia[k + 1]; const unsigned iak1 = ia[k + 1];
const double LUpk = LU[pk] = LU[pk] / LU[diag[k]]; const T LUpk = LU[pk] = LU[pk] / LU[diag[k]];
unsigned pt = ia[k]; unsigned pt = ia[k];
@ -81,7 +82,8 @@ struct mat_cr_t
} }
} }
void solveLUx (const nl_double * RESTRICT LU, nl_double * RESTRICT r) template<typename T>
void solveLUx (const T * RESTRICT LU, T * RESTRICT r)
{ {
/* /*
* Solve a linear equation Ax = r * Solve a linear equation Ax = r
@ -109,7 +111,7 @@ struct mat_cr_t
for (i = 1; ia[i] < nz_num; i++ ) for (i = 1; ia[i] < nz_num; i++ )
{ {
double tmp = 0.0; T tmp = 0.0;
const unsigned j1 = ia[i]; const unsigned j1 = ia[i];
const unsigned j2 = diag[i]; const unsigned j2 = diag[i];
@ -122,7 +124,7 @@ struct mat_cr_t
for (; 0 < i; i-- ) for (; 0 < i; i-- )
{ {
const unsigned im1 = i - 1; const unsigned im1 = i - 1;
double tmp = 0.0; T tmp = 0.0;
const unsigned j1 = diag[im1] + 1; const unsigned j1 = diag[im1] + 1;
const unsigned j2 = ia[im1+1]; const unsigned j2 = ia[im1+1];
for (unsigned j = j1; j < j2; j++ ) for (unsigned j = j1; j < j2; j++ )

View File

@ -11,6 +11,7 @@
#include <algorithm> #include <algorithm>
#include "solver/nld_solver.h" #include "solver/nld_solver.h"
#include "solver/nld_matrix_solver.h"
#include "solver/vector_base.h" #include "solver/vector_base.h"
/* Disabling dynamic allocation gives a ~10% boost in performance /* Disabling dynamic allocation gives a ~10% boost in performance
@ -133,7 +134,7 @@ protected:
virtual int vsolve_non_dynamic(const bool newton_raphson) override; virtual int vsolve_non_dynamic(const bool newton_raphson) override;
int solve_non_dynamic(const bool newton_raphson); int solve_non_dynamic(const bool newton_raphson);
inline const unsigned N() const { if (m_N == 0) return m_dim; else return m_N; } inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
void build_LE_A(); void build_LE_A();
void build_LE_RHS(); void build_LE_RHS();

View File

@ -11,6 +11,7 @@
#include <algorithm> #include <algorithm>
#include "solver/nld_solver.h" #include "solver/nld_solver.h"
#include "solver/nld_matrix_solver.h"
//#define A(_r, _c) m_A[_r][_c] //#define A(_r, _c) m_A[_r][_c]

View File

@ -13,9 +13,9 @@
* In this specific implementation, u is a unit vector specifying the row which * In this specific implementation, u is a unit vector specifying the row which
* changed. Thus v contains the changed column. * changed. Thus v contains the changed column.
* *
* Than z = A????? u , w = transpose(A?????) v , lambda = v z * Than z = A¹ u , w = transpose(A¹) v , lambda = v z
* *
* A????? <- 1.0 / (1.0 + lambda) * (z x w) * A¹ <- 1.0 / (1.0 + lambda) * (z x w)
* *
* The approach is iterative and applied for each row changed. * The approach is iterative and applied for each row changed.
* *
@ -36,6 +36,7 @@
#include <algorithm> #include <algorithm>
#include "solver/nld_solver.h" #include "solver/nld_solver.h"
#include "solver/nld_matrix_solver.h"
#include "solver/vector_base.h" #include "solver/vector_base.h"
NETLIB_NAMESPACE_DEVICES_START() NETLIB_NAMESPACE_DEVICES_START()
@ -62,7 +63,7 @@ protected:
virtual int vsolve_non_dynamic(const bool newton_raphson) override; virtual int vsolve_non_dynamic(const bool newton_raphson) override;
int solve_non_dynamic(const bool newton_raphson); int solve_non_dynamic(const bool newton_raphson);
inline const unsigned N() const { if (m_N == 0) return m_dim; else return m_N; } inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
void build_LE_A(); void build_LE_A();
void build_LE_RHS(); void build_LE_RHS();
@ -454,14 +455,14 @@ void matrix_solver_sm_t<m_N, _storage_N>::LE_compute_x(
{ {
const unsigned kN = N(); const unsigned kN = N();
for (int i=0; i<kN; i++) for (unsigned i=0; i<kN; i++)
x[i] = 0.0; x[i] = 0.0;
for (int k=0; k<kN; k++) for (unsigned k=0; k<kN; k++)
{ {
const nl_double f = RHS(k); const nl_double f = RHS(k);
for (int i=0; i<kN; i++) for (unsigned i=0; i<kN; i++)
x[i] += Ainv(i,k) * f; x[i] += Ainv(i,k) * f;
} }
} }
@ -512,13 +513,13 @@ int matrix_solver_sm_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const boo
} }
else else
{ {
if (!incremental) if (not incremental)
{ {
for (int row = 0; row < iN; row ++) for (unsigned row = 0; row < iN; row ++)
for (int k = 0; k < iN; k++) for (unsigned k = 0; k < iN; k++)
Ainv(row,k) = lAinv(row, k); Ainv(row,k) = lAinv(row, k);
} }
for (int row = 0; row < iN; row ++) for (unsigned row = 0; row < iN; row ++)
{ {
nl_double v[m_pitch] = {0}; nl_double v[m_pitch] = {0};
unsigned cols[m_pitch]; unsigned cols[m_pitch];
@ -555,11 +556,11 @@ int matrix_solver_sm_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const boo
} }
lamba = -1.0 / (1.0 + lamba); lamba = -1.0 / (1.0 + lamba);
for (int i=0; i<iN; i++) for (unsigned i=0; i<iN; i++)
{ {
const nl_double f = lamba * z[i]; const nl_double f = lamba * z[i];
if (f != 0.0) if (f != 0.0)
for (int k = 0; k < iN; k++) for (unsigned k = 0; k < iN; k++)
Ainv(i,k) += f * w[k]; Ainv(i,k) += f * w[k];
} }
} }

View File

@ -15,7 +15,7 @@
* Whilst the book proposes to invert the matrix R=(I+transpose(V)*Z) we define * Whilst the book proposes to invert the matrix R=(I+transpose(V)*Z) we define
* *
* w = transpose(V)*y * w = transpose(V)*y
* a = R????? * w * a = R¹ * w
* *
* and consequently * and consequently
* *
@ -43,6 +43,7 @@
#include <algorithm> #include <algorithm>
#include "solver/nld_solver.h" #include "solver/nld_solver.h"
#include "solver/nld_matrix_solver.h"
#include "solver/vector_base.h" #include "solver/vector_base.h"
NETLIB_NAMESPACE_DEVICES_START() NETLIB_NAMESPACE_DEVICES_START()
@ -69,7 +70,7 @@ protected:
virtual int vsolve_non_dynamic(const bool newton_raphson) override; virtual int vsolve_non_dynamic(const bool newton_raphson) override;
int solve_non_dynamic(const bool newton_raphson); int solve_non_dynamic(const bool newton_raphson);
inline const unsigned N() const { if (m_N == 0) return m_dim; else return m_N; } inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; }
void build_LE_A(); void build_LE_A();
void build_LE_RHS(); void build_LE_RHS();
@ -467,14 +468,14 @@ void matrix_solver_w_t<m_N, _storage_N>::LE_compute_x(
{ {
const unsigned kN = N(); const unsigned kN = N();
for (int i=0; i<kN; i++) for (unsigned i=0; i<kN; i++)
x[i] = 0.0; x[i] = 0.0;
for (int k=0; k<kN; k++) for (unsigned k=0; k<kN; k++)
{ {
const nl_double f = RHS(k); const nl_double f = RHS(k);
for (int i=0; i<kN; i++) for (unsigned i=0; i<kN; i++)
x[i] += Ainv(i,k) * f; x[i] += Ainv(i,k) * f;
} }
} }
@ -531,7 +532,7 @@ int matrix_solver_w_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const bool
unsigned rowcount=0; unsigned rowcount=0;
#define VT(r,c) (A(r,c) - lA(r,c)) #define VT(r,c) (A(r,c) - lA(r,c))
for (int row = 0; row < iN; row ++) for (unsigned row = 0; row < iN; row ++)
{ {
unsigned cc=0; unsigned cc=0;
auto &nz = m_terms[row]->m_nz; auto &nz = m_terms[row]->m_nz;
@ -596,7 +597,7 @@ int matrix_solver_w_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const bool
} }
/* Back substitution */ /* Back substitution */
//inv(H) w = t w = H t //inv(H) w = t w = H t
nl_double *t = new nl_double[rowcount]; nl_double t[_storage_N]; // FIXME: convert to member
for (int j = rowcount - 1; j >= 0; j--) for (int j = rowcount - 1; j >= 0; j--)
{ {
nl_double tmp = 0; nl_double tmp = 0;
@ -619,7 +620,6 @@ int matrix_solver_w_t<m_N, _storage_N>::solve_non_dynamic(ATTR_UNUSED const bool
} }
new_V[i] -= tmp; new_V[i] -= tmp;
} }
delete[] t;
} }
} }
m_cnt++; m_cnt++;