Commit 2b5de25a authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

moved tests to kernel

parent 7fcaaa5e
Pipeline #122406 failed with stages
in 5 minutes and 33 seconds
......@@ -25,10 +25,4 @@ add_mpp_test(pdesolver/TestPDESolver PDESOLVER)
# ------- Integration Tests -------
add_executable(TestMain TestMain.cpp)
target_link_libraries(TestMain MONTECARLO LIB_TEST)
add_executable(TestParallelization TestParallelization.cpp)
target_link_libraries(TestParallelization LIB_TEST)
add_executable(TestExchangeBuffer TestExchangeBuffer.cpp)
target_link_libraries(TestExchangeBuffer LIB_TEST)
target_link_libraries(TestMain MONTECARLO LIB_TEST)
\ No newline at end of file
#include "parallel/Parallel.hpp"
#include "TestEnvironment.hpp"
class TestExchangeBuffer : public Test {
public:
ExchangeBuffer exBuffer;
void SetUp() {}
void TearDown() {
exBuffer.Destruct();
}
};
TEST_F(TestExchangeBuffer, TestIsInitialized) {
EXPECT_FALSE(exBuffer.Initialized());
}
TEST_F(TestExchangeBuffer, ReceiveSize) {
for (int p = 0; p < PPM->Size(); p++)
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
TEST_F(TestExchangeBuffer, TestSendCstr) {
std::string message = "Test";
const char *cline = message.c_str();
for (int i = 0; i < message.length(); ++i)
exBuffer.Send(0) << cline[i];
exBuffer.Communicate();
for (int p = 0; p < PPM->Size(); p++) {
if (PPM->Proc() == 0)
EXPECT_EQ(exBuffer.ReceiveSize(p), 4);
else
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
}
TEST_F(TestExchangeBuffer, TestSendStr) {
std::string message = "Test";
for (int i = 0; i < message.length(); ++i)
exBuffer.Send(0) << message[i];
exBuffer.Communicate();
for (int p = 0; p < PPM->Size(); p++) {
if (PPM->Proc() == 0)
EXPECT_EQ(exBuffer.ReceiveSize(p), 4);
else
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
// std::string messageR = "";
//
// for (int p = 0; p < PPM->Size(); p++) {
// if (PPM->Proc() == 0) {
// for (int i = 0; i < message.length(); ++i)
// exBuffer.Receive(p) >> messageR[i];
// std::cout << messageR;
//// EXPECT_EQ(messageR, message);
// }
// else {
// exBuffer.Receive(p) >> messageR;
// std::cout << messageR;
//// EXPECT_EQ(messageR, "____");
// }
// }
}
TEST_F(TestExchangeBuffer, TestInt) {
ExchangeBuffer exBuffer;
int message = 0;
exBuffer.Send(0) << message;
exBuffer.Communicate();
for (int p = 0; p < PPM->Size(); p++) {
if (PPM->Proc() == 0)
EXPECT_EQ(exBuffer.ReceiveSize(p), 4);
else
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
}
TEST_F(TestExchangeBuffer, TestDouble) {
double message = 0.0;
exBuffer.Send(0) << message;
exBuffer.Communicate();
for (int p = 0; p < PPM->Size(); p++) {
if (PPM->Proc() == 0)
EXPECT_EQ(exBuffer.ReceiveSize(p), 8);
else
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
}
TEST_F(TestExchangeBuffer, TestShort) {
short message = 0.0;
exBuffer.Send(0) << message;
exBuffer.Communicate();
for (int p = 0; p < PPM->Size(); p++) {
if (PPM->Proc() == 0)
EXPECT_EQ(exBuffer.ReceiveSize(p), 2);
else
EXPECT_EQ(exBuffer.ReceiveSize(p), 0);
}
}
/*
* Todo
* finish at least some tests on exchange buffer
* extend with new PPM
* write some tests with split
* move tests to kernel
*
*/
//TEST(TestExchangeBuffer, Duff) {
// ExchangeBuffer exBuffer;
// const char *mSendA = "A";
// const char *mSendB = "B";
// const char *mSendC = "C";
// const char *mSendD = "D";
//
//
// /*
// * p = 0: ABC
// * p = 1: AB
// * p = 2: A
// * p = 3: D
// */
//
// int q = 0;
//// if (PPM->Proc() == q) {
//// exBuffer.Send(0) << mSendA << mSendB;
// exBuffer.Send(1) << "proc 1 send: " << mSendA;
//// exBuffer.Send(2) << mSendA;
//// exBuffer.Send(1) << mSendB;
//// exBuffer.Send(0) << mSendC;
//// exBuffer.Send(3) << mSendD;
//// }
//
// exBuffer.Communicate();
//
// char *mRecv;
// char *procID;
// std::string mRecvStr = "";
//
// int p = 0;
// for (p = 0; p < PPM->Size(); p++) {
// if (PPM->Proc() == p) {
// while (exBuffer.Receive(p).size() < exBuffer.ReceiveSize((p))) {
// exBuffer.Receive(p) >> procID;
//// exBuffer.Receive(p) >> mRecv;
//
// mRecvStr += procID;
// mRecvStr += mRecv;
// std::cout << mRecvStr << endl;
// }
// }
// }
//}
int main(int argc, char **argv) {
return MppTest(
MppTestBuilder(argc, argv).
WithPPM().
WithScreenLogging().
WithParallelListeners()
).RUN_ALL_MPP_TESTS();
}
\ No newline at end of file
#include "parallel/Parallel.hpp"
#include "TestEnvironment.hpp"
TEST(TestParallel, TestIsInitialized) {
EXPECT_TRUE(PPM->IsInitialized());
}
TEST(TestParallel, TestBroadcastDouble) {
double a;
if (PPM->Master()) PPM->Broadcast(1.0);
if (!PPM->Master()) {
PPM->Broadcast(a);
EXPECT_DOUBLE_EQ(a, 1.0);
}
}
TEST(TestParallel, TestBroadcastInt) {
int a;
if (PPM->Master()) PPM->Broadcast(1);
if (!PPM->Master()) {
PPM->Broadcast(a);
EXPECT_EQ(a, 1);
}
}
struct BroadcastStruct {
int integer;
BroadcastStruct(int _integer) : integer(_integer) {}
bool operator==(const BroadcastStruct other) {
return (other.integer == integer);
}
};
TEST(TestParallel, TestBroadcast) {
const BroadcastStruct structToBroadcast(0);
BroadcastStruct structFromBroadcast(1);
if (PPM->Master())
PPM->Broadcast(structToBroadcast);
if (!PPM->Master()) {
PPM->Broadcast(structFromBroadcast);
EXPECT_TRUE(structFromBroadcast == structToBroadcast);
}
}
TEST(TestParallel, TestProc) {
if (PPM->Master()) EXPECT_EQ(PPM->Proc(), 0);
if (!PPM->Master()) EXPECT_NE(PPM->Proc(), 0);
}
TEST(TestParallel, TestSize) {
int testSize;
MPI_Comm_size(MPI_COMM_WORLD, &testSize);
EXPECT_EQ(PPM->Size(), testSize);
}
TEST(TestParallel, TestIntegerSum) {
int a = 1;
EXPECT_EQ(PPM->Sum(a), PPM->Size());
}
TEST(TestParallel, TestDoubleSum) {
double a = 1.0;
EXPECT_DOUBLE_EQ(PPM->Sum(a), (double) PPM->Size());
}
TEST(TestParallel, TestSizeTypeSum) {
size_t a = sizeof(int);
EXPECT_EQ(PPM->Sum(a), (size_t) a * PPM->Size());
}
TEST(TestParallel, TestComplexSum) {
std::complex<double> a{1.0, 1.0};
std::complex<double> b{std::real(a) * PPM->Size(), std::imag(a) * PPM->Size()};
EXPECT_EQ(PPM->Sum(a), b);
}
TEST(TestParallel, TestIntegerMin) {
int a;
if (PPM->Master()) a = 1;
if (!PPM->Master()) a = 0;
EXPECT_EQ(PPM->Min(a), 0);
if (PPM->Master()) a = 0;
if (!PPM->Master()) a = 1;
EXPECT_EQ(PPM->Min(a), 0);
}
TEST(TestParallel, TestDoubleMin) {
double a;
if (PPM->Master()) a = 1.0;
if (!PPM->Master()) a = 0.0;
EXPECT_DOUBLE_EQ(PPM->Min(a), 0.0);
if (PPM->Master()) a = 0.0;
if (!PPM->Master()) a = 1.0;
EXPECT_DOUBLE_EQ(PPM->Min(a), 0.0);
}
TEST(TestParallel, TestUnsignedIntegerMin) {
long unsigned int a;
if (PPM->Master()) a = 1;
if (!PPM->Master()) a = 0;
EXPECT_EQ(PPM->Min(a), 0);
if (PPM->Master()) a = 0;
if (!PPM->Master()) a = 1;
EXPECT_EQ(PPM->Min(a), 0);
}
TEST(TestParallel, TestIntegerMax) {
int a;
if (PPM->Master()) a = 1;
if (!PPM->Master()) a = 0;
EXPECT_EQ(PPM->Max(a), 1);
if (PPM->Master()) a = 0;
if (!PPM->Master()) a = 1;
EXPECT_EQ(PPM->Max(a), 1);
}
TEST(TestParallel, TestDoubleMax) {
double a;
if (PPM->Master()) a = 1.0;
if (!PPM->Master()) a = 0.0;
EXPECT_DOUBLE_EQ(PPM->Max(a), 1.0);
if (PPM->Master()) a = 0.0;
if (!PPM->Master()) a = 1.0;
EXPECT_DOUBLE_EQ(PPM->Max(a), 1.0);
}
TEST(TestParallel, TestUnsignedIntMax) {
long unsigned int a;
if (PPM->Master()) a = 1;
if (!PPM->Master()) a = 0;
EXPECT_EQ(PPM->Max(a), 1);
if (PPM->Master()) a = 0;
if (!PPM->Master()) a = 1;
EXPECT_EQ(PPM->Max(a), 1);
}
TEST(TestParallel, TestSplit) {
PPM->SplitCommunicators();
EXPECT_EQ(PPM->Size(1), PPM->Size(0) / 2);
EXPECT_EQ(PPM->Proc(1) + PPM->Color(1) * PPM->Size(1), PPM->Proc(0));
}
TEST(TestParallel, TestDoubleSplit) {
PPM->SplitCommunicators();
PPM->SplitCommunicators();
EXPECT_EQ(PPM->Size(2), PPM->Size(0) / 4);
EXPECT_EQ(PPM->Size(2), PPM->Size(1) / 2);
EXPECT_EQ(PPM->Proc(2) + PPM->Color(2) * PPM->Size(2), PPM->Proc(1));
}
TEST(TestParallel, TestIntegerMinSplit) {
int a;
if (PPM->Master()) a = 1;
if (!PPM->Master()) a = 0;
EXPECT_EQ(PPM->Min(a), 0);
if (PPM->Master()) a = 0;
if (!PPM->Master()) a = 1;
EXPECT_EQ(PPM->Min(a), 0);
PPM->SplitCommunicators();
if (PPM->Master(1)) a = 2;
if (!PPM->Master(1)) a = 1;
EXPECT_EQ(PPM->Min(a), 1);
if (PPM->Master(1)) a = 1;
if (!PPM->Master(1)) a = 2;
EXPECT_EQ(PPM->Min(a), 1);
}
/*
* Todo
* more tests after splitting
* move test to kernel
* create job / maybe even test pattern
*
*/
int main(int argc, char **argv) {
return MppTest(
MppTestBuilder(argc, argv).
WithPPM().
WithScreenLogging().
WithParallelListeners()
).RUN_ALL_MPP_TESTS();
}
\ No newline at end of file
#ifndef TESTPARALLELIZATION_HPP
#define TESTPARALLELIZATION_HPP
#include <map>
#include <string>
typedef std::map<std::string, std::string> ConfigMap;
const ConfigMap defaultEllipticConfigMap = {
// ----- Problem Settings -----
{"Experiment", "MLMCExperiment"},
{"Problem", "StochasticLaplace1D"},
{"Model", "LagrangeElliptic"},
{"Functional", "L2"},
{"degree", "1"},
{"plevel", "2"},
// ----- Multilevel Monte Carlo -----
{"maxLevel", "7"},
{"epsilon", "0.01"},
{"mcOnly", "false"},
{"uniformSampleAmount", "100"},
{"initLevels", "[3, 4, 5]"},
{"initSampleAmount", "[12, 6, 3]"},
// ----- Stochastic Field -----
{"StochasticField", "LogNormal"},
{"mean", "1.0"}, // Todo should be 0.0
{"sigma", "1.0"},
{"norm_p", "2"},
{"lambda", "[0.15, 0.15]"},
{"smoothing", "1.8"},
{"evtol", "1e-10"},
// ----- Solver -----
{"LinearReduction", "1e-12"},
{"LinearEpsilon", "1e-10"},
{"LinearSteps", "3000"},
{"NewtonSteps", "1"},
{"NewtonLineSearchSteps", "0"},
// ----- Plotting -----
{"GeneratorPlotting", "0"},
{"MCPlotting", "0"},
// ----- Verbose ----- //
{"MCVerbose", "1"},
{"MLMCVerbose", "1"},
{"MainVerbose", "1"},
{"MeshVerbose", "1"},
{"ConfigVerbose", "0"},
{"LinearVerbose", "-1"},
{"NewtonVerbose", "-1"},
{"PDESolverVerbose", "1"},
{"GeneratorVerbose", "0"},
// ----- Logging -----
{"TimeLevel", "-1"},
{"MuteLevel", "-1"},
{"DebugLevel", "-1"},
};
#endif //TESTPARALLELIZATION_HPP
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment