Skip to content

Commit d95c67d

Browse files
committed
Merge pull request #8 from Parallel-in-Time/feature/tighten-mlsdc
Tighten up MLSDC: fewer function evals and other tidying.
2 parents 2e8f2df + 5f4e9d4 commit d95c67d

File tree

14 files changed

+363
-284
lines changed

14 files changed

+363
-284
lines changed

examples/advection_diffusion/CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ set(ex1_SOURCES
99
${CMAKE_CURRENT_SOURCE_DIR}/ex1.cpp
1010
)
1111

12-
set(ex2_SOURCES
13-
${CMAKE_CURRENT_SOURCE_DIR}/ex2.cpp
14-
)
15-
1612
add_executable(ex1 ${ex1_SOURCES})
1713
add_dependencies(ex1 fftw3)
1814
target_link_libraries(ex1
@@ -22,6 +18,9 @@ set_target_properties(ex1
2218
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${pfasst_BINARY_DIR}/examples
2319
)
2420

21+
set(ex2_SOURCES
22+
${CMAKE_CURRENT_SOURCE_DIR}/ex2.cpp
23+
)
2524
add_executable(ex2 ${ex2_SOURCES})
2625
add_dependencies(ex2 fftw3)
2726
target_link_libraries(ex2
@@ -30,3 +29,15 @@ target_link_libraries(ex2
3029
set_target_properties(ex2
3130
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${pfasst_BINARY_DIR}/examples
3231
)
32+
33+
set(ex3_SOURCES
34+
${CMAKE_CURRENT_SOURCE_DIR}/ex3.cpp
35+
)
36+
add_executable(ex3 ${ex3_SOURCES})
37+
add_dependencies(ex3 fftw3)
38+
target_link_libraries(ex3
39+
${fftw3_LIBS}
40+
)
41+
set_target_properties(ex3
42+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${pfasst_BINARY_DIR}/examples
43+
)

examples/advection_diffusion/advection_diffusion_sweeper.hpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <complex>
99
#include <vector>
1010

11-
#include <pfasst/encap/imex.hpp>
11+
#include <pfasst/encap/imex_sweeper.hpp>
1212
#include "fft.hpp"
1313

1414
#define pi 3.1415926535897932385
@@ -20,7 +20,7 @@ using pfasst::encap::Encapsulation;
2020

2121

2222
template<typename scalar, typename time>
23-
class AdvectionDiffusionSweeper : public pfasst::imex::IMEX<scalar,time> {
23+
class AdvectionDiffusionSweeper : public pfasst::encap::IMEXSweeper<scalar,time> {
2424

2525
using dvector = pfasst::encap::VectorEncapsulation<scalar,time>;
2626
FFT<scalar,time> fft;
@@ -30,6 +30,7 @@ class AdvectionDiffusionSweeper : public pfasst::imex::IMEX<scalar,time> {
3030
scalar v = 1.0;
3131
time t0 = 1.0;
3232
scalar nu = 0.02;
33+
int nf1evals = 0;
3334

3435
public:
3536

@@ -42,7 +43,11 @@ class AdvectionDiffusionSweeper : public pfasst::imex::IMEX<scalar,time> {
4243
ddx[i] = complex<scalar>(0.0, 1.0) * kx;
4344
lap[i] = (kx*kx < 1e-13) ? 0.0 : -kx*kx;
4445
}
46+
}
4547

48+
~AdvectionDiffusionSweeper()
49+
{
50+
cout << "number of f1 evals: " << nf1evals << endl;
4651
}
4752

4853
void exact(Encapsulation<scalar,time>* q, scalar t)
@@ -66,7 +71,7 @@ class AdvectionDiffusionSweeper : public pfasst::imex::IMEX<scalar,time> {
6671
}
6772
}
6873

69-
void echo_error(time t)
74+
void echo_error(time t, bool predict=false)
7075
{
7176
auto& qend = *dynamic_cast<dvector*>(this->get_state(this->get_nodes().size()-1));
7277
auto qex = dvector(qend.size());
@@ -79,18 +84,18 @@ class AdvectionDiffusionSweeper : public pfasst::imex::IMEX<scalar,time> {
7984
if (d > max)
8085
max = d;
8186
}
82-
cout << "err: " << scientific << max << " (" << qend.size() << ")" << endl;
87+
cout << "err: " << scientific << max << " (" << qend.size() << ", " << predict << ")" << endl;
8388
}
8489

85-
void predict(time t, time dt)
90+
void predict(time t, time dt, bool initial)
8691
{
87-
pfasst::imex::IMEX<scalar,time>::predict(t, dt);
88-
echo_error(t+dt);
92+
pfasst::encap::IMEXSweeper<scalar,time>::predict(t, dt, initial);
93+
echo_error(t+dt, true);
8994
}
9095

9196
void sweep(time t, time dt)
9297
{
93-
pfasst::imex::IMEX<scalar,time>::sweep(t, dt);
98+
pfasst::encap::IMEXSweeper<scalar,time>::sweep(t, dt);
9499
echo_error(t+dt);
95100
}
96101

@@ -105,6 +110,8 @@ class AdvectionDiffusionSweeper : public pfasst::imex::IMEX<scalar,time> {
105110
for (int i=0; i<q.size(); i++)
106111
z[i] *= c * ddx[i];
107112
fft.backward(f);
113+
114+
nf1evals++;
108115
}
109116

110117
void f2eval(Encapsulation<scalar,time> *F, Encapsulation<scalar,time> *Q, time t)

examples/advection_diffusion/ex1.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <pfasst.hpp>
8+
#include <pfasst/sdc.hpp>
89
#include <pfasst/encap/vector.hpp>
910

1011
#include "advection_diffusion_sweeper.hpp"

examples/advection_diffusion/ex2.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <pfasst.hpp>
8+
#include <pfasst/mlsdc.hpp>
89
#include <pfasst/encap/vector.hpp>
910

1011
#include "advection_diffusion_sweeper.hpp"
@@ -58,11 +59,9 @@ int main(int argc, char **argv)
5859
/*
5960
* set initial conditions on each level
6061
*/
61-
for (int l=0; l<nlevs; l++) {
62-
auto* sweeper = mlsdc.get_level<AdvectionDiffusionSweeper<double,double>>(l);
63-
auto* q0 = sweeper->get_state(0);
64-
sweeper->exact(q0, 0.0);
65-
}
62+
auto* sweeper = mlsdc.get_level<AdvectionDiffusionSweeper<double,double>>(mlsdc.nlevels()-1);
63+
auto* q0 = sweeper->get_state(0);
64+
sweeper->exact(q0, 0.0);
6665

6766
/*
6867
* run mlsdc!

examples/advection_diffusion/ex3.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <tuple>
1111

1212
#include <pfasst.hpp>
13+
#include <pfasst/mlsdc.hpp>
1314
#include <pfasst/encap/automagic.hpp>
1415
#include <pfasst/encap/vector.hpp>
1516

@@ -53,7 +54,8 @@ int main(int argc, char **argv)
5354
* the 'initial' function is called once for each level to set the
5455
* intial conditions.
5556
*/
56-
auto initial = [] (EncapSweeper<double,double> *sweeper, Encapsulation<double,double> *q0) {
57+
auto initial = [] (EncapSweeper<double,double> *sweeper,
58+
Encapsulation<double,double> *q0) {
5759
auto* ad = dynamic_cast<AdvectionDiffusionSweeper<double,double>*>(sweeper);
5860
ad->exact(q0, 0.0);
5961
};

examples/advection_diffusion/spectral_transfer_1d.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define _SPECTRAL_TRANSFER_1D_HPP_
77

88
#include <pfasst/encap/vector.hpp>
9+
#include <pfasst/encap/poly_interp.hpp>
10+
911
#include "fft.hpp"
1012

1113
template<typename scalar, typename time>

include/pfasst.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@
22
#define _PFASST_HPP_
33

44
#include "pfasst/interfaces.hpp"
5-
#include "pfasst/sdc.hpp"
6-
#include "pfasst/mlsdc.hpp"
7-
#include "pfasst/pfasst.hpp"
85

96
#endif

include/pfasst/encap/automagic.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <tuple>
66

77
#include "../quadrature.hpp"
8-
#include "encapsulation.hpp"
8+
#include "encap_sweeper.hpp"
99

1010
using namespace std;
1111

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Host based encapsulated base sweeper.
3+
*/
4+
5+
#ifndef _PFASST_ENCAP_ENCAP_SWEEPER_HPP_
6+
#define _PFASST_ENCAP_ENCAP_SWEEPER_HPP_
7+
8+
#include <vector>
9+
10+
#include "../interfaces.hpp"
11+
#include "../quadrature.hpp"
12+
#include "encapsulation.hpp"
13+
14+
namespace pfasst {
15+
namespace encap {
16+
17+
template<typename scalar, typename time>
18+
class EncapSweeper : public ISweeper {
19+
vector<scalar> nodes;
20+
shared_ptr<EncapFactory<scalar,time>> factory;
21+
22+
public:
23+
24+
void set_nodes(vector<time> nodes)
25+
{
26+
this->nodes = nodes;
27+
}
28+
29+
const vector<time> get_nodes() const
30+
{
31+
return nodes;
32+
}
33+
34+
void set_factory(EncapFactory<scalar,time>* factory)
35+
{
36+
this->factory = shared_ptr<EncapFactory<scalar,time>>(factory);
37+
}
38+
39+
EncapFactory<scalar,time>* get_factory() const
40+
{
41+
return factory.get();
42+
}
43+
44+
virtual void set_state(const Encapsulation<scalar,time>* q0, unsigned int m)
45+
{
46+
throw NotImplementedYet("sweeper");
47+
}
48+
49+
virtual Encapsulation<scalar,time>* get_state(unsigned int m) const
50+
{
51+
throw NotImplementedYet("sweeper");
52+
return NULL;
53+
}
54+
55+
virtual Encapsulation<scalar,time>* get_tau(unsigned int m) const
56+
{
57+
throw NotImplementedYet("sweeper");
58+
return NULL;
59+
}
60+
61+
virtual Encapsulation<scalar,time>* get_saved_state(unsigned int m) const
62+
{
63+
throw NotImplementedYet("sweeper");
64+
return NULL;
65+
}
66+
67+
virtual Encapsulation<scalar,time>* get_end_state()
68+
{
69+
return this->get_state(this->get_nodes().size()-1);
70+
}
71+
72+
virtual void evaluate(int m)
73+
{
74+
throw NotImplementedYet("sweeper");
75+
}
76+
77+
virtual void advance()
78+
{
79+
throw NotImplementedYet("sweeper");
80+
}
81+
82+
virtual void integrate(time dt, vector<Encapsulation<scalar,time>*> dst) const
83+
{
84+
throw NotImplementedYet("sweeper");
85+
}
86+
};
87+
88+
}
89+
90+
}
91+
92+
#endif

0 commit comments

Comments
 (0)