Skip to content

Commit

Permalink
Various minor fixes
Browse files Browse the repository at this point in the history
* Parallel finite differences
* fixed some types
* ADUPROP_MPI define to enable MPI
  • Loading branch information
michel2323 committed Jul 16, 2018
1 parent 28637d9 commit 6f7b8a4
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 24 deletions.
18 changes: 11 additions & 7 deletions include/ad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ original variable.
#ifndef ADUPROP_AD_HPP_
#define ADUPROP_AD_HPP_
#include <iostream>
#include <cstdlib>
#include "perf.hpp"
#include "alg.hpp"
#include "user.hpp"
Expand Down Expand Up @@ -172,14 +173,16 @@ void fdJ_driver(const pVector<double> &xic, pMatrix<double> &J) {
\pre "Input system and state"
\post "Hessian"
*/
void fdH_driver(const pVector<double> &xic, pTensor3<double> &H) {
void fdH_driver(const pVector<double> &xic, pTensor3<double> &H, size_t start = 0, size_t end =0) {
size_t dim = xic.dim();
// no end argument is set, hence pick dim as end
if(end == 0) end = dim;
pVector<double> xpert1(dim);
pVector<double> xpert2(dim);
pMatrix<double> Jpert1(dim, dim);
pMatrix<double> Jpert2(dim, dim);
double pert = 1e-8;
for (size_t i = 0; i < dim; ++i) {
for (size_t i = start; i < end; ++i) {
for (size_t j = 0; j < dim; ++j) xpert1[j] = xic[j];
for (size_t j = 0; j < dim; ++j) xpert2[j] = xic[j];
xpert1[i] += pert/2.0;
Expand All @@ -188,7 +191,7 @@ void fdH_driver(const pVector<double> &xic, pTensor3<double> &H) {
t1s_driver(xpert2, Jpert2);
for (size_t j = 0; j < dim; ++j) {
for (size_t k = 0; k < dim; ++k) {
H[j][k][i] = (Jpert1[j][k] - Jpert2[j][k])/pert;
H[j][k][i-start] = (Jpert1[j][k] - Jpert2[j][k])/pert;
}
}
}
Expand All @@ -204,15 +207,16 @@ void fdH_driver(const pVector<double> &xic, pTensor3<double> &H) {
\pre "Input system and state"
\post "Tensor"
*/
void fdT_driver(const pVector<double> &xic, pTensor4<double> &T) {
void fdT_driver(const pVector<double> &xic, pTensor4<double> &T, size_t start = 0, size_t end = 0) {
size_t dim = xic.dim();
if(end == 0) end = dim;
pVector<double> xpert1(dim);
pVector<double> xpert2(dim);
pMatrix<double> J(dim, dim);
pTensor3<double> Hpert1(dim, dim, dim);
pTensor3<double> Hpert2(dim, dim, dim);
double pert = 1e-8;
for (size_t i = 0; i < dim; ++i) {
for (size_t i = start; i < end; ++i) {
cout << "Computing tensor. "
<< (double) i*(double) 100.0/(double) dim << "\% done." << endl;
for (size_t j = 0; j < dim; ++j) xpert1[j] = xic[j];
Expand All @@ -224,7 +228,7 @@ void fdT_driver(const pVector<double> &xic, pTensor4<double> &T) {
for (size_t j = 0; j < dim; ++j) {
for (size_t k = 0; k < dim; ++k) {
for (size_t l = 0; l < dim; ++l) {
T[j][k][l][i] = (Hpert1[j][k][l] - Hpert2[j][k][l])/pert;
T[j][k][l][i-start] = (Hpert1[j][k][l] - Hpert2[j][k][l])/pert;
}
}
}
Expand Down Expand Up @@ -847,7 +851,7 @@ void propagateAD(pVector<double>& m0, pMatrix<double>& cv0, System& sys,
exit(-1);
}

double cutrate = 1.0 - 1.0/(double) dim;
// double cutrate = 1.0 - 1.0/(double) dim;
// double cutrate = 0.4;
// Obtain tensors
if(paduprop_getrank() == 0) {
Expand Down
2 changes: 1 addition & 1 deletion include/parallel.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef ADUPROP_PARALLEL_HPP_
#define ADUPROP_PARALLEL_HPP_
#ifdef MPI_VERSION
#ifdef ADUPROP_MPI
#include <mpi.h>
#endif
#include <fstream>
Expand Down
4 changes: 2 additions & 2 deletions include/perf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

#include <map>
#include <iostream>
#ifdef MPI_VERSION
#ifdef ADUPROP_MPI
#include <mpi.h>
#endif


// E.g. __rdtsc() or MPI_Wtime()
#ifdef MPI_VERSION
#ifdef ADUPROP_MPI
#define ADUPROP_TIMER MPI_Wtime()
#define ADUPROP_TIMER_TYPE double
#else
Expand Down
2 changes: 1 addition & 1 deletion test/covariance/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main(int argc, char* argv[]) {

// Variable declaration
int nbuses, nbranches, ngen, nload;
int tsteps = 20;
size_t tsteps = 20;
size_t dim;
pVector<double> xold, x, F;
pVector<double> x0;
Expand Down
8 changes: 4 additions & 4 deletions test/covariance/user.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ void expandComplex(int i, int j, double a, double b,

class System {
public:
int nbuses;
int nbranches;
int ngens;
int nloads;
size_t nbuses;
size_t nbranches;
size_t ngens;
size_t nloads;

double deltat; // step size for beuler
size_t dimension;
Expand Down
1 change: 1 addition & 0 deletions test/lorenz/lorenz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int main(int argc, char* argv[]) {
// jacobian test
if (test_jac) {
drivers.jactest(xold);
exit(0);
}

std::cout << "Computing sensitivities at x:" << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions test/pcovariance_hessian/user.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ void expandComplex(int i, int j, double a, double b,

class System {
public:
int nbuses;
int nbranches;
int ngens;
int nloads;
size_t nbuses;
size_t nbranches;
size_t ngens;
size_t nloads;

double deltat; // step size for beuler
size_t dimension;
Expand Down
2 changes: 1 addition & 1 deletion test/pcovariance_tensor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main(int argc, char* argv[]) {

// Variable declaration
int nbuses, nbranches, ngen, nload;
int tsteps = 2;
size_t tsteps = 2;
size_t dim;
pVector<double> xold, x, F;
pVector<double> x0;
Expand Down
8 changes: 4 additions & 4 deletions test/pcovariance_tensor/user.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ void expandComplex(int i, int j, double a, double b,

class System {
public:
int nbuses;
int nbranches;
int ngens;
int nloads;
size_t nbuses;
size_t nbranches;
size_t ngens;
size_t nloads;

double deltat; // step size for beuler
size_t dimension;
Expand Down

0 comments on commit 6f7b8a4

Please sign in to comment.