25 #include <queso/VectorFunctionSynchronizer.h> 
   26 #include <queso/GslVector.h> 
   27 #include <queso/GslMatrix.h> 
   32 template <
class P_V, 
class P_M, 
class Q_V, 
class Q_M>
 
   38   m_env           (inputFunction.domainSet().env()),
 
   39   m_vectorFunction(inputFunction),
 
   46 template <
class P_V, 
class P_M, 
class Q_V, 
class Q_M>
 
   51 template<
class P_V, 
class P_M, 
class Q_V, 
class Q_M>
 
   55   return m_vectorFunction.domainSet();
 
   59 template <
class P_V, 
class P_M, 
class Q_V, 
class Q_M>
 
   63   const P_V*                    vecDirection,
 
   69   if ((m_env.numSubEnvironments() < (
unsigned int) m_env.fullComm().NumProc()) &&
 
   70       (m_auxPVec.numOfProcsForStorage() == 1                                 ) &&
 
   71       (m_auxQVec.numOfProcsForStorage() == 1                                 )) {
 
   72     bool stayInRoutine = 
true;
 
   74       const P_V*                    internalValues    = NULL;
 
   75       const P_V*                    internalDirection = NULL;
 
   76             Q_V*                    internalImageVec  = NULL;
 
   90       std::vector<char> bufferChar(6,
'0');
 
   92       if (m_env.subRank() == 0) {
 
   95                             "VectorFunctionSynchronizer<P_V,P_M,Q_V,Q_M>::callFunction()",
 
   96                             "imageVector should not be NULL");
 
   97         internalValues    = vecValues;
 
   98         internalDirection = vecDirection;
 
   99         internalImageVec  = imageVector;
 
  100         internalGrads     = gradVectors;
 
  101         internalHessians  = hessianMatrices;
 
  102         internalEffects   = hessianEffects;
 
  104         if (internalValues    != NULL) bufferChar[0] = 
'1';
 
  105         if (internalDirection != NULL) bufferChar[1] = 
'1';
 
  106         if (internalImageVec  != NULL) bufferChar[2] = 
'1';
 
  107         if (internalGrads     != NULL) bufferChar[3] = 
'1';
 
  108         if (internalHessians  != NULL) bufferChar[4] = 
'1';
 
  109         if (internalEffects   != NULL) bufferChar[5] = 
'1';
 
  112       m_env.subComm().syncPrintDebugMsg(
"In VectorFunctionSynchronizer<V,M>::callFunction(), just before char Bcast()",3,3000000);
 
  115       int count = (int) bufferChar.size();
 
  117                             "VectorFunctionSynchronizer<P_V,P_M,Q_V,Q_M>::callFunction()",
 
  118                             "failed broadcast 1 of 3");
 
  120       if (bufferChar[0] == 
'1') {
 
  126         std::vector<double> bufferDouble(m_auxPVec.sizeLocal(),0);
 
  128         if (m_env.subRank() == 0) {
 
  129           for (
unsigned int i = 0; i < internalValues->sizeLocal(); ++i) {
 
  130             bufferDouble[i] = (*internalValues)[i];
 
  134         count = (int) bufferDouble.size();
 
  136                               "VectorFunctionSynchronizer<P_V,P_M,Q_V,Q_M>::callFunction()",
 
  137                               "failed broadcast 2 of 3");
 
  139         if (m_env.subRank() != 0) {
 
  140           P_V tmpPVec(m_auxPVec);
 
  141           for (
unsigned int i = 0; i < tmpPVec.sizeLocal(); ++i) {
 
  142             tmpPVec[i] = bufferDouble[i];
 
  144           internalValues = 
new P_V(tmpPVec);
 
  147         if (bufferChar[1] == 
'1') {
 
  153           if (m_env.subRank() == 0) {
 
  154             for (
unsigned int i = 0; i < internalDirection->sizeLocal(); ++i) {
 
  155               bufferDouble[i] = (*internalDirection)[i];
 
  159           count = (int) bufferDouble.size();
 
  161                                 "VectorFunctionSynchronizer<P_V,P_M,Q_V,Q_M>::callFunction()",
 
  162                                 "failed broadcast 3 of 3");
 
  164           if (m_env.subRank() != 0) {
 
  165             P_V tmpPVec(m_auxPVec);
 
  166             for (
unsigned int i = 0; i < tmpPVec.sizeLocal(); ++i) {
 
  167               tmpPVec[i] = bufferDouble[i];
 
  169             internalDirection = 
new P_V(tmpPVec);
 
  176         if (m_env.subRank() != 0) {
 
  177           if (bufferChar[2] == 
'1') internalImageVec = 
new Q_V(m_auxQVec);
 
  183         m_env.subComm().Barrier();
 
  184         m_vectorFunction.compute(*internalValues,
 
  195       if (m_env.subRank() == 0) {
 
  196         stayInRoutine = 
false; 
 
  199         if (internalValues    != NULL) 
delete internalValues;
 
  200         if (internalDirection != NULL) 
delete internalDirection;
 
  201         if (internalImageVec  != NULL) 
delete internalImageVec;
 
  206         stayInRoutine = (vecValues == NULL) && (bufferChar[0] == 
'1');
 
  208     } 
while (stayInRoutine);
 
  213                         "VectorFunctionSynchronizer<V,M>::callFunction()",
 
  214                         "Neither vecValues nor imageVector should not be NULL");
 
  215     UQ_FATAL_TEST_MACRO((m_auxPVec.numOfProcsForStorage() != m_auxQVec.numOfProcsForStorage()),
 
  217                         "VectorFunctionSynchronizer<V,M>::callFunction()",
 
  218                         "Number of processors required for storage should be the same");
 
  220     m_env.subComm().Barrier();
 
  221     m_vectorFunction.compute(*vecValues,
 
VectorFunctionSynchronizer(const BaseVectorFunction< P_V, P_M, Q_V, Q_M > &inputFunction, const P_V &auxPVec, const Q_V &auxQVec)
Default constructor. 
 
const VectorSet< P_V, P_M > & domainSet() const 
Access to the domain set of the vector-valued function which will be synchronized. 
 
#define RawValue_MPI_DOUBLE
 
A class for partitioning vectors and matrices. 
 
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
 
void callFunction(const P_V *vecValues, const P_V *vecDirection, Q_V *imageVector, DistArray< P_V * > *gradVectors, DistArray< P_M * > *hessianMatrices, DistArray< P_V * > *hessianEffects) const 
Calls the vector-valued function which will be synchronized. 
 
A templated (base) class for handling vector functions. 
 
#define RawValue_MPI_CHAR
 
A templated class for synchronizing the calls of vector-valued functions. 
 
~VectorFunctionSynchronizer()
Destructor.