1 #ifndef __GRIDCONVERSION_TEST_H__
13 #define __GRIDCONVERSION_TEST_H__
14 #ifdef _GRIDCONVERSION_PARALLEL_
23 namespace GridConversion {
28 namespace TestFixture {
34 double F1(
double x) {
return (2.0*x); };
40 double F2(
double x) {
return (3.0*x*x); };
70 template<
typename ResultsType>
107 for(
int i = 10;
i < 10000000;
i*=10)
N.push_back(
i);
114 double F1(
double x) {
return (2.0*x); };
120 double F2(
double x) {
return (3.0*x*x); };
136 result.UpdateResult(
"ExampleFunction:Works",
138 result.UpdateResult(
"ExampleFunction:Fails",
156 std::ostringstream Ostr;
157 std::vector<double> E;
158 size_t n = 2*
N.size();
160 for(std::vector<int>::iterator
i =
N.begin();
i !=
N.end();
i++){
167 E.push_back(std::fabs(Ii-1.0));
169 bool order2 = (E[0] < 1e-14);
170 for(std::vector<int>::iterator
i =
N.begin();
i !=
N.end();
i++){
177 E.push_back(std::fabs(Ii-1.0));
179 result.UpdateResult(
"TrapezoidQuadrature:Runs",runs);
180 result.UpdateResult(
"TrapezoidQuadrature:Accurate",E[n-1] < 1e-12);
181 for(
int i =
N.size();
i < n - 1;
i++){
182 double e = E[
i+1]/E[
i];
183 double n1 =
static_cast<double>(
N[
i-
N.size()])/static_cast<double>(
N[(
i-
N.size())+1]);
191 result.UpdateResult(
"TrapezoidQuadrature:Order2",order2);
208 std::ostringstream Ostr;
209 std::vector<double> Ibar;
210 std::vector<double> E;
211 size_t n = 2*
N.size();
214 for(std::vector<int>::iterator
i =
N.begin();
i !=
N.end();
i++){
222 E.push_back(std::fabs(Ii-1.0));
224 order2 = (E[0] < 1e-14);
225 for(std::vector<int>::iterator
i =
N.begin();
i !=
N.end();
i++){
233 E.push_back(std::fabs(Ii-1.0));
235 result.UpdateResult(
"MidPointQuadrature:Runs",runs);
236 result.UpdateResult(
"MidPointQuadrature:Accurate",E[n-1] < 1e-12);
237 for(
int i =
N.size();
i < n - 1;
i++){
238 double e = E[
i+1]/E[
i];
239 double n1 =
static_cast<double>(
N[
i-
N.size()])/static_cast<double>(
N[(
i-
N.size())+1]);
247 result.UpdateResult(
"MidPointQuadrature:Order2",order2);
269 virtual void RunTest(
const std::string &name,ResultsType &result)
272 if(name ==
"ExampleFunction")
274 else if(name ==
"TrapezoidQuadrature")
276 else if(name ==
"MidPointQuadrature")
287 virtual void ProcessTests(std::list<std::string> &test_names,ResultsType &result){
289 std::list<std::string>::iterator tni = test_names.begin();
290 while(tni != test_names.end())
298 #ifdef _GRIDCONVERSION_PARALLEL_
299 template<
typename CommType,
typename ResultsType>
310 class ParallelTestingObject : TestingObject<ResultsType>
327 ParallelTestingObject(
CommType &incomm) :
328 TestingObject<ResultsType>(), _communicator(incomm) {};
334 virtual void Epilogue() {};
343 virtual void Prologue(){
344 for(
int i = _communicator.Size();
i <= 1000000;
i*=2) N.push_back(
i);
363 virtual void Test__ParallelTrapezoidQuadrature(ResultsType &result) {
364 std::ostringstream Ostr;
365 int fixed_n = 1000000;
366 int rank = _communicator.Rank();
367 int nproc = _communicator.Size();
370 bool accurate =
true;
373 std::vector<double> E;
374 std::vector<double> times;
375 for(
int i = 1;
i <= nproc;
i*=nproc){
377 int color = (rank <
i);
378 _communicator.Split(color,rank,subcomm);
379 int nproc_color = subcomm.Size();
380 double time0 = IRAD::Profiler::Time();
383 for(
int j = 0;
j < 200;
j++){
396 subcomm.AllReduce(Ii, Itot,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP);
398 error =
std::abs(Itot - (200*nproc_color));
399 accurate = (error < 1e-14);
403 times.push_back(IRAD::Profiler::Time() - time0);
408 double dt = *times.rbegin() - *times.begin();
409 double percent_change = dt/(*times.begin());
410 scales = (percent_change < (nproc*.005));
412 result.UpdateResult(
"ParallelTrapezoidQuadrature:Runs",runs);
413 result.UpdateResult(
"ParallelTrapezoidQuadrature:Accurate",accurate);
415 result.UpdateResult(
"ParallelTrapezoidQuadrature:WeakScaling",scales);
418 for(
int i = 1;
i <= nproc;
i*=nproc){
420 int color = (rank <
i);
421 _communicator.Split(color,rank,subcomm);
422 int nproc_color = subcomm.Size();
423 double time0 = IRAD::Profiler::Time();
425 int npart = *N.rbegin()/nproc_color;
427 for(
int j = 0;
j < 200;
j++){
440 subcomm.AllReduce(Ii, Itot,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP);
442 error =
std::abs(Itot - (200*nproc_color));
443 accurate = (error < 1e-14);
447 times.push_back(IRAD::Profiler::Time() - time0);
450 double n_t = (*times.begin())/(*times.rbegin());
451 double n_p = n_t - nproc;
453 scales = (n_p < 2e-1);
455 result.UpdateResult(
"ParallelTrapezoidQuadrateure:StrongScaling",scales);
457 for(
int i = nproc;
i <= 1000000;
i*=10){
464 _communicator.SetExit(1);
466 if(_communicator.Check())
470 _communicator.AllReduce(Ii, Itot,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP);
477 int esize = E.size();
478 for(
int i = 0;
i < esize-1;
i++){
479 double e = E[
i+1]/E[
i];
488 result.UpdateResult(
"ParallelTrapezoidQuadrature:Order2",order2);
508 virtual void Test__ParallelMidPointQuadrature(ResultsType &result) {
509 std::ostringstream Ostr;
510 int fixed_n = 1000000;
511 int rank = _communicator.Rank();
512 int nproc = _communicator.Size();
515 bool accurate =
true;
518 std::vector<double> E;
519 std::vector<double> times;
520 for(
int i = 1;
i <= nproc;
i*=nproc){
522 int color = (rank <
i);
523 _communicator.Split(color,rank,subcomm);
524 int nproc_color = subcomm.Size();
525 double time0 = IRAD::Profiler::Time();
528 for(
int j = 0;
j < 200;
j++){
541 subcomm.AllReduce(Ii, Itot,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP);
543 error =
std::abs(Itot - (200*nproc_color));
544 accurate = (error < 1e-14);
548 times.push_back(IRAD::Profiler::Time() - time0);
553 double dt = *times.rbegin() - *times.begin();
554 double percent_change = dt/(*times.begin());
555 scales = (percent_change < (nproc*.005));
564 result.UpdateResult(
"ParallelMidPointQuadrature:Runs",runs);
565 result.UpdateResult(
"ParallelMidPointQuadrature:Accurate",accurate);
567 result.UpdateResult(
"ParallelMidPointQuadrature:WeakScaling",scales);
570 for(
int i = 1;
i <= nproc;
i*=nproc){
572 int color = (rank <
i);
573 _communicator.Split(color,rank,subcomm);
574 int nproc_color = subcomm.Size();
575 double time0 = IRAD::Profiler::Time();
577 int npart = *N.rbegin()/nproc_color;
579 for(
int j = 0;
j < 200;
j++){
592 subcomm.AllReduce(Ii, Itot,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP);
594 error =
std::abs(Itot - (200*nproc_color));
595 accurate = (error < 1e-14);
599 times.push_back(IRAD::Profiler::Time() - time0);
602 double n_t = (*times.begin())/(*times.rbegin());
603 double n_p = n_t - nproc;
605 scales = (n_p < 2e-1);
607 result.UpdateResult(
"ParallelMidPointQuadrateure:StrongScaling",scales);
609 for(
int i = nproc;
i <= 1000000;
i*=10){
616 _communicator.SetExit(1);
618 if(_communicator.Check())
622 _communicator.AllReduce(Ii, Itot,IRAD::Comm::DTDOUBLE, IRAD::Comm::SUMOP);
629 int esize = E.size();
630 for(
int i = 0;
i < esize-1;
i++){
631 double e = E[
i+1]/E[
i];
640 result.UpdateResult(
"ParallelMidPointQuadrature:Order2",order2);
648 virtual void Process(ResultsType &result){
650 Test__ParallelTrapezoidQuadrature(result);
651 Test__ParallelMidPointQuadrature(result);
661 virtual void RunTest(
const std::string &name,ResultsType &result)
663 if(name ==
"ParallelTrapezoidQuadrature")
664 Test__ParallelTrapezoidQuadrature(result);
665 if(name ==
"ParallelMidPointQuadrature")
666 Test__ParallelMidPointQuadrature(result);
675 virtual void ProcessTests(std::list<std::string> &test_names,ResultsType &result){
677 std::list<std::string>::iterator tni = test_names.begin();
678 while(tni != test_names.end())
679 RunTest(*tni++,result);
double TrapezoidQuadrature(double(*f)(double), double x0, double xn, int n)
Integrates f with composite trapezoid rule.
std::vector< int > N
A set of values for testing quadrature methods.
virtual void Prologue()
Sets up the data fixtures for the tests.
std::string ExampleFunction(const std::string &instring)
Example function for GridConversion (this is a brief description).
virtual void ProcessTests(std::list< std::string > &test_names, ResultsType &result)
Runs a list of tests specified by name.
std::string ExampleTestFixture
A sample string test fixture.
CImg< _cimg_Tfloat > log(const CImg< T > &instance)
TestingObject()
Default constructor.
IRAD::Util::TestingObject< ResultsType > TestingObjectBaseType
virtual void RunTest(const std::string &name, ResultsType &result)
Runs a test specified by name.
double F1(double x)
Simple test function fixture returns .
double F2(double x)
Simple test function fixture returns .
double F1(double x)
Simple test function fixture returns .
IRAD::Util::TestResults TestResults
Project-specific test results type.
IRAD::Comm::CommunicatorObject CommType
Convenience typedef for CommunicatorObject.
double MidPointQuadrature(double(*f)(double), double x0, double xn, int n)
Integrates f with composite midpoint rule.
virtual void Process(ResultsType &result)
Runs all tests implemented by the GridConversion::TestingObject.
double F2(double x)
Simple test function fixture returns .
MPI_Comm GetCommunicator()
virtual void Epilogue()
Tears down the testing fixtures if needed.
virtual void Test__MidPointQuadrature(ResultsType &result)
Test for GridConversion::MidPointQuadrature.
virtual void Test__ExampleFunction(ResultsType &result)
Test for GridConversion::ExampleFunction.
virtual void Test__TrapezoidQuadrature(ResultsType &result)
Test for GridConversion::TrapezoidQuadrature.
Project-specific testing object.