Skip to content

Commit

Permalink
Re #4980. Move functors into cpp for tidyness.
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellTaylor committed Mar 26, 2012
1 parent 3f3fe8b commit 4ca510a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is mainly here so you don't get a complaint when running cmake
cmake_minimum_required (VERSION 2.6)
cmake_minimum_required (VERSION 2.8)

# Add the path to our custom 'find' modules
set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../Build/CMake")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace MPIAlgorithms
<LI> OutputWorkspace - The name of the output workspace. Will only be created by the root process.</LI>
</UL>
Copyright &copy; 2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
Copyright &copy; 2011-2 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Expand Down Expand Up @@ -64,43 +64,12 @@ class GatherWorkspaces : public API::Algorithm
virtual int version() const { return (1); }
/// Algorithm's category for identification
virtual const std::string category() const { return "MPI"; }
/// Sum for boostmpi MantidVec
struct vplus
: public std::binary_function<MantidVec, MantidVec, MantidVec>
{ // functor for operator+
MantidVec operator()(const MantidVec& _Left, const MantidVec& _Right) const
{ // apply operator+ to operands
MantidVec v(_Left.size());
std::transform(_Left.begin(), _Left.end(), _Right.begin(), v.begin(), std::plus<double>());
return (v);
}

};
/// Sum for error for boostmpi MantidVec
struct eplus : public std::binary_function<MantidVec, MantidVec, MantidVec>
{ // functor for operator+
MantidVec operator()(const MantidVec& _Left, const MantidVec& _Right) const
{ // apply operator+ to operands
MantidVec v(_Left.size());
std::transform(_Left.begin(), _Left.end(), _Right.begin(), v.begin(), SumGaussError<double>());
return (v);
}
};


private:
void init();
void exec();
//! Functor used for computing the sum of the square values of a vector, using the accumulate algorithm
template <class T> struct SumGaussError: public std::binary_function<T,T,T>
{
SumGaussError(){}
/// Sums the arguments in quadrature
inline T operator()(const T& l, const T& r) const
{
return std::sqrt(l*l+r*r);
}
};


void execEvent();
DataObjects::EventWorkspace_const_sptr eventW;
Expand Down
41 changes: 17 additions & 24 deletions Code/Mantid/Framework/MPIAlgorithms/scripts/NOMAD_mpi_example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from MantidFramework import *
mtd.initialise()

back = 'NOM_1000_event.nxs'#'/SNS/NOM/2011_2_1B_SCI/1/1000/preNeXus/NOM_1000_neutron_event.dat' # 1GB
van = 'NOM_998_event.nxs'#Cheat for now (real file is huge) #van = '/SNS/users/pf9/NOM_989_event.nxs'#'/SNS/NOM/2011_2_1B_SCI/1/989/preNeXus/NOM_989_neutron_event.dat' # 73GB
#back = 'NOM_1000_event.nxs'#'/SNS/NOM/2011_2_1B_SCI/1/1000/preNeXus/
#van = 'NOM_1000_neutron_event.dat' # 1GB
#van = 'NOM_989_event.nxs'
van = '/SNS/NOM/2011_2_1B_SCI/1/989/preNeXus/NOM_989_neutron_event.dat'
#van = 'NOM_989_neutron_event.dat' # 73GB
#dia = '/SNS/users/pf9/NOM_990_event.nxs'#'/SNS/NOM/2011_2_1B_SCI/1/990/preNeXus/NOM_990_neutron_event.dat' # 65GB
sio2 = 'NOM_998_event.nxs'#'/NOM-DAS-FS/2011_2_1B_SCI/NOM_998/NOM_998_neutron_event.dat' # 5.6GB
#calib = 'NOM_calibrate_d739_2011_03_29.cal'
Expand All @@ -26,16 +29,11 @@ def focus(filename):
wksp = os.path.split(filename)[-1]
wksp = '_'.join(wksp.split('_')[0:2]) + "-" + str(1+comm.rank)

