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) {
93 if ((vecValues != NULL))
queso_require_msg(imageVector,
"imageVector should not be NULL");
94 internalValues = vecValues;
95 internalDirection = vecDirection;
96 internalImageVec = imageVector;
97 internalGrads = gradVectors;
98 internalHessians = hessianMatrices;
99 internalEffects = hessianEffects;
101 if (internalValues != NULL) bufferChar[0] =
'1';
102 if (internalDirection != NULL) bufferChar[1] =
'1';
103 if (internalImageVec != NULL) bufferChar[2] =
'1';
104 if (internalGrads != NULL) bufferChar[3] =
'1';
105 if (internalHessians != NULL) bufferChar[4] =
'1';
106 if (internalEffects != NULL) bufferChar[5] =
'1';
109 m_env.subComm().syncPrintDebugMsg(
"In VectorFunctionSynchronizer<V,M>::callFunction(), just before char Bcast()",3,3000000);
112 int count = (int) bufferChar.size();
114 "VectorFunctionSynchronizer<P_V,P_M,Q_V,Q_M>::callFunction()",
115 "failed broadcast 1 of 3");
117 if (bufferChar[0] ==
'1') {
123 std::vector<double> bufferDouble(m_auxPVec.sizeLocal(),0);
125 if (m_env.subRank() == 0) {
126 for (
unsigned int i = 0; i < internalValues->sizeLocal(); ++i) {
127 bufferDouble[i] = (*internalValues)[i];
131 count = (int) bufferDouble.size();
133 "VectorFunctionSynchronizer<P_V,P_M,Q_V,Q_M>::callFunction()",
134 "failed broadcast 2 of 3");
136 if (m_env.subRank() != 0) {
137 P_V tmpPVec(m_auxPVec);
138 for (
unsigned int i = 0; i < tmpPVec.sizeLocal(); ++i) {
139 tmpPVec[i] = bufferDouble[i];
141 internalValues =
new P_V(tmpPVec);
144 if (bufferChar[1] ==
'1') {
150 if (m_env.subRank() == 0) {
151 for (
unsigned int i = 0; i < internalDirection->sizeLocal(); ++i) {
152 bufferDouble[i] = (*internalDirection)[i];
156 count = (int) bufferDouble.size();
158 "VectorFunctionSynchronizer<P_V,P_M,Q_V,Q_M>::callFunction()",
159 "failed broadcast 3 of 3");
161 if (m_env.subRank() != 0) {
162 P_V tmpPVec(m_auxPVec);
163 for (
unsigned int i = 0; i < tmpPVec.sizeLocal(); ++i) {
164 tmpPVec[i] = bufferDouble[i];
166 internalDirection =
new P_V(tmpPVec);
173 if (m_env.subRank() != 0) {
174 if (bufferChar[2] ==
'1') internalImageVec =
new Q_V(m_auxQVec);
180 m_env.subComm().Barrier();
181 m_vectorFunction.compute(*internalValues,
192 if (m_env.subRank() == 0) {
193 stayInRoutine =
false;
196 if (internalValues != NULL)
delete internalValues;
197 if (internalDirection != NULL)
delete internalDirection;
198 if (internalImageVec != NULL)
delete internalImageVec;
203 stayInRoutine = (vecValues == NULL) && (bufferChar[0] ==
'1');
205 }
while (stayInRoutine);
208 queso_require_msg(!((vecValues == NULL) || (imageVector == NULL)),
"Neither vecValues nor imageVector should not be NULL");
209 queso_require_equal_to_msg(m_auxPVec.numOfProcsForStorage(), m_auxQVec.numOfProcsForStorage(),
"Number of processors required for storage should be the same");
211 m_env.subComm().Barrier();
212 m_vectorFunction.compute(*vecValues,
A templated (base) class for handling vector functions.
#define queso_require_equal_to_msg(expr1, expr2, msg)
#define queso_require_msg(asserted, msg)
VectorFunctionSynchronizer(const BaseVectorFunction< P_V, P_M, Q_V, Q_M > &inputFunction, const P_V &auxPVec, const Q_V &auxQVec)
Default constructor.
A class for partitioning vectors and matrices.
A templated class for synchronizing the calls of vector-valued functions.
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.
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_CHAR
#define RawValue_MPI_DOUBLE
~VectorFunctionSynchronizer()
Destructor.