Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/9022_serialWorkspaceComp…
Browse files Browse the repository at this point in the history
…arison'
  • Loading branch information
martyngigg committed Apr 8, 2014
2 parents 602d6bc + 757b060 commit b0d8ba3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 26 deletions.
Expand Up @@ -112,6 +112,9 @@ class DLLExport CheckWorkspacesMatch : public API::Algorithm
std::string result; ///< the result string

API::Progress * prog;
/// Variable states if one wants to compare workspaces in parallell. This usully true but if one wants to look at the comparison logs, parallell comparison make things complicated as
/// logs from different threads are mixed together. In this case, it is better not to do parallell comparison.
bool m_ParallelComparison;
};

} // namespace Algorithms
Expand Down
70 changes: 44 additions & 26 deletions Code/Mantid/Framework/Algorithms/src/CheckWorkspacesMatch.cpp
Expand Up @@ -24,10 +24,37 @@ In the case of [[EventWorkspace]]s, they are checked to hold identical event lis
#include "MantidGeometry/MDGeometry/IMDDimension.h"
#include <sstream>

//
namespace Mantid
{
namespace Algorithms
{
namespace
{
/** Function which calculates relative error between two values and analyses if this error is within the limits
* requested. When the absolute value of the difference is smaller then the value of the error requested,
* absolute error is used instead of relative error.
@param x1 -- first value to check difference
@param x2 -- second value to check difference
@param errorVal -- the value of the error, to check against. Should be large then 0
@returns true if error or false if the value is within the limits requested
*/
inline bool relErr(const double &x1,const double &x2,const double &errorVal)
{

double num= std::fabs(x1-x2);
// how to treat x1<0 and x2 > 0 ? probably this way
double den=0.5*(std::fabs(x1)+std::fabs(x2));
if (den<errorVal)
return (num>errorVal);

return (num/den>errorVal);

}

}

// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(CheckWorkspacesMatch)
Expand All @@ -40,7 +67,7 @@ void CheckWorkspacesMatch::initDocs()
}

/// Constructor
CheckWorkspacesMatch::CheckWorkspacesMatch() : API::Algorithm(), result(), prog(NULL)
CheckWorkspacesMatch::CheckWorkspacesMatch() : API::Algorithm(), result(), prog(NULL),m_ParallelComparison(true)
{}

/// Virtual destructor
Expand Down Expand Up @@ -181,6 +208,10 @@ void CheckWorkspacesMatch::exec()
{
result.clear();

if (g_log.is(Logger::Priority::PRIO_DEBUG) )
m_ParallelComparison = false;


this->doComparison();

if ( result != "")
Expand Down Expand Up @@ -377,8 +408,9 @@ bool CheckWorkspacesMatch::compareEventWorkspaces(DataObjects::EventWorkspace_co
size_t numUnequalBothEvents = 0;

std::vector<int> vec_mismatchedwsindex;

PARALLEL_FOR2(ews1, ews2)
bool condition = m_ParallelComparison && ews1->threadSafe() && ews2->threadSafe() ;
PARALLEL_FOR_IF(condition)
for (int i=0; i<static_cast<int>(ews1->getNumberHistograms()); ++i)
for (int i=0; i<static_cast<int>(ews1->getNumberHistograms()); i++)
{
PARALLEL_START_INTERUPT_REGION
Expand Down Expand Up @@ -420,15 +452,15 @@ bool CheckWorkspacesMatch::compareEventWorkspaces(DataObjects::EventWorkspace_co
{
// 2 spectra have different number of events
++ numUnequalNumEventsSpectra;
}
}
else
{
// 2 spectra have some events different to each other
numUnequalEvents += static_cast<size_t>(tempNumUnequal);
numUnequalTOFEvents += tempNumTof;
numUnequalPulseEvents += tempNumPulses;
numUnequalBothEvents += tempNumBoth;
}
}

vec_mismatchedwsindex.push_back(i);
} // Parallel critical region
Expand Down Expand Up @@ -514,8 +546,9 @@ bool CheckWorkspacesMatch::checkData(API::MatrixWorkspace_const_sptr ws1, API::M
bool resultBool = true;

// Now check the data itself
PARALLEL_FOR2(ws1, ws2)
for ( int i = 0; i < static_cast<int>(numHists); ++i )
bool condition = m_ParallelComparison && ws1->threadSafe() && ws2->threadSafe() ;
PARALLEL_FOR_IF(condition)
for ( long i = 0; i < static_cast<long>(numHists); ++i )
{
PARALLEL_START_INTERUPT_REGION
prog->report("Histograms");
Expand All @@ -535,27 +568,10 @@ bool CheckWorkspacesMatch::checkData(API::MatrixWorkspace_const_sptr ws1, API::M
bool err;
if (RelErr)
{
double s1=0.5*(X1[j]+X2[j]);
if (s1>tolerance)
err = (std::fabs(X1[j] - X2[j]) > tolerance*s1);
else
err = (std::fabs(X1[j] - X2[j]) > tolerance);

double s2=0.5*(Y1[j]+Y2[j]);
if (s2>tolerance)
err = ((std::fabs(Y1[j] - Y2[j]) > tolerance*s2)||err);
else
err = ((std::fabs(Y1[j] - Y2[j]) > tolerance)||err);


double s3=0.5*(E1[j]+E2[j]);
if (s3>tolerance)
err = ((std::fabs(E1[j] - E2[j]) > tolerance*s3)||err);
else
err = ((std::fabs(E1[j] - E2[j]) > tolerance)||err);
err = (relErr(X1[j],X2[j],tolerance) || relErr(Y1[j],Y2[j],tolerance) || relErr(E1[j],E2[j],tolerance));
}
else
err = (std::fabs(X1[j] - X2[j]) > tolerance || std::fabs(Y1[j] - Y2[j]) > tolerance
err = (std::fabs(X1[j] - X2[j]) > tolerance || std::fabs(Y1[j] - Y2[j]) > tolerance
|| std::fabs(E1[j] - E2[j]) > tolerance);

if (err)
Expand All @@ -573,6 +589,8 @@ bool CheckWorkspacesMatch::checkData(API::MatrixWorkspace_const_sptr ws1, API::M
// Extra one for histogram data
if ( histogram && std::fabs(X1.back() - X2.back()) > tolerance )
{
g_log.debug() << " Data ranges mismatch for spectra N: (" << i << ")\n";
g_log.debug() << " Last bin ranges (X1_end vs X2_end) = (" << X1.back() << "," <<X2.back() << ")\n";
PARALLEL_CRITICAL(resultBool)
resultBool = false;
}
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Kernel/src/Logger.cpp
Expand Up @@ -215,6 +215,7 @@ namespace Kernel
}
}


int Logger::getLevel() const
{
return m_log->getLevel();
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Kernel/test/LoggerTest.h
Expand Up @@ -79,6 +79,7 @@ class LoggerTest : public CxxTest::TestSuite
log.information() << "Information Message" << std::endl;
}


//---------------------------------------------------------------------------
/** Log very quickly from a lot of OpenMP threads*/
void test_OpenMP_ParallelLogging()
Expand Down

0 comments on commit b0d8ba3

Please sign in to comment.