# Have a guard so that all processes don't hit the same file at the same time.
# All processes except the root wait for a signal that the (rank-1) process has finished.
if comm.rank > 0:
comm.recv(comm.rank-1)
# Need SingleBankPixelsOnly switched off or DiffractionFocussing fails
LoadEventNexus(Filename=filename, OutputWorkspace=wksp,
BankName="bank"+str(1+comm.rank),
SingleBankPixelsOnly=False, CompressTolerance=.01)
if comm.rank < comm.size-1:
comm.isend(comm.rank+1)
# LoadEventNexus(Filename=filename, OutputWorkspace=wksp,
# BankName="bank"+str(1+comm.rank),
# SingleBankPixelsOnly=False, CompressTolerance=.01)
LoadEventPreNexus(EventFilename=filename, OutputWorkspace=wksp, ChunkNumber=comm.rank+1, TotalChunks=comm.size, UseParallelProcessing="Serial")
# TODO: Check for zero events here?
NormaliseByCurrent(InputWorkspace=wksp, OutputWorkspace=wksp)
AlignDetectors(InputWorkspace=wksp, OutputWorkspace=wksp,
Expand All @@ -49,23 +47,18 @@ def focus(filename):


CreateGroupingWorkspace(InstrumentName='NOMAD', GroupNames='NOMAD', OutputWorkspace="grouping")
#CreateGroupingWorkspace(InstrumentName='NOMAD', OldCalFilename=calib, OutputWorkspace="grouping")
print back
back = focus(back)
print back
print sio2
sio2 = focus(sio2)
print sio2
print van
##CreateGroupingWorkspace(InstrumentName='NOMAD', OldCalFilename=calib, OutputWorkspace="grouping")

#back = focus(back)
#sio2 = focus(sio2)
van = focus(van)
print van

sio2 -= back
van -= back
sio2 /= van
#sio2 -= back
#van -= back
#sio2 /= van

done = "Done " + str(1+comm.rank) + "!"
GatherWorkspaces(InputWorkspace=back, OutputWorkspace="nomad")
GatherWorkspaces(InputWorkspace=van, OutputWorkspace="nomad")
if comm.rank == 0:
SumSpectra("nomad","nomad")
SaveNexus(InputWorkspace="nomad",Filename="NOMAD.nxs")
Expand Down
37 changes: 37 additions & 0 deletions Code/Mantid/Framework/MPIAlgorithms/src/GatherWorkspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gathers workspaces from all processors of MPI run. Add or append workspaces to

namespace mpi = boost::mpi;


namespace Mantid
{
namespace MPIAlgorithms
Expand All @@ -28,6 +29,42 @@ using namespace Kernel;
using namespace API;
using namespace DataObjects;

// Anonymous namespace for locally-used functors
namespace {
/// Sum for boostmpi MantidVec
struct vplus : public std::binary_function<MantidVec, MantidVec, MantidVec>
{ // functor for operator+
MantidVec operator()(const MantidVec& _Left, const MantidVec& _Right) const
{ // apply operator+ to operands
MantidVec v(_Left.size());
std::transform(_Left.begin(), _Left.end(), _Right.begin(), v.begin(), std::plus<double>());
return (v);
}
};

/// Functor used for computing the sum of the square values of a vector
template <class T> struct SumGaussError: public std::binary_function<T,T,T>
{
SumGaussError(){}
/// Sums the arguments in quadrature
inline T operator()(const T& l, const T& r) const
{
return std::sqrt(l*l+r*r);
}
};

/// Sum for error for boostmpi MantidVec
struct eplus : public std::binary_function<MantidVec, MantidVec, MantidVec>
{ // functor for operator+
MantidVec operator()(const MantidVec& _Left, const MantidVec& _Right) const
{ // apply operator+ to operands
MantidVec v(_Left.size());
std::transform(_Left.begin(), _Left.end(), _Right.begin(), v.begin(), SumGaussError<double>());
return (v);
}
};
}

// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(GatherWorkspaces)

Expand Down

0 comments on commit 4ca510a

Please sign in to comment.