25 #include <queso/MLSampling.h>
26 #include <queso/InstantiateIntersection.h>
27 #include <queso/GslVector.h>
28 #include <queso/GslMatrix.h>
34 void BIP_routine(glp_tree *tree,
void *info)
36 const BaseEnvironment& env = *(((BIP_routine_struct *) info)->env);
37 unsigned int currLevel = ((BIP_routine_struct *) info)->currLevel;
39 int reason = glp_ios_reason(tree);
41 if ((env.subDisplayFile()) && (env.displayVerbosity() >= 1)) {
42 *env.subDisplayFile() <<
"In BIP_routine()"
44 <<
": glp_ios_reason() = " << reason
47 std::cout <<
"In BIP_routine: reason = " << reason << std::endl;
82 "invalid glp_ios_readon");
89 #endif // QUESO_HAS_GLPK
91 template <
class P_V,
class P_M>
94 unsigned int unifiedRequestedNumSamples,
95 const std::vector<double>& unifiedWeightStdVectorAtProc0Only,
96 std::vector<unsigned int>& unifiedIndexCountersAtProc0Only)
98 if (m_env.inter0Rank() != 0)
return;
100 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
101 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::sampleIndexes_proc0()"
103 <<
", step " << m_currStep
104 <<
": unifiedRequestedNumSamples = " << unifiedRequestedNumSamples
105 <<
", unifiedWeightStdVectorAtProc0Only.size() = " << unifiedWeightStdVectorAtProc0Only.size()
109 #if 0 // For debug only
110 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
111 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::sampleIndexes_proc0()"
113 <<
", step " << m_currStep
116 unsigned int numZeros = 0;
117 for (
unsigned int i = 0; i < unifiedWeightStdVectorAtProc0Only.size(); ++i) {
118 *m_env.subDisplayFile() <<
" unifiedWeightStdVectorAtProc0Only[" << i
119 <<
"] = " << unifiedWeightStdVectorAtProc0Only[i]
121 if (unifiedWeightStdVectorAtProc0Only[i] == 0.) numZeros++;
123 *m_env.subDisplayFile() <<
"Number of zeros in unifiedWeightStdVectorAtProc0Only = " << numZeros
128 if (m_env.inter0Rank() == 0) {
129 unsigned int resizeSize = unifiedWeightStdVectorAtProc0Only.size();
130 unifiedIndexCountersAtProc0Only.resize(resizeSize,0);
135 unifiedWeightStdVectorAtProc0Only);
136 for (
unsigned int i = 0; i < unifiedRequestedNumSamples; ++i) {
137 unsigned int index = tmpFd.
sample();
138 unifiedIndexCountersAtProc0Only[index] += 1;
145 template <
class P_V,
class P_M>
149 unsigned int indexOfFirstWeight,
150 unsigned int indexOfLastWeight,
151 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
152 std::vector<ExchangeInfoStruct>& exchangeStdVec)
156 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
157 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::decideOnBalancedChains_all()"
159 <<
", step " << m_currStep
160 <<
": indexOfFirstWeight = " << indexOfFirstWeight
161 <<
", indexOfLastWeight = " << indexOfLastWeight
167 if (m_env.inter0Rank() >= 0) {
168 Np = (
unsigned int) m_env.inter0Comm().NumProc();
170 std::vector<unsigned int> allFirstIndexes(Np,0);
171 std::vector<unsigned int> allLastIndexes(Np,0);
173 if (m_env.inter0Rank() >= 0) {
177 unsigned int auxUInt = indexOfFirstWeight;
179 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
180 "failed MPI.Gather() for first indexes");
182 if (m_env.inter0Rank() == 0) {
185 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
186 "failed MPI.Gather() result for first indexes, at proc 0");
189 auxUInt = indexOfLastWeight;
191 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
192 "failed MPI.Gather() for last indexes");
194 if (m_env.inter0Rank() == 0) {
198 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
199 "failed MPI.Gather() result for last indexes, at proc 0");
206 if (m_env.inter0Rank() == 0) {
207 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
208 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::decideOnBalancedChains_all()"
210 <<
", step " << m_currStep
211 <<
": original distribution of unified indexes in 'inter0Comm' is as follows"
213 for (
unsigned int r = 0; r < Np; ++r) {
214 *m_env.subDisplayFile() <<
" allFirstIndexes[" << r <<
"] = " << allFirstIndexes[r]
215 <<
" allLastIndexes[" << r <<
"] = " << allLastIndexes[r]
219 for (
unsigned int r = 0; r < (Np-1); ++r) {
222 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
226 for (
unsigned int r = 0; r < (Np-1); ++r) {
229 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
233 std::vector<unsigned int> origNumChainsPerNode (Np,0);
234 std::vector<unsigned int> origNumPositionsPerNode(Np,0);
236 for (
unsigned int i = 0; i < unifiedIndexCountersAtProc0Only.size(); ++i) {
237 if ((allFirstIndexes[r] <= i) &&
238 (i <= allLastIndexes[r] )) {
243 if ((r < (
int) Np ) &&
244 (allFirstIndexes[r] <= i) &&
245 (i <= allLastIndexes[r] )) {
249 std::cerr <<
"In MLSampling<P_V,P_M>::decideOnBalancedChains_all()"
252 <<
", allFirstIndexes[r] = " << allFirstIndexes[r]
253 <<
", allLastIndexes[r] = " << allLastIndexes[r]
257 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
258 "wrong indexes or 'r' got too large");
261 if (unifiedIndexCountersAtProc0Only[i] != 0) {
262 origNumChainsPerNode [r] += 1;
263 origNumPositionsPerNode[r] += unifiedIndexCountersAtProc0Only[i];
270 exchangeStdVec.push_back(auxInfo);
276 unsigned int totalNumberOfChains = 0;
277 for (
unsigned int r = 0; r < Np; ++r) {
278 totalNumberOfChains += origNumChainsPerNode[r];
280 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
281 *m_env.subDisplayFile() <<
" KEY"
283 <<
", step " << m_currStep
285 <<
", totalNumberOfChains = " << totalNumberOfChains
290 unsigned int origMinPosPerNode = *std::min_element(origNumPositionsPerNode.begin(), origNumPositionsPerNode.end());
291 unsigned int origMaxPosPerNode = *std::max_element(origNumPositionsPerNode.begin(), origNumPositionsPerNode.end());
292 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
293 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
294 *m_env.subDisplayFile() <<
" KEY"
296 <<
", step " << m_currStep
297 <<
", origNumChainsPerNode[" << nodeId <<
"] = " << origNumChainsPerNode[nodeId]
298 <<
", origNumPositionsPerNode[" << nodeId <<
"] = " << origNumPositionsPerNode[nodeId]
302 double origRatioOfPosPerNode = ((double) origMaxPosPerNode ) / ((double) origMinPosPerNode);
303 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
304 *m_env.subDisplayFile() <<
" KEY"
306 <<
", step " << m_currStep
307 <<
", origRatioOfPosPerNode = " << origRatioOfPosPerNode
315 (m_env.numSubEnvironments() > 1 ) &&
316 (Np < totalNumberOfChains ) &&
323 m_env.fullComm().Barrier();
324 unsigned int tmpValue = result;
326 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
327 "failed MPI.Bcast() for 'result'");
328 if (m_env.inter0Rank() != 0) result = tmpValue;
330 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
331 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::decideOnBalancedChains_all()"
333 <<
", step " << m_currStep
334 <<
": result = " << result
341 template <
class P_V,
class P_M>
346 std::vector<ExchangeInfoStruct>& exchangeStdVec,
349 if (m_env.inter0Rank() < 0)
return;
351 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
352 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()"
354 <<
", step " << m_currStep
358 unsigned int Np = (
unsigned int) m_env.inter0Comm().NumProc();
359 if (m_env.inter0Rank() == 0) {
362 justBalance_proc0(currOptions,
368 #ifdef QUESO_HAS_GLPK
370 solveBIP_proc0(exchangeStdVec);
372 if (m_env.subDisplayFile()) {
373 *m_env.subDisplayFile() <<
"WARNING in MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()"
375 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
376 <<
". Code will therefore process the algorithm id '" << 2
380 if (m_env.subRank() == 0) {
381 std::cerr <<
"WARNING in MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()"
383 <<
"' has been requested, but this QUESO library has not been built with 'hdf5'"
384 <<
". Code will therefore process the algorithm id '" << 2
388 justBalance_proc0(currOptions,
395 m_env.inter0Comm().Barrier();
400 unsigned int exchangeStdVecSize = exchangeStdVec.size();
402 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
403 "failed MPI.Bcast() for exchangeStdVec size");
404 if (m_env.inter0Rank() > 0) exchangeStdVec.resize(exchangeStdVecSize);
407 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
408 "failed MPI.Bcast() for exchangeStdVec data");
413 std::vector<unsigned int> finalNumChainsPerNode (Np,0);
414 std::vector<unsigned int> finalNumPositionsPerNode(Np,0);
415 unsigned int Nc = exchangeStdVec.size();
416 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
417 unsigned int nodeId = exchangeStdVec[chainId].finalNodeOfInitialPosition;
418 finalNumChainsPerNode [nodeId] += 1;
419 finalNumPositionsPerNode[nodeId] += exchangeStdVec[chainId].numberOfPositions;
425 unsigned int finalMinPosPerNode = *std::min_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
426 unsigned int finalMaxPosPerNode = *std::max_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
427 double finalRatioOfPosPerNode = ((double) finalMaxPosPerNode) / ((double)finalMinPosPerNode);
430 std::vector<double> auxBuf(1,0.);
431 double minRatio = 0.;
432 auxBuf[0] = finalRatioOfPosPerNode;
434 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
435 "failed MPI.Allreduce() for min");
439 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
440 "failed minRatio sanity check");
442 double maxRatio = 0.;
443 auxBuf[0] = finalRatioOfPosPerNode;
445 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
446 "failed MPI.Allreduce() for max");
450 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
451 "failed maxRatio sanity check");
456 unsigned int finalNumChainsPerNodeSize = finalNumChainsPerNode.size();
458 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
459 "failed MPI.Bcast() for finalNumChainsPerNode size");
460 if (m_env.inter0Rank() > 0) finalNumChainsPerNode.resize(finalNumChainsPerNodeSize);
462 m_env.inter0Comm().Bcast((
void *) &finalNumChainsPerNode[0], (
int) finalNumChainsPerNodeSize,
RawValue_MPI_UNSIGNED, 0,
463 "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
464 "failed MPI.Bcast() for finalNumChainsPerNode data");
470 mpiExchangePositions_inter0(prevChain,
472 finalNumChainsPerNode,
473 finalNumPositionsPerNode,
474 balancedLinkControl);
479 template <
class P_V,
class P_M>
482 unsigned int indexOfFirstWeight,
483 unsigned int indexOfLastWeight,
484 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
487 if (m_env.inter0Rank() < 0)
return;
489 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
490 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
492 <<
", step " << m_currStep
493 <<
": indexOfFirstWeight = " << indexOfFirstWeight
494 <<
", indexOfLastWeight = " << indexOfLastWeight
498 unsigned int subNumSamples = 0;
499 std::vector<unsigned int> unifiedIndexCountersAtAllProcs(0);
502 unsigned int resizeSize = unifiedIndexCountersAtProc0Only.size();
504 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
505 "failed MPI.Bcast() for resizeSize");
506 unifiedIndexCountersAtAllProcs.resize(resizeSize,0);
508 if (m_env.inter0Rank() == 0) unifiedIndexCountersAtAllProcs = unifiedIndexCountersAtProc0Only;
511 m_env.inter0Comm().Bcast((
void *) &unifiedIndexCountersAtAllProcs[0], (
int) unifiedIndexCountersAtAllProcs.size(),
RawValue_MPI_UNSIGNED, 0,
512 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
513 "failed MPI.Bcast() for unified index counters");
514 #if 0 // Use allgatherv ??? for subNumSamples instead
515 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
516 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
518 <<
", step " << m_currStep
521 for (
int r = 0; r < m_env.inter0Comm().NumProc(); ++r) {
522 *m_env.subDisplayFile() <<
" unifiedIndexCountersAtAllProcs[" << r <<
"] = " << unifiedIndexCountersAtAllProcs[r]
536 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
537 "invalid indexOfFirstWeight");
540 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
541 "invalid indexOfLastWeight");
543 for (
unsigned int i = indexOfFirstWeight; i <= indexOfLastWeight; ++i) {
544 subNumSamples += unifiedIndexCountersAtAllProcs[i];
547 std::vector<unsigned int> auxBuf(1,0);
549 unsigned int minModifiedSubNumSamples = 0;
550 auxBuf[0] = subNumSamples;
552 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
553 "failed MPI.Allreduce() for min");
555 unsigned int maxModifiedSubNumSamples = 0;
556 auxBuf[0] = subNumSamples;
558 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
559 "failed MPI.Allreduce() for max");
561 unsigned int sumModifiedSubNumSamples = 0;
562 auxBuf[0] = subNumSamples;
564 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
565 "failed MPI.Allreduce() for sum");
572 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
573 *m_env.subDisplayFile() <<
"KEY Leaving MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
575 <<
", step " << m_currStep
576 <<
": subNumSamples = " << subNumSamples
577 <<
", unifiedIndexCountersAtAllProcs.size() = " << unifiedIndexCountersAtAllProcs.size()
579 *m_env.subDisplayFile() <<
"KEY Leaving MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
581 <<
", step " << m_currStep
582 <<
": minModifiedSubNumSamples = " << minModifiedSubNumSamples
583 <<
", avgModifiedSubNumSamples = " << ((double) sumModifiedSubNumSamples)/((double) m_env.inter0Comm().NumProc())
584 <<
", maxModifiedSubNumSamples = " << maxModifiedSubNumSamples
588 unsigned int numberOfPositionsToGuaranteeForNode = subNumSamples;
589 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
590 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
592 <<
", step " << m_currStep
593 <<
": numberOfPositionsToGuaranteeForNode = " << numberOfPositionsToGuaranteeForNode
596 for (
unsigned int i = indexOfFirstWeight; i <= indexOfLastWeight; ++i) {
598 while (unifiedIndexCountersAtAllProcs[i] != 0) {
599 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 30)) {
600 *m_env.subDisplayFile() <<
", numberOfPositionsToGuaranteeForNode = " << numberOfPositionsToGuaranteeForNode
601 <<
", unifiedIndexCountersAtAllProcs[" << i
602 <<
"] = " << unifiedIndexCountersAtAllProcs[i]
605 if (unifiedIndexCountersAtAllProcs[i] < numberOfPositionsToGuaranteeForNode) {
611 numberOfPositionsToGuaranteeForNode -= unifiedIndexCountersAtAllProcs[i];
612 unifiedIndexCountersAtAllProcs[i] = 0;
614 else if ((unifiedIndexCountersAtAllProcs[i] == numberOfPositionsToGuaranteeForNode) &&
615 (unifiedIndexCountersAtAllProcs[i] > 0 )) {
622 unifiedIndexCountersAtAllProcs[i] -= numberOfPositionsToGuaranteeForNode;
623 numberOfPositionsToGuaranteeForNode = 0;
625 else if ((unifiedIndexCountersAtAllProcs[i] == numberOfPositionsToGuaranteeForNode) &&
626 (unifiedIndexCountersAtAllProcs[i] == 0 )) {
632 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
633 "should never get here");
639 "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
640 "numberOfPositionsToGuaranteeForNode exited loop with wrong value");
643 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
644 *m_env.subDisplayFile() <<
"KEY Leaving MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()"
646 <<
", step " << m_currStep
647 <<
": unbalancedLinkControl.unbLinkedChains.size() = " << unbalancedLinkControl.
unbLinkedChains.size()
654 template <
class P_V,
class P_M>
658 const P_M& unifiedCovMatrix,
662 double& cumulativeRunTime,
663 unsigned int& cumulativeRejections,
667 m_env.fullComm().Barrier();
669 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
670 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
671 <<
": balancedLinkControl.balLinkedChains.size() = " << balancedLinkControl.
balLinkedChains.size()
675 P_V auxInitialPosition(m_vectorSpace.zeroVector());
677 unsigned int chainIdMax = 0;
678 if (m_env.inter0Rank() >= 0) {
683 "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
684 "failed MPI.Bcast() for chainIdMax");
686 struct timeval timevalEntering;
688 iRC = gettimeofday(&timevalEntering, NULL);
691 if (m_env.inter0Rank() >= 0) {
692 unsigned int numberOfPositions = 0;
693 for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
694 numberOfPositions += balancedLinkControl.
balLinkedChains[chainId].numberOfPositions;
697 std::vector<unsigned int> auxBuf(1,0);
699 unsigned int minNumberOfPositions = 0;
700 auxBuf[0] = numberOfPositions;
702 "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
703 "failed MPI.Allreduce() for min");
705 unsigned int maxNumberOfPositions = 0;
706 auxBuf[0] = numberOfPositions;
708 "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
709 "failed MPI.Allreduce() for max");
711 unsigned int sumNumberOfPositions = 0;
712 auxBuf[0] = numberOfPositions;
714 "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
715 "failed MPI.Allreduce() for sum");
717 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
718 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
720 <<
", step " << m_currStep
721 <<
": chainIdMax = " << chainIdMax
722 <<
", numberOfPositions = " << numberOfPositions
723 <<
", at " << ctime(&timevalEntering.tv_sec)
725 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
727 <<
", step " << m_currStep
728 <<
": minNumberOfPositions = " << minNumberOfPositions
729 <<
", avgNumberOfPositions = " << ((double) sumNumberOfPositions)/((double) m_env.inter0Comm().NumProc())
730 <<
", maxNumberOfPositions = " << maxNumberOfPositions
736 if ((m_debugExponent == 1.) &&
737 (m_currStep == 10)) {
740 unsigned int cumulativeNumPositions = 0;
741 for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
742 unsigned int tmpChainSize = 0;
743 if (m_env.inter0Rank() >= 0) {
745 auxInitialPosition = *(balancedLinkControl.
balLinkedChains[chainId].initialPosition);
746 tmpChainSize = balancedLinkControl.
balLinkedChains[chainId].numberOfPositions+1;
747 if ((m_env.subDisplayFile() ) &&
748 (m_env.displayVerbosity() >= 3)) {
749 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
751 <<
", step " << m_currStep
752 <<
", chainId = " << chainId
753 <<
" < " << chainIdMax
754 <<
": begin generating " << tmpChainSize
755 <<
" chain positions"
759 auxInitialPosition.mpiBcast(0, m_env.subComm());
760 #if 0 // For debug only
761 for (
int r = 0; r < m_env.subComm().NumProc(); ++r) {
762 if (r == m_env.subComm().MyPID()) {
763 std::cout <<
"Vector 'auxInitialPosition at rank " << r
764 <<
" has contents " << auxInitialPosition
767 m_env.subComm().Barrier();
774 "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
775 "failed MPI.Bcast() for tmpChainSize");
780 m_options.m_prefix+
"tmp_chain");
792 &tmpLogLikelihoodValues,
793 &tmpLogTargetValues);
796 cumulativeRunTime += mcRawInfo.
runTime;
799 if (m_env.inter0Rank() >= 0) {
800 if (m_env.exceptionalCircumstance()) {
801 if ((m_env.subDisplayFile() ) &&
802 (m_env.displayVerbosity() >= 0)) {
803 P_V tmpVec(m_vectorSpace.zeroVector());
804 for (
unsigned int i = 0; i < tmpLogLikelihoodValues.
subSequenceSize(); ++i) {
806 *m_env.subDisplayFile() <<
"DEBUG finalChain[" << cumulativeNumPositions+i <<
"] "
807 <<
"= tmpChain[" << i <<
"] = " << tmpVec
808 <<
", tmpLogLikelihoodValues[" << i <<
"] = " << tmpLogLikelihoodValues[i]
809 <<
", tmpLogTargetValues[" << i <<
"] = " << tmpLogTargetValues[i]
815 cumulativeNumPositions += tmpChainSize;
816 if (cumulativeNumPositions > 100) m_env.setExceptionalCircumstance(
false);
818 if ((m_env.subDisplayFile() ) &&
819 (m_env.displayVerbosity() >= 3)) {
820 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
822 <<
", step " << m_currStep
823 <<
", chainId = " << chainId
824 <<
" < " << chainIdMax
826 <<
" chain positions"
832 if (currLogLikelihoodValues) {
833 currLogLikelihoodValues->
append(tmpLogLikelihoodValues,1,tmpLogLikelihoodValues.
subSequenceSize()-1);
834 if ((m_env.subDisplayFile() ) &&
835 (m_env.displayVerbosity() >= 99) &&
837 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
839 <<
", step " << m_currStep
840 <<
", chainId = " << chainId
841 <<
", tmpLogLikelihoodValues.subSequenceSize() = " << tmpLogLikelihoodValues.
subSequenceSize()
842 <<
", tmpLogLikelihoodValues[0] = " << tmpLogLikelihoodValues[0]
843 <<
", tmpLogLikelihoodValues[1] = " << tmpLogLikelihoodValues[1]
844 <<
", currLogLikelihoodValues[0] = " << (*currLogLikelihoodValues)[0]
848 if (currLogTargetValues) {
857 struct timeval timevalBarrier;
858 iRC = gettimeofday(&timevalBarrier, NULL);
861 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
862 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
864 <<
", step " << m_currStep
865 <<
": ended chain loop after " << loopTime <<
" seconds"
866 <<
", calling fullComm().Barrier() at " << ctime(&timevalBarrier.tv_sec)
870 m_env.fullComm().Barrier();
872 struct timeval timevalLeaving;
873 iRC = gettimeofday(&timevalLeaving, NULL);
876 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
877 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateBalLinkedChains_all()"
879 <<
", step " << m_currStep
880 <<
": after " << barrierTime <<
" seconds in fullComm().Barrier()"
881 <<
", at " << ctime(&timevalLeaving.tv_sec)
888 template <
class P_V,
class P_M>
892 const P_M& unifiedCovMatrix,
895 unsigned int indexOfFirstWeight,
898 double& cumulativeRunTime,
899 unsigned int& cumulativeRejections,
903 m_env.fullComm().Barrier();
905 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
906 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
907 <<
": unbalancedLinkControl.unbLinkedChains.size() = " << unbalancedLinkControl.
unbLinkedChains.size()
908 <<
", indexOfFirstWeight = " << indexOfFirstWeight
912 P_V auxInitialPosition(m_vectorSpace.zeroVector());
914 unsigned int chainIdMax = 0;
915 if (m_env.inter0Rank() >= 0) {
920 "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
921 "failed MPI.Bcast() for chainIdMax");
923 struct timeval timevalEntering;
925 iRC = gettimeofday(&timevalEntering, NULL);
928 if (m_env.inter0Rank() >= 0) {
929 unsigned int numberOfPositions = 0;
930 for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
931 numberOfPositions += unbalancedLinkControl.
unbLinkedChains[chainId].numberOfPositions;
934 std::vector<unsigned int> auxBuf(1,0);
936 unsigned int minNumberOfPositions = 0;
937 auxBuf[0] = numberOfPositions;
939 "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
940 "failed MPI.Allreduce() for min");
942 unsigned int maxNumberOfPositions = 0;
943 auxBuf[0] = numberOfPositions;
945 "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
946 "failed MPI.Allreduce() for max");
948 unsigned int sumNumberOfPositions = 0;
949 auxBuf[0] = numberOfPositions;
951 "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
952 "failed MPI.Allreduce() for sum");
954 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
955 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
957 <<
", step " << m_currStep
958 <<
": chainIdMax = " << chainIdMax
959 <<
", numberOfPositions = " << numberOfPositions
960 <<
", at " << ctime(&timevalEntering.tv_sec)
962 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
964 <<
", step " << m_currStep
965 <<
": minNumberOfPositions = " << minNumberOfPositions
966 <<
", avgNumberOfPositions = " << ((double) sumNumberOfPositions)/((double) m_env.inter0Comm().NumProc())
967 <<
", maxNumberOfPositions = " << maxNumberOfPositions
971 if ((m_debugExponent == 1.) &&
972 (m_currStep == 10)) {
975 unsigned int cumulativeNumPositions = 0;
976 for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
977 unsigned int tmpChainSize = 0;
978 if (m_env.inter0Rank() >= 0) {
979 unsigned int auxIndex = unbalancedLinkControl.
unbLinkedChains[chainId].initialPositionIndexInPreviousChain - indexOfFirstWeight;
981 tmpChainSize = unbalancedLinkControl.
unbLinkedChains[chainId].numberOfPositions+1;
982 if ((m_env.subDisplayFile() ) &&
983 (m_env.displayVerbosity() >= 3)) {
984 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
986 <<
", step " << m_currStep
987 <<
", chainId = " << chainId
988 <<
" < " << chainIdMax
989 <<
": begin generating " << tmpChainSize
990 <<
" chain positions"
994 auxInitialPosition.mpiBcast(0, m_env.subComm());
995 #if 0 // For debug only
996 for (
int r = 0; r < m_env.subComm().NumProc(); ++r) {
997 if (r == m_env.subComm().MyPID()) {
998 std::cout <<
"Vector 'auxInitialPosition at rank " << r
999 <<
" has contents " << auxInitialPosition
1002 m_env.subComm().Barrier();
1009 "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
1010 "failed MPI.Bcast() for tmpChainSize");
1015 m_options.m_prefix+
"tmp_chain");
1027 &tmpLogLikelihoodValues,
1028 &tmpLogTargetValues);
1031 cumulativeRunTime += mcRawInfo.
runTime;
1034 if (m_env.inter0Rank() >= 0) {
1035 if (m_env.exceptionalCircumstance()) {
1036 if ((m_env.subDisplayFile() ) &&
1037 (m_env.displayVerbosity() >= 0)) {
1038 P_V tmpVec(m_vectorSpace.zeroVector());
1039 for (
unsigned int i = 0; i < tmpLogLikelihoodValues.
subSequenceSize(); ++i) {
1041 *m_env.subDisplayFile() <<
"DEBUG finalChain[" << cumulativeNumPositions+i <<
"] "
1042 <<
"= tmpChain[" << i <<
"] = " << tmpVec
1043 <<
", tmpLogLikelihoodValues[" << i <<
"] = " << tmpLogLikelihoodValues[i]
1044 <<
", tmpLogTargetValues[" << i <<
"] = " << tmpLogTargetValues[i]
1050 cumulativeNumPositions += tmpChainSize;
1051 if (cumulativeNumPositions > 100) m_env.setExceptionalCircumstance(
false);
1053 if ((m_env.subDisplayFile() ) &&
1054 (m_env.displayVerbosity() >= 3)) {
1055 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
1057 <<
", step " << m_currStep
1058 <<
", chainId = " << chainId
1059 <<
" < " << chainIdMax
1061 <<
" chain positions"
1067 if (currLogLikelihoodValues) {
1068 currLogLikelihoodValues->
append(tmpLogLikelihoodValues,1,tmpLogLikelihoodValues.
subSequenceSize()-1);
1069 if ((m_env.subDisplayFile() ) &&
1070 (m_env.displayVerbosity() >= 99) &&
1072 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
1074 <<
", step " << m_currStep
1075 <<
", chainId = " << chainId
1076 <<
", tmpLogLikelihoodValues.subSequenceSize() = " << tmpLogLikelihoodValues.
subSequenceSize()
1077 <<
", tmpLogLikelihoodValues[0] = " << tmpLogLikelihoodValues[0]
1078 <<
", tmpLogLikelihoodValues[1] = " << tmpLogLikelihoodValues[1]
1079 <<
", currLogLikelihoodValues[0] = " << (*currLogLikelihoodValues)[0]
1083 if (currLogTargetValues) {
1089 struct timeval timevalBarrier;
1090 iRC = gettimeofday(&timevalBarrier, NULL);
1093 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1094 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
1096 <<
", step " << m_currStep
1097 <<
": ended chain loop after " << loopTime <<
" seconds"
1098 <<
", calling fullComm().Barrier() at " << ctime(&timevalBarrier.tv_sec)
1102 m_env.fullComm().Barrier();
1104 struct timeval timevalLeaving;
1105 iRC = gettimeofday(&timevalLeaving, NULL);
1108 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1109 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateUnbLinkedChains_all()"
1111 <<
", step " << m_currStep
1112 <<
": after " << barrierTime <<
" seconds in fullComm().Barrier()"
1113 <<
", at " << ctime(&timevalLeaving.tv_sec)
1120 #ifdef QUESO_HAS_GLPK
1121 template <
class P_V,
class P_M>
1124 std::vector<ExchangeInfoStruct>& exchangeStdVec)
1126 if (m_env.inter0Rank() != 0)
return;
1129 struct timeval timevalBIP;
1130 iRC = gettimeofday(&timevalBIP, NULL);
1133 unsigned int Np = (
unsigned int) m_env.inter0Comm().NumProc();
1134 unsigned int Nc = exchangeStdVec.size();
1136 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1137 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::solveBIP_proc0()"
1139 <<
", step " << m_currStep
1149 lp = glp_create_prob();
1150 glp_set_prob_name(lp,
"sample");
1155 unsigned int m = Nc+Np-1;
1156 unsigned int n = Nc*Np;
1157 unsigned int ne = Nc*Np + 2*Nc*(Np -1);
1159 glp_add_rows(lp, m);
1160 for (
int i = 1; i <= (int) Nc; ++i) {
1161 glp_set_row_bnds(lp, i, GLP_FX, 1.0, 1.0);
1162 glp_set_row_name(lp, i,
"");
1164 for (
int i = (Nc+1); i <= (int) (Nc+Np-1); ++i) {
1165 glp_set_row_bnds(lp, i, GLP_UP, 0.0, 0.0);
1166 glp_set_row_name(lp, i,
"");
1169 glp_add_cols(lp, n);
1170 for (
int j = 1; j <= (int) n; ++j) {
1172 glp_set_col_kind(lp, j, GLP_IV);
1173 glp_set_col_bnds(lp, j, GLP_DB, 0.0, 1.0);
1174 glp_set_col_name(lp, j,
"");
1177 glp_set_obj_dir(lp, GLP_MIN);
1178 for (
int chainId = 0; chainId <= (int) (Nc-1); ++chainId) {
1179 glp_set_obj_coef(lp, (chainId*Np)+1, exchangeStdVec[chainId].numberOfPositions);
1182 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1183 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1185 <<
", step " << m_currStep
1186 <<
": finished setting BIP rows and cols"
1196 std::vector<int > iVec(ne+1,0);
1197 std::vector<int > jVec(ne+1,0);
1198 std::vector<double> aVec(ne+1,0.);
1200 for (
int i = 1; i <= (int) Nc; ++i) {
1201 for (
int j = 1; j <= (int) Np; ++j) {
1203 jVec[coefId] = (i-1)*Np + j;
1208 for (
int i = 1; i <= (int) (Np-1); ++i) {
1209 for (
int j = 1; j <= (int) Nc; ++j) {
1210 iVec[coefId] = Nc+i;
1211 jVec[coefId] = (j-1)*Np + i;
1212 aVec[coefId] = -((double) exchangeStdVec[j-1].numberOfPositions);
1215 iVec[coefId] = Nc+i;
1216 jVec[coefId] = (j-1)*Np + i + 1;
1217 aVec[coefId] = exchangeStdVec[j-1].numberOfPositions;
1221 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1222 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1224 <<
", step " << m_currStep
1225 <<
": finished setting BIP constraint matrix"
1227 <<
", coefId = " << coefId
1233 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1234 "invalid final coefId");
1236 glp_load_matrix(lp, ne, &iVec[0], &jVec[0], &aVec[0]);
1238 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1239 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1241 <<
", step " << m_currStep
1242 <<
": finished loading BIP constraint matrix"
1243 <<
", glp_get_num_rows(lp) = " << glp_get_num_rows(lp)
1244 <<
", glp_get_num_cols(lp) = " << glp_get_num_cols(lp)
1245 <<
", glp_get_num_nz(lp) = " << glp_get_num_nz(lp)
1246 <<
", glp_get_num_int(lp) = " << glp_get_num_int(lp)
1247 <<
", glp_get_num_bin(lp) = " << glp_get_num_bin(lp)
1256 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1257 "invalid number of rows");
1261 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1262 "invalid number of columnss");
1266 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1267 "invalid number of nonzero constraint coefficients");
1271 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1272 "invalid number of integer structural variables");
1276 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1277 "invalid number of binary structural variables");
1282 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1283 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1284 int j = chainId*Np + nodeId + 1;
1286 glp_set_col_stat(lp, j, GLP_BS);
1289 glp_set_col_stat(lp, j, GLP_BS);
1294 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1295 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1296 int j = chainId*Np + nodeId + 1;
1297 int initialState = glp_mip_col_val(lp, j);
1301 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1302 "for nodeId = 0, initial state should be '1'");
1307 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1308 "for nodeId > 0, initial state should be '0'");
1313 for (
int i = 1; i <= (int) Nc; ++i) {
1314 glp_set_row_stat(lp, i, GLP_NS);
1316 for (
int i = (Nc+1); i <= (int) (Nc+Np-1); ++i) {
1317 glp_set_row_stat(lp, i, GLP_BS);
1327 BIP_routine_struct BIP_routine_info;
1328 BIP_routine_info.env = &m_env;
1329 BIP_routine_info.currLevel = m_currLevel;
1331 glp_iocp BIP_params;
1332 glp_init_iocp(&BIP_params);
1333 BIP_params.presolve = GLP_ON;
1338 int BIP_rc = glp_intopt(lp, &BIP_params);
1340 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1341 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1343 <<
", step " << m_currStep
1344 <<
": finished solving BIP"
1345 <<
", BIP_rc = " << BIP_rc
1351 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1352 "BIP returned rc != 0");
1357 int BIP_Status = glp_mip_status(lp);
1358 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1359 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1361 <<
", step " << m_currStep
1362 <<
": BIP_Status = " << BIP_Status
1366 switch (BIP_Status) {
1369 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1370 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1372 <<
", step " << m_currStep
1373 <<
": BIP solution is optimal"
1380 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1381 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1383 <<
", step " << m_currStep
1384 <<
": BIP solution is guaranteed to be 'only' feasible"
1392 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1393 "BIP has an undefined solution or has no solution");
1397 for (
int i = 1; i <= (int) Nc; ++i) {
1400 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1401 "row should have value 1 at solution");
1403 for (
int i = (Nc+1); i <= (int) (Nc+Np-1); ++i) {
1406 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1407 "row should have value 0 or should be negative at solution");
1413 std::vector<unsigned int> finalNumChainsPerNode (Np,0);
1414 std::vector<unsigned int> finalNumPositionsPerNode(Np,0);
1415 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1416 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1417 int j = chainId*Np + nodeId + 1;
1418 if (glp_mip_col_val(lp, j) == 0) {
1421 else if (glp_mip_col_val(lp, j) == 1) {
1424 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1425 "chain has already been taken care of");
1426 exchangeStdVec[chainId].finalNodeOfInitialPosition = nodeId;
1427 finalNumChainsPerNode [nodeId] += 1;
1428 finalNumPositionsPerNode[nodeId] += exchangeStdVec[chainId].numberOfPositions;
1433 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1434 "control variable should be either '0' or '1'");
1439 unsigned int finalMinPosPerNode = *std::min_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
1440 unsigned int finalMaxPosPerNode = *std::max_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
1442 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1443 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::solveBIP_proc0()"
1445 <<
", step " << m_currStep
1446 <<
": finished preparing output information"
1453 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1454 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::solveBIP_proc0()"
1456 <<
", step " << m_currStep
1457 <<
": solution gives the following redistribution"
1459 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1460 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::solveBIP_proc0()"
1462 <<
", step " << m_currStep
1463 <<
", finalNumChainsPerNode[" << nodeId <<
"] = " << finalNumChainsPerNode[nodeId]
1464 <<
", finalNumPositionsPerNode[" << nodeId <<
"] = " << finalNumPositionsPerNode[nodeId]
1467 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::solveBIP_proc0()"
1469 <<
", step " << m_currStep
1470 <<
", finalRatioOfPosPerNode = " << ((double) finalMaxPosPerNode) / ((double)finalMinPosPerNode)
1479 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1480 "Invalid objective value");
1482 for (
unsigned int nodeId = 1; nodeId < Np; ++nodeId) {
1483 UQ_FATAL_TEST_MACRO(finalNumPositionsPerNode[nodeId-1] < finalNumPositionsPerNode[nodeId],
1485 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1486 "Next node should have a number of positions equal or less than the current node");
1489 for (
int i = (
int) (Nc+1); i <= (int) (Nc+Np-1); ++i) {
1490 unsigned int nodeId = i - Nc;
1491 int diff = ((int) finalNumPositionsPerNode[nodeId]) - ((int) finalNumPositionsPerNode[nodeId-1]);
1494 "MLSampling<P_V,P_M>::solveBIP_proc0()",
1501 glp_delete_prob(lp);
1504 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1505 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::solveBIP_proc0()"
1507 <<
", step " << m_currStep
1508 <<
", after " << bipRunTime <<
" seconds"
1514 #endif // QUESO_HAS_GLPK
1516 template <
class P_V,
class P_M>
1520 std::vector<ExchangeInfoStruct>& exchangeStdVec)
1522 if (m_env.inter0Rank() != 0)
return;
1525 struct timeval timevalBal;
1526 iRC = gettimeofday(&timevalBal, NULL);
1529 unsigned int Np = m_env.numSubEnvironments();
1530 unsigned int Nc = exchangeStdVec.size();
1532 std::vector<ExchangeInfoStruct> currExchangeStdVec(Nc);
1533 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1534 currExchangeStdVec[chainId] = exchangeStdVec[chainId];
1535 currExchangeStdVec[chainId].finalNodeOfInitialPosition = currExchangeStdVec[chainId].originalNodeOfInitialPosition;
1541 unsigned int iterIdMax = 0;
1542 std::vector<unsigned int> currNumChainsPerNode (Np,0);
1543 std::vector<unsigned int> currNumPositionsPerNode(Np,0);
1544 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1545 unsigned int nodeId = currExchangeStdVec[chainId].finalNodeOfInitialPosition;
1546 currNumChainsPerNode [nodeId] += 1;
1547 currNumPositionsPerNode[nodeId] += currExchangeStdVec[chainId].numberOfPositions;
1548 iterIdMax += currExchangeStdVec[chainId].numberOfPositions;
1550 unsigned int currMinPosPerNode = *std::min_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
1551 unsigned int currMaxPosPerNode = *std::max_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
1552 double currRatioOfPosPerNode = ((double) currMaxPosPerNode ) / ((double) currMinPosPerNode);
1559 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1560 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::justBalance_proc0()"
1562 <<
", step " << m_currStep
1563 <<
", iter " << iterId
1564 <<
", currRatioOfPosPerNode = " << currRatioOfPosPerNode
1566 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1567 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::justBalance_proc0()"
1569 <<
", step " << m_currStep
1570 <<
", iter " << iterId
1571 <<
", currNumChainsPerNode[" << nodeId <<
"] = " << currNumChainsPerNode[nodeId]
1572 <<
", currNumPositionsPerNode[" << nodeId <<
"] = " << currNumPositionsPerNode[nodeId]
1577 std::vector<std::vector<double> > vectorOfChainSizesPerNode(Np);
1578 while ((iterId < (
int) iterIdMax ) &&
1585 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1586 vectorOfChainSizesPerNode[nodeId].clear();
1588 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1589 unsigned int nodeId = currExchangeStdVec[chainId].finalNodeOfInitialPosition;
1590 vectorOfChainSizesPerNode[nodeId].push_back(currExchangeStdVec[chainId].numberOfPositions);
1593 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1594 std::sort(vectorOfChainSizesPerNode[nodeId].begin(), vectorOfChainSizesPerNode[nodeId].end());
1595 UQ_FATAL_TEST_MACRO(vectorOfChainSizesPerNode[nodeId].size() != currNumChainsPerNode[nodeId],
1597 "MLSampling<P_V,P_M>::justBalance_proc0()",
1598 "inconsistent number of chains in node");
1604 unsigned int currBiggestAmountOfPositionsPerNode = currNumPositionsPerNode[0];
1605 unsigned int currSmallestAmountOfPositionsPerNode = currNumPositionsPerNode[0];
1606 unsigned int currNodeWithMostPositions = 0;
1607 unsigned int currNodeWithLeastPositions = 0;
1608 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1609 if (currNumPositionsPerNode[nodeId] > currBiggestAmountOfPositionsPerNode) {
1610 currBiggestAmountOfPositionsPerNode = currNumPositionsPerNode[nodeId];
1611 currNodeWithMostPositions = nodeId;
1613 if (currNumPositionsPerNode[nodeId] < currSmallestAmountOfPositionsPerNode) {
1614 currSmallestAmountOfPositionsPerNode = currNumPositionsPerNode[nodeId];
1615 currNodeWithLeastPositions = nodeId;
1619 UQ_FATAL_TEST_MACRO(currMinPosPerNode != currNumPositionsPerNode[currNodeWithLeastPositions],
1621 "MLSampling<P_V,P_M>::justBalance_proc0()",
1622 "inconsistent currMinPosPerNode");
1624 UQ_FATAL_TEST_MACRO(currMaxPosPerNode != currNumPositionsPerNode[currNodeWithMostPositions],
1626 "MLSampling<P_V,P_M>::justBalance_proc0()",
1627 "inconsistent currMaxPosPerNode");
1629 unsigned int numberOfPositionsToMove = vectorOfChainSizesPerNode[currNodeWithMostPositions][0];
1631 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1632 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::justBalance_proc0()"
1634 <<
", step " << m_currStep
1635 <<
", iter " << iterId
1636 <<
", before update"
1637 <<
", node w/ most pos is "
1638 << currNodeWithMostPositions <<
"(cs=" << currNumChainsPerNode[currNodeWithMostPositions ] <<
", ps=" << currNumPositionsPerNode[currNodeWithMostPositions ] <<
")"
1639 <<
", node w/ least pos is "
1640 << currNodeWithLeastPositions <<
"(cs=" << currNumChainsPerNode[currNodeWithLeastPositions] <<
", ps=" << currNumPositionsPerNode[currNodeWithLeastPositions] <<
")"
1641 <<
", number of pos to move = " << numberOfPositionsToMove
1648 std::vector<ExchangeInfoStruct> newExchangeStdVec(Nc);
1649 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1650 newExchangeStdVec[chainId] = currExchangeStdVec[chainId];
1653 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1654 if ((newExchangeStdVec[chainId].finalNodeOfInitialPosition == (
int) currNodeWithMostPositions) &&
1655 (newExchangeStdVec[chainId].numberOfPositions == numberOfPositionsToMove )) {
1656 newExchangeStdVec[chainId].finalNodeOfInitialPosition = currNodeWithLeastPositions;
1664 std::vector<unsigned int> newNumChainsPerNode (Np,0);
1665 std::vector<unsigned int> newNumPositionsPerNode(Np,0);
1666 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1667 unsigned int nodeId = newExchangeStdVec[chainId].finalNodeOfInitialPosition;
1668 newNumChainsPerNode [nodeId] += 1;
1669 newNumPositionsPerNode[nodeId] += newExchangeStdVec[chainId].numberOfPositions;
1672 unsigned int newBiggestAmountOfPositionsPerNode = newNumPositionsPerNode[0];
1673 unsigned int newSmallestAmountOfPositionsPerNode = newNumPositionsPerNode[0];
1674 unsigned int newNodeWithMostPositions = 0;
1675 unsigned int newNodeWithLeastPositions = 0;
1676 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1677 if (newNumPositionsPerNode[nodeId] > newBiggestAmountOfPositionsPerNode) {
1678 newBiggestAmountOfPositionsPerNode = newNumPositionsPerNode[nodeId];
1679 newNodeWithMostPositions = nodeId;
1681 if (newNumPositionsPerNode[nodeId] < newSmallestAmountOfPositionsPerNode) {
1682 newSmallestAmountOfPositionsPerNode = newNumPositionsPerNode[nodeId];
1683 newNodeWithLeastPositions = nodeId;
1687 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1688 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::justBalance_proc0()"
1690 <<
", step " << m_currStep
1691 <<
", iter " << iterId
1693 <<
", node w/ most pos is "
1694 << newNodeWithMostPositions <<
"(cs=" << newNumChainsPerNode[newNodeWithMostPositions ] <<
", ps=" << newNumPositionsPerNode[newNodeWithMostPositions ] <<
")"
1695 <<
", node w/ least pos is "
1696 << newNodeWithLeastPositions <<
"(cs=" << newNumChainsPerNode[newNodeWithLeastPositions] <<
", ps=" << newNumPositionsPerNode[newNodeWithLeastPositions] <<
")"
1700 unsigned int newMinPosPerNode = *std::min_element(newNumPositionsPerNode.begin(), newNumPositionsPerNode.end());
1701 unsigned int newMaxPosPerNode = *std::max_element(newNumPositionsPerNode.begin(), newNumPositionsPerNode.end());
1702 double newRatioOfPosPerNode = ((double) newMaxPosPerNode ) / ((double) newMinPosPerNode);
1704 UQ_FATAL_TEST_MACRO(newMinPosPerNode != newNumPositionsPerNode[newNodeWithLeastPositions],
1706 "MLSampling<P_V,P_M>::justBalance_proc0()",
1707 "inconsistent newMinPosPerNode");
1711 "MLSampling<P_V,P_M>::justBalance_proc0()",
1712 "inconsistent newMaxPosPerNode");
1714 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
1715 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::justBalance_proc0()"
1717 <<
", step " << m_currStep
1718 <<
", iter " << iterId
1719 <<
", newMaxPosPerNode = " << newMaxPosPerNode
1720 <<
", newMinPosPerNode = " << newMinPosPerNode
1721 <<
", newRatioOfPosPerNode = " << newRatioOfPosPerNode
1723 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1724 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::justBalance_proc0()"
1726 <<
", step " << m_currStep
1727 <<
", iter " << iterId
1728 <<
", newNumChainsPerNode[" << nodeId <<
"] = " << newNumChainsPerNode [nodeId]
1729 <<
", newNumPositionsPerNode[" << nodeId <<
"] = " << newNumPositionsPerNode[nodeId]
1737 if (newRatioOfPosPerNode > currRatioOfPosPerNode) {
1744 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1745 currNumChainsPerNode [nodeId] = 0;
1746 currNumPositionsPerNode[nodeId] = 0;
1748 currRatioOfPosPerNode = newRatioOfPosPerNode;
1749 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1750 currExchangeStdVec[chainId] = newExchangeStdVec[chainId];
1751 unsigned int nodeId = currExchangeStdVec[chainId].finalNodeOfInitialPosition;
1752 currNumChainsPerNode [nodeId] += 1;
1753 currNumPositionsPerNode[nodeId] += currExchangeStdVec[chainId].numberOfPositions;
1755 currMinPosPerNode = *std::min_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
1756 currMaxPosPerNode = *std::max_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
1757 currRatioOfPosPerNode = ((double) currMaxPosPerNode ) / ((double) currMinPosPerNode);
1763 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1764 exchangeStdVec[chainId].finalNodeOfInitialPosition = currExchangeStdVec[chainId].finalNodeOfInitialPosition;
1770 std::vector<unsigned int> finalNumChainsPerNode (Np,0);
1771 std::vector<unsigned int> finalNumPositionsPerNode(Np,0);
1772 for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
1773 unsigned int nodeId = exchangeStdVec[chainId].finalNodeOfInitialPosition;
1774 finalNumChainsPerNode [nodeId] += 1;
1775 finalNumPositionsPerNode[nodeId] += exchangeStdVec[chainId].numberOfPositions;
1777 unsigned int finalMinPosPerNode = *std::min_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
1778 unsigned int finalMaxPosPerNode = *std::max_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
1779 double finalRatioOfPosPerNode = ((double) finalMaxPosPerNode ) / ((double) finalMinPosPerNode);
1781 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1782 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::justBalance_proc0()"
1784 <<
", step " << m_currStep
1785 <<
": solution gives the following redistribution"
1787 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1788 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::justBalance_proc0()"
1790 <<
", step " << m_currStep
1791 <<
", finalNumChainsPerNode[" << nodeId <<
"] = " << finalNumChainsPerNode[nodeId]
1792 <<
", finalNumPositionsPerNode[" << nodeId <<
"] = " << finalNumPositionsPerNode[nodeId]
1795 *m_env.subDisplayFile() <<
" KEY In MLSampling<P_V,P_M>::justBalance_proc0()"
1797 <<
", step " << m_currStep
1798 <<
", finalRatioOfPosPerNode = " << finalRatioOfPosPerNode
1806 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1807 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::justBalance_proc0()"
1809 <<
", step " << m_currStep
1810 <<
", iterId = " << iterId
1811 <<
", currRatioOfPosPerNode = " << currRatioOfPosPerNode
1812 <<
", after " << balRunTime <<
" seconds"
1819 template <
class P_V,
class P_M>
1823 const std::vector<ExchangeInfoStruct>& exchangeStdVec,
1824 const std::vector<unsigned int>& finalNumChainsPerNode,
1825 const std::vector<unsigned int>& finalNumPositionsPerNode,
1828 if (m_env.inter0Rank() < 0)
return;
1830 unsigned int Np = (
unsigned int) m_env.inter0Comm().NumProc();
1831 unsigned int Nc = exchangeStdVec.size();
1833 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1834 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::mpiExchangePositions_inter0()"
1836 <<
", step " << m_currStep
1847 for (
unsigned int r = 0; r < Np; ++r) {
1851 unsigned int numberOfInitialPositionsNodeRAlreadyHas = 0;
1852 std::vector<unsigned int> numberOfInitialPositionsNodeRHasToReceiveFromNode(Np,0);
1853 std::vector<unsigned int> indexesOfInitialPositionsNodeRHasToReceiveFromMe(0);
1855 unsigned int sumOfChainLenghtsNodeRAlreadyHas = 0;
1856 std::vector<unsigned int> chainLenghtsNodeRHasToInherit(0);
1858 for (
unsigned int i = 0; i < Nc; ++i) {
1859 if (exchangeStdVec[i].finalNodeOfInitialPosition == (
int) r) {
1860 if (exchangeStdVec[i].originalNodeOfInitialPosition == (
int) r) {
1861 numberOfInitialPositionsNodeRAlreadyHas++;
1862 sumOfChainLenghtsNodeRAlreadyHas += exchangeStdVec[i].numberOfPositions;
1865 numberOfInitialPositionsNodeRHasToReceiveFromNode[exchangeStdVec[i].originalNodeOfInitialPosition]++;
1866 chainLenghtsNodeRHasToInherit.push_back(exchangeStdVec[i].numberOfPositions);
1867 if (m_env.inter0Rank() == exchangeStdVec[i].originalNodeOfInitialPosition) {
1868 indexesOfInitialPositionsNodeRHasToReceiveFromMe.push_back(exchangeStdVec[i].originalIndexOfInitialPosition);
1874 unsigned int totalNumberOfInitialPositionsNodeRHasToReceive = 0;
1875 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1876 totalNumberOfInitialPositionsNodeRHasToReceive += numberOfInitialPositionsNodeRHasToReceiveFromNode[nodeId];
1879 unsigned int totalNumberOfChainLenghtsNodeRHasToInherit = chainLenghtsNodeRHasToInherit.size();
1880 unsigned int totalSumOfChainLenghtsNodeRHasToInherit = 0;
1881 for (
unsigned int i = 0; i < totalNumberOfChainLenghtsNodeRHasToInherit; ++i) {
1882 totalSumOfChainLenghtsNodeRHasToInherit += chainLenghtsNodeRHasToInherit[i];
1888 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
1889 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::mpiExchangePositions_inter0()"
1891 <<
", step " << m_currStep
1893 <<
", finalNumChainsPerNode[r] = " << finalNumChainsPerNode[r]
1894 <<
", totalNumberOfInitialPositionsNodeRHasToReceive = " << totalNumberOfInitialPositionsNodeRHasToReceive
1895 <<
", numberOfInitialPositionsNodeRAlreadyHas = " << numberOfInitialPositionsNodeRAlreadyHas
1897 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::mpiExchangePositions_inter0()"
1899 <<
", step " << m_currStep
1901 <<
", finalNumPositionsPerNode[r] = " << finalNumPositionsPerNode[r]
1902 <<
", totalSumOfChainLenghtsNodeRHasToInherit = " << totalSumOfChainLenghtsNodeRHasToInherit
1903 <<
", sumOfChainLenghtsNodeRAlreadyHas = " << sumOfChainLenghtsNodeRAlreadyHas
1910 UQ_FATAL_TEST_MACRO(indexesOfInitialPositionsNodeRHasToReceiveFromMe.size() != numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()],
1912 "MLSampling<P_V,P_M>::mpiExchangePositions_inter0()",
1913 "inconsistent number of initial positions to send to node 'r'");
1915 UQ_FATAL_TEST_MACRO(finalNumChainsPerNode[r] != (totalNumberOfInitialPositionsNodeRHasToReceive + numberOfInitialPositionsNodeRAlreadyHas),
1917 "MLSampling<P_V,P_M>::mpiExchangePositions_inter0()",
1918 "inconsistent number of chains in node 'r'");
1920 UQ_FATAL_TEST_MACRO(finalNumPositionsPerNode[r] != (totalSumOfChainLenghtsNodeRHasToInherit + sumOfChainLenghtsNodeRAlreadyHas),
1922 "MLSampling<P_V,P_M>::mpiExchangePositions_inter0()",
1923 "inconsistent sum of chain lenghts in node 'r'");
1925 UQ_FATAL_TEST_MACRO(totalNumberOfInitialPositionsNodeRHasToReceive != totalNumberOfChainLenghtsNodeRHasToInherit,
1927 "MLSampling<P_V,P_M>::mpiExchangePositions_inter0()",
1928 "inconsistent on total number of initial positions to receive in node 'r'");
1931 indexesOfInitialPositionsNodeRHasToReceiveFromMe.resize(numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()]);
1932 chainLenghtsNodeRHasToInherit.resize (totalSumOfChainLenghtsNodeRHasToInherit);
1937 unsigned int dimSize = m_vectorSpace.dimLocal();
1938 P_V auxInitialPosition(m_vectorSpace.zeroVector());
1939 std::vector<double> sendbuf(0);
1940 unsigned int sendcnt = 0;
1941 if (m_env.inter0Rank() != (int) r) {
1942 sendcnt = numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()] * dimSize;
1943 sendbuf.resize(sendcnt);
1944 for (
unsigned int i = 0; i < numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()]; ++i) {
1945 unsigned int auxIndex = indexesOfInitialPositionsNodeRHasToReceiveFromMe[i];
1947 for (
unsigned int j = 0; j < dimSize; ++j) {
1948 sendbuf[i*dimSize + j] = auxInitialPosition[j];
1953 std::vector<double> recvbuf(0);
1954 std::vector<int> recvcnts(Np,0);
1955 if (m_env.inter0Rank() == (int) r) {
1956 recvbuf.resize(totalNumberOfInitialPositionsNodeRHasToReceive * dimSize);
1957 for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
1958 recvcnts[nodeId] = numberOfInitialPositionsNodeRHasToReceiveFromNode[nodeId] * dimSize;
1962 std::vector<int> displs(Np,0);
1963 for (
unsigned int nodeId = 1; nodeId < Np; ++nodeId) {
1964 displs[nodeId] = displs[nodeId-1] + recvcnts[nodeId-1];
1968 if (m_env.inter0Rank() == r) {
1970 "MLSampling<P_V,P_M>::mpiExchangePositions_inter0(1)",
1971 "failed MPI.Gatherv()");
1975 "MLSampling<P_V,P_M>::mpiExchangePositions_inter0(2)",
1976 "failed MPI.Gatherv()");
1980 "MLSampling<P_V,P_M>::mpiExchangePositions_inter0()",
1981 "failed MPI.Gatherv()");
1993 if (m_env.inter0Rank() == (int) r) {
1995 unsigned int auxIndex = 0;
1997 for (
unsigned int i = 0; i < Nc; ++i) {
1998 if ((exchangeStdVec[i].finalNodeOfInitialPosition == (
int) r) &&
1999 (exchangeStdVec[i].originalNodeOfInitialPosition == (
int) r)) {
2000 prevChain.
getPositionValues(exchangeStdVec[i].originalIndexOfInitialPosition,auxInitialPosition);
2001 balancedLinkControl.
balLinkedChains[auxIndex].initialPosition =
new P_V(auxInitialPosition);
2002 balancedLinkControl.
balLinkedChains[auxIndex].numberOfPositions = exchangeStdVec[i].numberOfPositions;
2007 for (
unsigned int i = 0; i < totalNumberOfInitialPositionsNodeRHasToReceive; ++i) {
2008 for (
unsigned int j = 0; j < dimSize; ++j) {
2009 auxInitialPosition[j] = recvbuf[i*dimSize + j];
2011 balancedLinkControl.
balLinkedChains[auxIndex].initialPosition =
new P_V(auxInitialPosition);
2012 balancedLinkControl.
balLinkedChains[auxIndex].numberOfPositions = chainLenghtsNodeRHasToInherit[i];
2017 m_env.inter0Comm().Barrier();
2020 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2021 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::mpiExchangePositions_inter0()"
2023 <<
", step " << m_currStep
2031 template <
class P_V,
class P_M>
2034 double currExponent,
2040 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2041 *m_env.subDisplayFile() <<
"\n CHECKPOINTING initiating at level " << m_currLevel
2042 <<
"\n" << std::endl;
2049 unsigned int quantity2 = currLogLikelihoodValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2050 unsigned int quantity3 = currLogTargetValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2051 if (m_env.inter0Rank() >= 0) {
2054 "MLSampling<P_V,P_M>::checkpointML()",
2055 "number of evidence factors is not consistent");
2058 "MLSampling<P_V,P_M>::checkpointML()",
2059 "quantity2 is not consistent");
2062 "MLSampling<P_V,P_M>::checkpointML()",
2063 "quantity3 is not consistent");
2066 if (m_env.fullRank() == 0) {
2067 std::ofstream* ofsVar =
new std::ofstream((m_options.m_restartOutput_baseNameForFiles +
"Control.txt").c_str(),
2068 std::ofstream::out | std::ofstream::trunc);
2069 *ofsVar << m_currLevel << std::endl
2070 << m_vectorSpace.dimGlobal() << std::endl
2071 << currExponent << std::endl
2072 << currEta << std::endl
2073 << quantity1 << std::endl;
2074 unsigned int savedPrecision = ofsVar->precision();
2075 ofsVar->precision(16);
2076 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2077 *ofsVar << m_logEvidenceFactors[i] << std::endl;
2079 ofsVar->precision(savedPrecision);
2080 *ofsVar <<
"COMPLETE" << std::endl;
2084 m_env.fullComm().Barrier();
2089 char levelSufix[256];
2092 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2093 *m_env.subDisplayFile() <<
"\n CHECKPOINTING chain at level " << m_currLevel
2094 <<
"\n" << std::endl;
2096 currChain.
unifiedWriteContents(m_options.m_restartOutput_baseNameForFiles +
"Chain_l" + levelSufix,
2097 m_options.m_restartOutput_fileType);
2098 m_env.fullComm().Barrier();
2100 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2101 *m_env.subDisplayFile() <<
"\n CHECKPOINTING like at level " << m_currLevel
2102 <<
"\n" << std::endl;
2104 currLogLikelihoodValues.
unifiedWriteContents(m_options.m_restartOutput_baseNameForFiles +
"LogLike_l" + levelSufix,
2105 m_options.m_restartOutput_fileType);
2106 m_env.fullComm().Barrier();
2108 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2109 *m_env.subDisplayFile() <<
"\n CHECKPOINTING target at level " << m_currLevel
2110 <<
"\n" << std::endl;
2112 currLogTargetValues.
unifiedWriteContents(m_options.m_restartOutput_baseNameForFiles +
"LogTarget_l" + levelSufix,
2113 m_options.m_restartOutput_fileType);
2114 m_env.fullComm().Barrier();
2119 if (m_env.fullRank() == 0) {
2120 std::ofstream* ofsVar =
new std::ofstream((m_options.m_restartOutput_baseNameForFiles +
"Control_l" + levelSufix +
".txt").c_str(),
2121 std::ofstream::out | std::ofstream::trunc);
2122 *ofsVar << m_currLevel << std::endl
2123 << m_vectorSpace.dimGlobal() << std::endl
2124 << currExponent << std::endl
2125 << currEta << std::endl
2126 << quantity1 << std::endl;
2127 unsigned int savedPrecision = ofsVar->precision();
2128 ofsVar->precision(16);
2129 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2130 *ofsVar << m_logEvidenceFactors[i] << std::endl;
2132 ofsVar->precision(savedPrecision);
2133 *ofsVar <<
"COMPLETE" << std::endl;
2137 m_env.fullComm().Barrier();
2139 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2140 *m_env.subDisplayFile() <<
"\n CHECKPOINTING done at level " << m_currLevel
2141 <<
"\n" << std::endl;
2147 template <
class P_V,
class P_M>
2150 double& currExponent,
2156 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2157 *m_env.subDisplayFile() <<
"\n RESTARTING initiating at level " << m_currLevel
2158 <<
"\n" << std::endl;
2164 unsigned int vectorSpaceDim = 0;
2165 unsigned int quantity1 = 0;
2166 std::string checkingString(
"");
2167 if (m_env.fullRank() == 0) {
2168 std::ifstream* ifsVar =
new std::ifstream((m_options.m_restartInput_baseNameForFiles +
"Control.txt").c_str(),
2174 unsigned int numLines = std::count(std::istreambuf_iterator<char>(*ifsVar),
2175 std::istreambuf_iterator<char>(),
2177 ifsVar->seekg(0,std::ios_base::beg);
2178 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2179 *m_env.subDisplayFile() <<
"Restart input file has " << numLines
2187 *ifsVar >> m_currLevel;
2190 "MLSampling<P_V,P_M>::restartML()",
2191 "number of lines read is different than pre-established number of lines in control file");
2193 m_logEvidenceFactors.clear();
2194 m_logEvidenceFactors.resize(m_currLevel,0.);
2195 *ifsVar >> vectorSpaceDim
2199 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2200 *ifsVar >> m_logEvidenceFactors[i];
2202 *ifsVar >> checkingString;
2205 "MLSampling<P_V,P_M>::restartML()",
2206 "control txt input file is not complete");
2208 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2209 *m_env.subDisplayFile() <<
"Restart input file has the following information:"
2210 <<
"\n m_currLevel = " << m_currLevel
2211 <<
"\n vectorSpaceDim = " << vectorSpaceDim
2212 <<
"\n currExponent = " << currExponent
2213 <<
"\n currEta = " << currEta
2214 <<
"\n quantity1 = " << quantity1;
2215 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2216 *m_env.subDisplayFile() <<
"\n [" << i <<
"] = " << m_logEvidenceFactors[i];
2218 *m_env.subDisplayFile() << std::endl;
2221 #if 0 // For debug only
2222 std::string tmpString;
2223 for (
unsigned int i = 0; i < 2; ++i) {
2224 *ifsVar >> tmpString;
2225 std::cout <<
"Just read '" << tmpString <<
"'" << std::endl;
2227 while ((lineId < numLines) && (ifsVar->eof() ==
false)) {
2229 ifsVar->ignore(maxCharsPerLine,
'\n');
2234 m_env.fullComm().Barrier();
2239 unsigned int tmpUint = (
unsigned int) m_currLevel;
2241 "MLSampling<P_V,P_M>::restartML()",
2242 "failed MPI.Bcast() for m_currLevel");
2243 if (m_env.fullRank() != 0) {
2244 m_currLevel = tmpUint;
2251 if (m_env.fullRank() == 0) {
2252 tmpData[0] = vectorSpaceDim;
2253 tmpData[1] = currExponent;
2254 tmpData[2] = currEta;
2255 tmpData[3] = quantity1;
2256 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2257 tmpData[4+i] = m_logEvidenceFactors[i];
2261 m_logEvidenceFactors.clear();
2262 m_logEvidenceFactors.resize(m_currLevel,0.);
2264 m_env.fullComm().Bcast((
void *) &tmpData[0], (
int) tmpData.size(),
RawValue_MPI_DOUBLE, 0,
2265 "MLSampling<P_V,P_M>::restartML()",
2266 "failed MPI.Bcast() for rest of information read from input file");
2267 if (m_env.fullRank() != 0) {
2268 vectorSpaceDim = tmpData[0];
2269 currExponent = tmpData[1];
2270 currEta = tmpData[2];
2271 quantity1 = tmpData[3];
2272 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
2273 m_logEvidenceFactors[i] = tmpData[4+i];
2282 "MLSampling<P_V,P_M>::restartML()",
2283 "read vector space dimension is not consistent");
2286 "MLSampling<P_V,P_M>::restartML()",
2287 "read currExponent is not consistent");
2290 "MLSampling<P_V,P_M>::restartML()",
2291 "read size of chain should be a multiple of the number of subenvironments");
2292 unsigned int subSequenceSize = 0;
2293 subSequenceSize = ((double) quantity1) / ((double) m_env.numSubEnvironments());
2295 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2296 *m_env.subDisplayFile() <<
"Restart input file has the following information"
2297 <<
": subSequenceSize = " << subSequenceSize
2304 char levelSufix[256];
2307 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2308 *m_env.subDisplayFile() <<
"\n RESTARTING chain at level " << m_currLevel
2309 <<
"\n" << std::endl;
2311 currChain.
unifiedReadContents(m_options.m_restartInput_baseNameForFiles +
"Chain_l" + levelSufix,
2312 m_options.m_restartInput_fileType,
2314 m_env.fullComm().Barrier();
2316 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2317 *m_env.subDisplayFile() <<
"\n RESTARTING like at level " << m_currLevel
2318 <<
"\n" << std::endl;
2320 currLogLikelihoodValues.
unifiedReadContents(m_options.m_restartInput_baseNameForFiles +
"LogLike_l" + levelSufix,
2321 m_options.m_restartInput_fileType,
2323 m_env.fullComm().Barrier();
2325 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2326 *m_env.subDisplayFile() <<
"\n RESTARTING target at level " << m_currLevel
2327 <<
"\n" << std::endl;
2329 currLogTargetValues.
unifiedReadContents(m_options.m_restartInput_baseNameForFiles +
"LogTarget_l" + levelSufix,
2330 m_options.m_restartInput_fileType,
2332 m_env.fullComm().Barrier();
2334 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
2335 *m_env.subDisplayFile() <<
"\n RESTARTING done at level " << m_currLevel
2336 <<
"\n" << std::endl;
2342 template <
class P_V,
class P_M>
2346 unsigned int& unifiedRequestedNumSamples,
2351 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2352 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateSequence()"
2354 <<
", currOptions.m_rawChainSize = " << currOptions.
m_rawChainSize
2359 struct timeval timevalLevel;
2360 iRC = gettimeofday(&timevalLevel, NULL);
2363 if (m_env.inter0Rank() >= 0) {
2366 "MLSampling<P_V,P_M>::generateSequence()",
2367 "failed MPI.Allreduce() for requested num samples in level 0");
2374 currLogLikelihoodValues.
setName(currOptions.
m_prefix +
"rawLogLikelihood");
2381 P_V auxVec(m_vectorSpace.zeroVector());
2385 bool outOfSupport =
true;
2388 m_priorRv.realizer().realization(auxVec);
2389 if (m_numDisabledParameters > 0) {
2390 unsigned int disabledCounter = 0;
2391 for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
2392 if (m_parameterEnabledStatus[paramId] ==
false) {
2398 auxVec.mpiBcast(0, m_env.subComm());
2400 outOfSupport = !(m_targetDomain->contains(auxVec));
2401 }
while (outOfSupport);
2405 #if 1 // prudencio 2010-08-01
2406 currLogLikelihoodValues[i] = likelihoodSynchronizer.callFunction(&auxVec,NULL,NULL,NULL,NULL,NULL,NULL);
2408 currLogLikelihoodValues[i] = m_likelihoodFunction.lnValue(auxVec,NULL,NULL,NULL,NULL);
2410 currLogTargetValues[i] = m_priorRv.pdf().lnValue(auxVec,NULL,NULL,NULL,NULL) + currLogLikelihoodValues[i];
2414 if (m_env.inter0Rank() >= 0) {
2415 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
2416 if (currOptions.m_rawChainComputeStats) {
2425 currChain.computeStatistics(*currOptions.m_rawChainStatisticalOptionsObj,
2442 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2443 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2446 <<
" chain positions"
2462 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
2463 if (currOptions.m_filteredChainComputeStats) {
2478 "MLSampling<P_V,P_M>::generateSequence()",
2479 "currChain (first one) has been generated with invalid size");
2482 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2483 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2485 <<
", total level time = " << levelRunTime <<
" seconds"
2492 template <
class P_V,
class P_M>
2496 unsigned int& unifiedRequestedNumSamples)
2499 struct timeval timevalStep;
2500 iRC = gettimeofday(&timevalStep, NULL);
2503 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2504 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2506 <<
", step " << m_currStep
2507 <<
": beginning step 1 of 11"
2515 "MLSampling<P_V,P_M>::generateSequence()",
2516 "failed MPI.Allreduce() for requested num samples in step 1");
2518 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2519 *m_env.subDisplayFile() <<
"KEY In MLSampling<P_V,P_M>::generateSequence()"
2521 <<
", step " << m_currStep
2522 <<
", currOptions->m_rawChainSize = " << currOptions->
m_rawChainSize
2527 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2528 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
2530 <<
", step " << m_currStep
2531 <<
", after " << stepRunTime <<
" seconds"
2538 template <
class P_V,
class P_M>
2548 unsigned int& indexOfFirstWeight,
2549 unsigned int& indexOfLastWeight)
2552 struct timeval timevalStep;
2553 iRC = gettimeofday(&timevalStep, NULL);
2556 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2557 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2559 <<
", step " << m_currStep
2560 <<
": beginning step 2 of 11"
2564 prevChain = currChain;
2568 prevLogLikelihoodValues = currLogLikelihoodValues;
2569 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2570 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step()"
2572 <<
", step " << m_currStep
2573 <<
", prevLogLikelihoodValues[0] = " << prevLogLikelihoodValues[0]
2576 prevLogTargetValues = currLogTargetValues;
2578 currLogLikelihoodValues.
clear();
2579 currLogLikelihoodValues.
setName(currOptions->
m_prefix +
"rawLogLikelihood");
2581 currLogTargetValues.
clear();
2584 #if 0 // For debug only
2585 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2586 P_V prevPosition(m_vectorSpace.zeroVector());
2587 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2589 <<
", step " << m_currStep
2594 *m_env.subDisplayFile() <<
" prevChain[" << i
2595 <<
"] = " << prevPosition
2596 <<
", prevLogLikelihoodValues[" << i
2597 <<
"] = " << prevLogLikelihoodValues[i]
2598 <<
", prevLogTargetValues[" << i
2599 <<
"] = " << prevLogTargetValues[i]
2607 unsigned int quantity3 = prevLogLikelihoodValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2608 unsigned int quantity4 = currLogLikelihoodValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2609 unsigned int quantity5 = prevLogTargetValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2610 unsigned int quantity6 = currLogTargetValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2611 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2612 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2614 <<
", step " << m_currStep
2615 <<
": prevChain.unifiedSequenceSize() = " << quantity1
2616 <<
", currChain.unifiedSequenceSize() = " << quantity2
2617 <<
", prevLogLikelihoodValues.unifiedSequenceSize() = " << quantity3
2618 <<
", currLogLikelihoodValues.unifiedSequenceSize() = " << quantity4
2619 <<
", prevLogTargetValues.unifiedSequenceSize() = " << quantity5
2620 <<
", currLogTargetValues.unifiedSequenceSize() = " << quantity6
2626 "MLSampling<P_V,P_M>::generateSequence()",
2627 "different sizes between previous chain and previous sequence of likelihood values");
2631 "MLSampling<P_V,P_M>::generateSequence()",
2632 "different sizes between previous chain and previous sequence of target values");
2635 indexOfFirstWeight = 0;
2636 indexOfLastWeight = indexOfFirstWeight + prevChain.
subSequenceSize()-1;
2639 int r = m_env.inter0Rank();
2641 m_env.inter0Comm().Barrier();
2642 unsigned int auxUint = 0;
2647 "MLSampling<P_V,P_M>::generateSequence()",
2648 "failed MPI.Recv()");
2650 indexOfFirstWeight = auxUint;
2651 indexOfLastWeight = indexOfFirstWeight + prevChain.
subSequenceSize()-1;
2653 if (r < (m_env.inter0Comm().NumProc()-1)) {
2654 auxUint = indexOfLastWeight + 1;
2657 "MLSampling<P_V,P_M>::generateSequence()",
2658 "failed MPI.Send()");
2661 m_env.inter0Comm().Barrier();
2665 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2666 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
2668 <<
", step " << m_currStep
2669 <<
", after " << stepRunTime <<
" seconds"
2676 template <
class P_V,
class P_M>
2681 double prevExponent,
2682 double failedExponent,
2683 double& currExponent,
2687 struct timeval timevalStep;
2688 iRC = gettimeofday(&timevalStep, NULL);
2691 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2692 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2694 <<
", step " << m_currStep
2695 <<
", failedExponent = " << failedExponent
2696 <<
": beginning step 3 of 11"
2700 std::vector<double> exponents(2,0.);
2701 exponents[0] = prevExponent;
2704 double nowExponent = 1.;
2705 double nowEffectiveSizeRatio = 0.;
2707 unsigned int nowAttempt = 0;
2708 bool testResult =
false;
2712 double nowUnifiedEvidenceLnFactor = 0.;
2714 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2715 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2717 <<
", step " << m_currStep
2718 <<
", failedExponent = " << failedExponent
2719 <<
": entering loop for computing next exponent"
2720 <<
", with nowAttempt = " << nowAttempt
2724 if (failedExponent > 0.) {
2725 nowExponent = .5*(prevExponent+failedExponent);
2728 if (nowAttempt > 0) {
2729 if (nowEffectiveSizeRatio > meanEffectiveSizeRatio) {
2730 exponents[0] = nowExponent;
2733 exponents[1] = nowExponent;
2735 nowExponent = .5*(exponents[0] + exponents[1]);
2738 double auxExponent = nowExponent;
2739 if (prevExponent != 0.) {
2740 auxExponent /= prevExponent;
2743 double subWeightRatioSum = 0.;
2744 double unifiedWeightRatioSum = 0.;
2747 omegaLnDiffSequence[i] = prevLogLikelihoodValues[i]*auxExponent;
2750 #if 1 // prudenci-2012-07-06
2752 double unifiedOmegaLnMax = omegaLnDiffSequence.
unifiedMaxPlain(m_vectorSpace.numOfProcsForStorage() == 1);
2754 double unifiedOmegaLnMin = 0.;
2755 double unifiedOmegaLnMax = 0.;
2756 omegaLnDiffSequence.unifiedMinMaxExtra(m_vectorSpace.numOfProcsForStorage() == 1,
2758 omegaLnDiffSequence.subSequenceSize(),
2763 omegaLnDiffSequence[i] -= unifiedOmegaLnMax;
2764 weightSequence[i] = exp(omegaLnDiffSequence[i]);
2765 subWeightRatioSum += weightSequence[i];
2766 #if 0 // For debug only
2767 if ((m_currLevel == 1) && (nowAttempt == 6)) {
2768 if (m_env.subDisplayFile() && (m_env.displayVerbosity() >= 99)) {
2769 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2771 <<
", step " << m_currStep
2773 <<
", prevLogLikelihoodValues[i] = " << prevLogLikelihoodValues[i]
2774 <<
", omegaLnDiffSequence[i] = " << omegaLnDiffSequence[i]
2775 <<
", weightSequence[i] = " << weightSequence[i]
2783 "MLSampling<P_V,P_M>::generateSequence()",
2784 "failed MPI.Allreduce() for weight ratio sum");
2786 unsigned int auxQuantity = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2787 nowUnifiedEvidenceLnFactor = log(unifiedWeightRatioSum) + unifiedOmegaLnMax - log(auxQuantity);
2789 double effectiveSampleSize = 0.;
2791 weightSequence[i] /= unifiedWeightRatioSum;
2792 effectiveSampleSize += weightSequence[i]*weightSequence[i];
2803 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2804 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2806 <<
", step " << m_currStep
2807 <<
": nowAttempt = " << nowAttempt
2808 <<
", prevExponent = " << prevExponent
2809 <<
", exponents[0] = " << exponents[0]
2810 <<
", nowExponent = " << nowExponent
2811 <<
", exponents[1] = " << exponents[1]
2812 <<
", subWeightRatioSum = " << subWeightRatioSum
2813 <<
", unifiedWeightRatioSum = " << unifiedWeightRatioSum
2814 <<
", unifiedOmegaLnMax = " << unifiedOmegaLnMax
2815 <<
", weightSequence.unifiedSequenceSize() = " << auxQuantity
2816 <<
", nowUnifiedEvidenceLnFactor = " << nowUnifiedEvidenceLnFactor
2817 <<
", effectiveSampleSize = " << effectiveSampleSize
2821 #if 0 // For debug only
2822 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2823 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2825 <<
", step " << m_currStep
2830 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2831 *m_env.subDisplayFile() <<
" weightSequence[" << i
2832 <<
"] = " << weightSequence[i]
2838 double subQuantity = effectiveSampleSize;
2839 effectiveSampleSize = 0.;
2841 "MLSampling<P_V,P_M>::generateSequence()",
2842 "failed MPI.Allreduce() for effective sample size");
2844 effectiveSampleSize = 1./effectiveSampleSize;
2845 nowEffectiveSizeRatio = effectiveSampleSize/((double) weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1));
2848 "MLSampling<P_V,P_M>::generateSequence()",
2849 "effective sample size ratio cannot be > 1");
2855 if (failedExponent > 0.) {
2860 bool aux2 = (nowExponent == 1. )
2862 (nowEffectiveSizeRatio > meanEffectiveSizeRatio);
2865 (nowEffectiveSizeRatio <= currOptions->m_maxEffectiveSizeRatio);
2866 testResult = aux2 || aux3;
2869 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2870 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2872 <<
", step " << m_currStep
2873 <<
": nowAttempt = " << nowAttempt
2874 <<
", prevExponent = " << prevExponent
2875 <<
", failedExponent = " << failedExponent
2876 <<
", exponents[0] = " << exponents[0]
2877 <<
", nowExponent = " << nowExponent
2878 <<
", exponents[1] = " << exponents[1]
2879 <<
", effectiveSampleSize = " << effectiveSampleSize
2882 <<
", nowEffectiveSizeRatio = " << nowEffectiveSizeRatio
2886 <<
", testResult = " << testResult
2895 "MLSampling<P_V,P_M>::generateSequence(), step 3, nowExponent") ==
false) {
2896 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2897 *m_env.subDisplayFile() <<
"WARNING, In MLSampling<P_V,P_M>::generateSequence()"
2899 <<
", step " << m_currStep
2900 <<
": nowAttempt = " << nowAttempt
2901 <<
", MiscCheck for 'nowExponent' detected a problem"
2910 "MLSampling<P_V,P_M>::generateSequence(), step 3, testResult") ==
false) {
2911 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2912 *m_env.subDisplayFile() <<
"WARNING, In MLSampling<P_V,P_M>::generateSequence()"
2914 <<
", step " << m_currStep
2915 <<
": nowAttempt = " << nowAttempt
2916 <<
", MiscCheck for 'testResult' detected a problem"
2920 }
while (testResult ==
false);
2921 currExponent = nowExponent;
2922 if (failedExponent > 0.) {
2923 m_logEvidenceFactors[m_logEvidenceFactors.size()-1] = nowUnifiedEvidenceLnFactor;
2926 m_logEvidenceFactors.push_back(nowUnifiedEvidenceLnFactor);
2929 unsigned int quantity1 = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
2930 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2931 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2933 <<
", step " << m_currStep
2934 <<
": weightSequence.subSequenceSize() = " << weightSequence.
subSequenceSize()
2935 <<
", weightSequence.unifiedSequenceSize() = " << quantity1
2936 <<
", failedExponent = " << failedExponent
2937 <<
", currExponent = " << currExponent
2938 <<
", effective ratio = " << nowEffectiveSizeRatio
2939 <<
", log(evidence factor) = " << m_logEvidenceFactors[m_logEvidenceFactors.size()-1]
2940 <<
", evidence factor = " << exp(m_logEvidenceFactors[m_logEvidenceFactors.size()-1])
2958 "MLSampling<P_V,P_M>::generateSequence(), step 3, logEvidenceFactor") ==
false) {
2959 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2960 *m_env.subDisplayFile() <<
"WARNING, In MLSampling<P_V,P_M>::generateSequence()"
2962 <<
", step " << m_currStep
2963 <<
", failedExponent = " << failedExponent
2964 <<
": nowAttempt = " << nowAttempt
2965 <<
", MiscCheck for 'logEvidenceFactor' detected a problem"
2971 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2972 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
2974 <<
", step " << m_currStep
2975 <<
", failedExponent = " << failedExponent
2976 <<
", after " << stepRunTime <<
" seconds"
2983 template <
class P_V,
class P_M>
2988 P_M& unifiedCovMatrix)
2991 struct timeval timevalStep;
2992 iRC = gettimeofday(&timevalStep, NULL);
2995 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
2996 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
2998 <<
", step " << m_currStep
2999 <<
": beginning step 4 of 11"
3003 P_V auxVec(m_vectorSpace.zeroVector());
3004 P_V subWeightedMeanVec(m_vectorSpace.zeroVector());
3007 subWeightedMeanVec += weightSequence[i]*auxVec;
3011 P_V unifiedWeightedMeanVec(m_vectorSpace.zeroVector());
3012 if (m_env.inter0Rank() >= 0) {
3013 subWeightedMeanVec.mpiAllReduce(
RawValue_MPI_SUM,m_env.inter0Comm(),unifiedWeightedMeanVec);
3016 unifiedWeightedMeanVec = subWeightedMeanVec;
3019 P_V diffVec(m_vectorSpace.zeroVector());
3020 P_M subCovMatrix(m_vectorSpace.zeroVector());
3023 diffVec = auxVec - unifiedWeightedMeanVec;
3024 subCovMatrix += weightSequence[i]*
matrixProduct(diffVec,diffVec);
3027 for (
unsigned int i = 0; i < unifiedCovMatrix.numRowsLocal(); ++i) {
3028 for (
unsigned int j = 0; j < unifiedCovMatrix.numCols(); ++j) {
3029 double localValue = subCovMatrix(i,j);
3030 double sumValue = 0.;
3031 if (m_env.inter0Rank() >= 0) {
3033 "MLSampling<P_V,P_M>::generateSequence()",
3034 "failed MPI.Allreduce() for cov matrix");
3037 sumValue = localValue;
3039 unifiedCovMatrix(i,j) = sumValue;
3043 if (m_numDisabledParameters > 0) {
3044 for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
3045 if (m_parameterEnabledStatus[paramId] ==
false) {
3046 for (
unsigned int i = 0; i < m_vectorSpace.dimLocal(); ++i) {
3047 unifiedCovMatrix(i,paramId) = 0.;
3049 for (
unsigned int j = 0; j < m_vectorSpace.dimLocal(); ++j) {
3050 unifiedCovMatrix(paramId,j) = 0.;
3052 unifiedCovMatrix(paramId,paramId) = 1.;
3057 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3058 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3060 <<
", step " << m_currStep
3061 <<
": unifiedCovMatrix = " << unifiedCovMatrix
3066 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3067 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3069 <<
", step " << m_currStep
3070 <<
", after " << stepRunTime <<
" seconds"
3077 template <
class P_V,
class P_M>
3080 unsigned int unifiedRequestedNumSamples,
3082 std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
3083 std::vector<double>& unifiedWeightStdVectorAtProc0Only)
3086 struct timeval timevalStep;
3087 iRC = gettimeofday(&timevalStep, NULL);
3090 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3091 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3093 <<
", step " << m_currStep
3094 <<
": beginning step 5 of 11"
3098 #if 0 // For debug only
3099 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3100 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3102 <<
", step " << m_currStep
3103 <<
", before weightSequence.getUnifiedContentsAtProc0Only()"
3108 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3109 *m_env.subDisplayFile() <<
", weightSequence[" << i
3110 <<
"] = " << weightSequence[i]
3117 unifiedWeightStdVectorAtProc0Only);
3119 #if 0 // For debug only
3120 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3121 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3123 <<
", step " << m_currStep
3124 <<
", after weightSequence.getUnifiedContentsAtProc0Only()"
3128 for (
unsigned int i = 0; i < unifiedWeightStdVectorAtProc0Only.size(); ++i) {
3129 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3130 *m_env.subDisplayFile() <<
" unifiedWeightStdVectorAtProc0Only[" << i
3131 <<
"] = " << unifiedWeightStdVectorAtProc0Only[i]
3136 sampleIndexes_proc0(unifiedRequestedNumSamples,
3137 unifiedWeightStdVectorAtProc0Only,
3138 unifiedIndexCountersAtProc0Only);
3140 unsigned int auxUnifiedSize = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
3141 if (m_env.inter0Rank() == 0) {
3144 "MLSampling<P_V,P_M>::generateSequence()",
3145 "wrong output from sampleIndexesAtProc0() in step 5");
3149 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3150 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3152 <<
", step " << m_currStep
3153 <<
", after " << stepRunTime <<
" seconds"
3160 template <
class P_V,
class P_M>
3164 unsigned int indexOfFirstWeight,
3165 unsigned int indexOfLastWeight,
3166 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
3167 bool& useBalancedChains,
3168 std::vector<ExchangeInfoStruct>& exchangeStdVec)
3171 struct timeval timevalStep;
3172 iRC = gettimeofday(&timevalStep, NULL);
3175 useBalancedChains = decideOnBalancedChains_all(currOptions,
3178 unifiedIndexCountersAtProc0Only,
3182 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3183 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3185 <<
", step " << m_currStep
3186 <<
", after " << stepRunTime <<
" seconds"
3193 template <
class P_V,
class P_M>
3196 bool useBalancedChains,
3197 unsigned int indexOfFirstWeight,
3198 unsigned int indexOfLastWeight,
3199 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
3203 std::vector<ExchangeInfoStruct>& exchangeStdVec,
3207 struct timeval timevalStep;
3208 iRC = gettimeofday(&timevalStep, NULL);
3211 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3212 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3214 <<
", step " << m_currStep
3215 <<
": beginning step 7 of 11"
3219 if (useBalancedChains) {
3220 prepareBalLinkedChains_inter0(currOptions,
3223 balancedLinkControl);
3226 prepareUnbLinkedChains_inter0(indexOfFirstWeight,
3228 unifiedIndexCountersAtProc0Only,
3229 unbalancedLinkControl);
3232 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3233 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3235 <<
", step " << m_currStep
3236 <<
": balancedLinkControl.balLinkedChains.size() = " << balancedLinkControl.
balLinkedChains.size()
3237 <<
", unbalancedLinkControl.unbLinkedChains.size() = " << unbalancedLinkControl.
unbLinkedChains.size()
3242 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3243 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3245 <<
", step " << m_currStep
3246 <<
", after " << stepRunTime <<
" seconds"
3253 template <
class P_V,
class P_M>
3260 struct timeval timevalStep;
3261 iRC = gettimeofday(&timevalStep, NULL);
3264 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3265 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3267 <<
", step " << m_currStep
3268 <<
": beginning step 8 of 11"
3275 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3276 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3278 <<
", step " << m_currStep
3279 <<
", after " << stepRunTime <<
" seconds"
3286 template <
class P_V,
class P_M>
3290 unsigned int indexOfFirstWeight,
3291 unsigned int indexOfLastWeight,
3292 const std::vector<double>& unifiedWeightStdVectorAtProc0Only,
3297 P_M& unifiedCovMatrix,
3301 struct timeval timevalStep;
3302 iRC = gettimeofday(&timevalStep, NULL);
3306 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3307 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3309 <<
", step " << m_currStep
3310 <<
": skipping step 9 of 11"
3315 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3316 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3318 <<
", step " << m_currStep
3319 <<
": beginning step 9 of 11"
3323 double beforeEta = prevEta;
3324 double beforeRejectionRate = 0.;
3325 bool beforeRejectionRateIsBelowRange =
true;
3327 double nowEta = prevEta;
3328 double nowRejectionRate = 0.;
3329 bool nowRejectionRateIsBelowRange =
true;
3331 std::vector<double> etas(2,0.);
3332 etas[0] = beforeEta;
3335 std::vector<double> rejs(2,0.);
3339 unsigned int nowAttempt = 0;
3340 bool testResult =
false;
3342 bool useMiddlePointLogicForEta =
false;
3343 P_M nowCovMatrix(unifiedCovMatrix);
3344 #if 0 // KAUST, to check
3345 std::vector<double> unifiedWeightStdVectorAtProc0Only(0);
3347 unifiedWeightStdVectorAtProc0Only);
3350 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3351 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3353 <<
", step " << m_currStep
3354 <<
": entering loop for assessing rejection rate"
3355 <<
", with nowAttempt = " << nowAttempt
3356 <<
", nowRejectionRate = " << nowRejectionRate
3359 nowCovMatrix = unifiedCovMatrix;
3361 if (nowRejectionRate < currOptions->m_minRejectionRate) {
3362 nowRejectionRateIsBelowRange =
true;
3365 nowRejectionRateIsBelowRange =
false;
3370 "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
3371 "nowRejectionRate should be out of the requested range at this point of the logic");
3374 if (m_env.inter0Rank() >= 0) {
3375 if (nowAttempt > 0) {
3376 if (useMiddlePointLogicForEta ==
false) {
3377 if (nowAttempt == 1) {
3380 else if ((beforeRejectionRateIsBelowRange ==
true) &&
3381 (nowRejectionRateIsBelowRange ==
true)) {
3384 else if ((beforeRejectionRateIsBelowRange ==
false) &&
3385 (nowRejectionRateIsBelowRange ==
false)) {
3388 else if ((beforeRejectionRateIsBelowRange ==
true ) &&
3389 (nowRejectionRateIsBelowRange ==
false)) {
3390 useMiddlePointLogicForEta =
true;
3393 etas[0] = std::min(beforeEta,nowEta);
3394 etas[1] = std::max(beforeEta,nowEta);
3396 if (etas[0] == beforeEta) {
3397 rejs[0] = beforeRejectionRate;
3398 rejs[1] = nowRejectionRate;
3401 rejs[0] = nowRejectionRate;
3402 rejs[1] = beforeRejectionRate;
3405 else if ((beforeRejectionRateIsBelowRange ==
false) &&
3406 (nowRejectionRateIsBelowRange ==
true )) {
3407 useMiddlePointLogicForEta =
true;
3410 etas[0] = std::min(beforeEta,nowEta);
3411 etas[1] = std::max(beforeEta,nowEta);
3416 "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
3417 "before and now range flags are inconsistent");
3422 beforeRejectionRate = nowRejectionRate;
3423 beforeRejectionRateIsBelowRange = nowRejectionRateIsBelowRange;
3424 if (useMiddlePointLogicForEta ==
false) {
3425 if (beforeRejectionRateIsBelowRange) nowEta *= 4.;
3427 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3428 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3430 <<
", step " << m_currStep
3431 <<
": in loop for assessing rejection rate"
3432 <<
", with nowAttempt = " << nowAttempt
3433 <<
", useMiddlePointLogicForEta = false"
3434 <<
", nowEta just updated to value (to be tested) " << nowEta
3439 if (nowRejectionRate > meanRejectionRate) {
3440 if (rejs[0] > meanRejectionRate) {
3450 if (rejs[0] < meanRejectionRate) {
3459 nowEta = .5*(etas[0] + etas[1]);
3460 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3461 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3463 <<
", step " << m_currStep
3464 <<
": in loop for assessing rejection rate"
3465 <<
", with nowAttempt = " << nowAttempt
3466 <<
", useMiddlePointLogicForEta = true"
3467 <<
", nowEta just updated to value (to be tested) " << nowEta
3468 <<
", etas[0] = " << etas[0]
3469 <<
", etas[1] = " << etas[1]
3476 nowCovMatrix *= nowEta;
3480 unsigned int originalSubNumSamples = 1 + (
unsigned int) (doubSubNumSamples);
3481 double auxDouble = (double) originalSubNumSamples;
3482 if ((auxDouble - doubSubNumSamples) < 1.e-8) {
3483 originalSubNumSamples += 1;
3486 if (m_env.inter0Rank() >= 0) {
3487 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3488 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3490 <<
", step " << m_currStep
3491 <<
": in loop for assessing rejection rate"
3492 <<
", about to sample " << originalSubNumSamples <<
" indexes"
3493 <<
", meanRejectionRate = " << meanRejectionRate
3499 std::vector<unsigned int> nowUnifiedIndexCountersAtProc0Only(0);
3500 if (m_env.inter0Rank() >= 0) {
3501 unsigned int tmpUnifiedNumSamples = originalSubNumSamples*m_env.inter0Comm().NumProc();
3502 sampleIndexes_proc0(tmpUnifiedNumSamples,
3503 unifiedWeightStdVectorAtProc0Only,
3504 nowUnifiedIndexCountersAtProc0Only);
3506 unsigned int auxUnifiedSize = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
3507 if (m_env.inter0Rank() == 0) {
3510 "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
3511 "wrong output from sampleIndexesAtProc0() in step 9");
3514 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3515 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3517 <<
", step " << m_currStep
3518 <<
": in loop for assessing rejection rate"
3519 <<
", about to distribute sampled assessment indexes"
3524 std::vector<ExchangeInfoStruct> exchangeStdVec(0);
3529 bool useBalancedChains = decideOnBalancedChains_all(currOptions,
3532 nowUnifiedIndexCountersAtProc0Only,
3535 if (m_env.inter0Rank() >= 0) {
3536 if (useBalancedChains) {
3537 prepareBalLinkedChains_inter0(currOptions,
3543 prepareUnbLinkedChains_inter0(indexOfFirstWeight,
3545 nowUnifiedIndexCountersAtProc0Only,
3550 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3551 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3553 <<
", step " << m_currStep
3554 <<
": in loop for assessing rejection rate"
3555 <<
", about to generate assessment chain"
3561 m_options.m_prefix+
"now_chain");
3562 double nowRunTime = 0.;
3563 unsigned int nowRejections = 0;
3568 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3569 bool savedRawChainComputeStats = currOptions->m_rawChainComputeStats;
3576 if (m_env.displayVerbosity() >= 999999) {
3580 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3581 currOptions->m_rawChainComputeStats =
false;
3588 if (useBalancedChains) {
3589 generateBalLinkedChains_all(*currOptions,
3600 generateUnbLinkedChains_all(*currOptions,
3616 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3617 currOptions->m_rawChainComputeStats = savedRawChainComputeStats;
3623 for (
unsigned int i = 0; i < nowBalLinkControl.
balLinkedChains.size(); ++i) {
3626 "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
3627 "Initial position pointer in step 9 should not be NULL");
3633 if (m_env.inter0Rank() >= 0) {
3635 unsigned int nowUnifiedRejections = 0;
3637 "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
3638 "failed MPI.Allreduce() for now rejections");
3640 #if 0 // Round Rock 2009 12 29
3641 unsigned int tmpUnifiedNumSamples = 0;
3643 "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
3644 "failed MPI.Allreduce() for num samples in step 9");
3647 unsigned int tmpUnifiedNumSamples = originalSubNumSamples*m_env.inter0Comm().NumProc();
3648 nowRejectionRate = ((double) nowUnifiedRejections) / ((double) tmpUnifiedNumSamples);
3653 (nowRejectionRate <= currOptions->m_maxRejectionRate);
3660 "MLSampling<P_V,P_M>::generateSequence_Step09_all(), step 9, testResult") ==
false) {
3661 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3662 *m_env.subDisplayFile() <<
"WARNING, In MLSampling<P_V,P_M>::generateSequence()"
3664 <<
", step " << m_currStep
3665 <<
": nowAttempt = " << nowAttempt
3666 <<
", MiscCheck for 'testResult' detected a problem"
3673 unsigned int tmpUint = (
unsigned int) testResult;
3675 "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
3676 "failed MPI.Bcast() for testResult");
3677 testResult = (bool) tmpUint;
3679 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3680 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3682 <<
", step " << m_currStep
3683 <<
": in loop for assessing rejection rate"
3684 <<
", nowAttempt = " << nowAttempt
3685 <<
", beforeEta = " << beforeEta
3686 <<
", etas[0] = " << etas[0]
3687 <<
", nowEta = " << nowEta
3688 <<
", etas[1] = " << etas[1]
3690 <<
", nowRejectionRate = " << nowRejectionRate
3696 if (m_env.inter0Rank() >= 0) {
3701 "MLSampling<P_V,P_M>::generateSequence_Step09_all(), step 9, nowEta") ==
false) {
3702 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3703 *m_env.subDisplayFile() <<
"WARNING, In MLSampling<P_V,P_M>::generateSequence()"
3705 <<
", step " << m_currStep
3706 <<
": nowAttempt = " << nowAttempt
3707 <<
", MiscCheck for 'nowEta' detected a problem"
3712 }
while (testResult ==
false);
3714 if (currEta != 1.) {
3715 unifiedCovMatrix *= currEta;
3716 if (m_numDisabledParameters > 0) {
3717 for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
3718 if (m_parameterEnabledStatus[paramId] ==
false) {
3719 for (
unsigned int i = 0; i < m_vectorSpace.dimLocal(); ++i) {
3720 unifiedCovMatrix(i,paramId) = 0.;
3722 for (
unsigned int j = 0; j < m_vectorSpace.dimLocal(); ++j) {
3723 unifiedCovMatrix(paramId,j) = 0.;
3725 unifiedCovMatrix(paramId,paramId) = 1.;
3731 unsigned int quantity1 = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
3732 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3733 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()"
3735 <<
", step " << m_currStep
3736 <<
": weightSequence.subSequenceSize() = " << weightSequence.
subSequenceSize()
3737 <<
", weightSequence.unifiedSequenceSize() = " << quantity1
3738 <<
", currEta = " << currEta
3739 <<
", assessed rejection rate = " << nowRejectionRate
3745 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3746 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3748 <<
", step " << m_currStep
3749 <<
", after " << stepRunTime <<
" seconds"
3756 template <
class P_V,
class P_M>
3760 const P_M& unifiedCovMatrix,
3762 bool useBalancedChains,
3764 unsigned int indexOfFirstWeight,
3768 double& cumulativeRawChainRunTime,
3769 unsigned int& cumulativeRawChainRejections,
3774 struct timeval timevalStep;
3775 iRC = gettimeofday(&timevalStep, NULL);
3778 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3779 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3781 <<
", step " << m_currStep
3782 <<
": beginning step 10 of 11"
3783 <<
", currLogLikelihoodValues = " << currLogLikelihoodValues
3790 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3791 bool savedRawChainComputeStats = currOptions.m_rawChainComputeStats;
3796 if (m_env.displayVerbosity() >= 999999) {
3800 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3801 currOptions.m_rawChainComputeStats =
false;
3806 if (useBalancedChains) {
3807 generateBalLinkedChains_all(currOptions,
3810 balancedLinkControl,
3812 cumulativeRawChainRunTime,
3813 cumulativeRawChainRejections,
3814 currLogLikelihoodValues,
3815 currLogTargetValues);
3818 generateUnbLinkedChains_all(currOptions,
3821 unbalancedLinkControl,
3825 cumulativeRawChainRunTime,
3826 cumulativeRawChainRejections,
3827 currLogLikelihoodValues,
3828 currLogTargetValues);
3831 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3832 double tmpValue = INFINITY;
3833 if (currLogLikelihoodValues) tmpValue = (*currLogLikelihoodValues)[0];
3834 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step()"
3836 <<
", step " << m_currStep
3837 <<
", after chain generatrion"
3838 <<
", currLogLikelihoodValues[0] = " << tmpValue
3845 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3846 currOptions.m_rawChainComputeStats = savedRawChainComputeStats;
3851 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3852 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
3854 <<
", step " << m_currStep
3855 <<
", after " << stepRunTime <<
" seconds"
3862 template <
class P_V,
class P_M>
3866 unsigned int unifiedRequestedNumSamples,
3867 unsigned int cumulativeRawChainRejections,
3871 unsigned int& unifiedNumberOfRejections)
3874 struct timeval timevalStep;
3875 iRC = gettimeofday(&timevalStep, NULL);
3878 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3879 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
3881 <<
", step " << m_currStep
3882 <<
": beginning step 11 of 11"
3888 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3889 if (currOptions->m_rawChainComputeStats) {
3897 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
3898 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step()"
3900 <<
", step " << m_currStep
3901 <<
", calling computeStatistics for raw chain"
3902 <<
". Ofstream pointer value = " << filePtrSet.
ofsVar
3903 <<
", statistical options are"
3904 <<
"\n" << *currOptions->m_rawChainStatisticalOptionsObj
3908 currChain.computeStatistics(*currOptions->m_rawChainStatisticalOptionsObj,
3919 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
3920 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step()"
3922 <<
", step " << m_currStep
3923 <<
", before calling currLogLikelihoodValues.unifiedWriteContents()"
3924 <<
", currLogLikelihoodValues[0] = " << currLogLikelihoodValues[0]
3943 if (filterSpacing == 0) {
3950 currChain.
filter(filterInitialPos,
3954 currLogLikelihoodValues.
filter(filterInitialPos,
3956 currLogLikelihoodValues.
setName(currOptions->
m_prefix +
"filtLogLikelihood");
3958 currLogTargetValues.
filter(filterInitialPos,
3962 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
3963 if (currOptions->m_filteredChainComputeStats) {
3964 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) {
3965 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence_Step()"
3967 <<
", step " << m_currStep
3968 <<
", calling computeStatistics for filtered chain"
3969 <<
". Ofstream pointer value = " << filePtrSet.
ofsVar
3970 <<
", statistical options are"
3971 <<
"\n" << *currOptions->m_rawChainStatisticalOptionsObj
3976 currChain.computeStatistics(*currOptions->m_filteredChainStatisticalOptionsObj,
4001 unsigned int unifiedGeneratedNumSamples = 0;
4003 "MLSampling<P_V,P_M>::generateSequence()",
4004 "failed MPI.Allreduce() for generated num samples in step 11");
4010 "MLSampling<P_V,P_M>::generateSequence()",
4011 "currChain (linked one) has been generated with invalid size");
4016 "MLSampling<P_V,P_M>::generateSequence()",
4017 "failed MPI.Allreduce() for number of rejections");
4020 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4021 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()"
4023 <<
", step " << m_currStep
4024 <<
", after " << stepRunTime <<
" seconds"
4032 template<
class P_V,
class P_M>
4038 m_env (priorRv.env()),
4039 m_priorRv (priorRv),
4040 m_likelihoodFunction(likelihoodFunction),
4041 m_vectorSpace (m_priorRv.imageSet().vectorSpace()),
4043 m_numDisabledParameters (0),
4044 m_parameterEnabledStatus(m_vectorSpace.dimLocal(),true),
4045 m_options (m_env,prefix),
4048 m_debugExponent (0.),
4049 m_logEvidenceFactors(0),
4051 m_meanLogLikelihood (0.),
4067 template<
class P_V,
class P_M>
4070 m_numDisabledParameters = 0;
4071 m_parameterEnabledStatus.clear();
4072 if (m_targetDomain)
delete m_targetDomain;
4078 template <
class P_V,
class P_M>
4085 struct timeval timevalRoutineBegin;
4087 iRC = gettimeofday(&timevalRoutineBegin, NULL);
4090 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4091 *m_env.subDisplayFile() <<
"Entering MLSampling<P_V,P_M>::generateSequence()"
4092 <<
", at " << ctime(&timevalRoutineBegin.tv_sec)
4093 <<
", after " << timevalRoutineBegin.tv_sec - m_env.timevalBegin().tv_sec
4094 <<
" seconds from queso environment instatiation..."
4101 double currExponent = 0.;
4102 double currEta = 1.;
4103 unsigned int currUnifiedRequestedNumSamples = 0;
4106 m_options.m_prefix+
"curr_chain");
4114 bool stopAtEndOfLevel =
false;
4115 char levelPrefix[256];
4126 if (m_options.m_restartInput_baseNameForFiles !=
".") {
4127 restartML(currExponent,
4130 currLogLikelihoodValues,
4131 currLogTargetValues);
4133 if (currExponent == 1.) {
4134 if (lastLevelOptions.m_parameterDisabledSet.size() > 0) {
4135 for (std::set<unsigned int>::iterator setIt = lastLevelOptions.m_parameterDisabledSet.begin(); setIt != lastLevelOptions.m_parameterDisabledSet.end(); ++setIt) {
4136 unsigned int paramId = *setIt;
4137 if (paramId < m_vectorSpace.dimLocal()) {
4138 m_numDisabledParameters++;
4139 m_parameterEnabledStatus[paramId] =
false;
4144 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
4145 if (lastLevelOptions.m_rawChainComputeStats) {
4147 m_env.openOutputFile(lastLevelOptions.m_dataOutputFileName,
4149 lastLevelOptions.m_dataOutputAllowedSet,
4153 currChain.computeStatistics(*lastLevelOptions.m_rawChainStatisticalOptionsObj,
4163 currChain.
unifiedWriteContents (lastLevelOptions.m_rawChainDataOutputFileName,lastLevelOptions.m_rawChainDataOutputFileType);
4164 currLogLikelihoodValues.
unifiedWriteContents(lastLevelOptions.m_rawChainDataOutputFileName,lastLevelOptions.m_rawChainDataOutputFileType);
4165 currLogTargetValues.
unifiedWriteContents (lastLevelOptions.m_rawChainDataOutputFileName,lastLevelOptions.m_rawChainDataOutputFileType);
4168 if (lastLevelOptions.m_filteredChainGenerate) {
4170 m_env.openOutputFile(lastLevelOptions.m_dataOutputFileName,
4172 lastLevelOptions.m_dataOutputAllowedSet,
4176 unsigned int filterInitialPos = (
unsigned int) (lastLevelOptions.m_filteredChainDiscardedPortion * (
double) currChain.
subSequenceSize());
4177 unsigned int filterSpacing = lastLevelOptions.m_filteredChainLag;
4178 if (filterSpacing == 0) {
4185 currChain.
filter(filterInitialPos,
4187 currChain.
setName(lastLevelOptions.m_prefix +
"filtChain");
4189 currLogLikelihoodValues.
filter(filterInitialPos,
4191 currLogLikelihoodValues.
setName(lastLevelOptions.m_prefix +
"filtLogLikelihood");
4193 currLogTargetValues.
filter(filterInitialPos,
4195 currLogTargetValues.
setName(lastLevelOptions.m_prefix +
"filtLogTarget");
4197 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS
4198 if (lastLevelOptions.m_filteredChainComputeStats) {
4199 currChain.computeStatistics(*lastLevelOptions.m_filteredChainStatisticalOptionsObj,
4208 currChain.
unifiedWriteContents (lastLevelOptions.m_filteredChainDataOutputFileName,lastLevelOptions.m_filteredChainDataOutputFileType);
4209 currLogLikelihoodValues.
unifiedWriteContents(lastLevelOptions.m_filteredChainDataOutputFileName,lastLevelOptions.m_filteredChainDataOutputFileType);
4210 currLogTargetValues.
unifiedWriteContents (lastLevelOptions.m_filteredChainDataOutputFileName,lastLevelOptions.m_filteredChainDataOutputFileType);
4220 if (currOptions.m_parameterDisabledSet.size() > 0) {
4221 for (std::set<unsigned int>::iterator setIt = currOptions.m_parameterDisabledSet.begin(); setIt != currOptions.m_parameterDisabledSet.end(); ++setIt) {
4222 unsigned int paramId = *setIt;
4223 if (paramId < m_vectorSpace.dimLocal()) {
4224 m_numDisabledParameters++;
4225 m_parameterEnabledStatus[paramId] =
false;
4230 generateSequence_Level0_all(currOptions,
4231 currUnifiedRequestedNumSamples,
4233 currLogLikelihoodValues,
4234 currLogTargetValues);
4236 stopAtEndOfLevel = currOptions.m_stopAtEnd;
4237 bool performCheckpoint = stopAtEndOfLevel;
4238 if (m_options.m_restartOutput_levelPeriod > 0) {
4239 performCheckpoint = performCheckpoint || ( ((m_currLevel + 1) % m_options.m_restartOutput_levelPeriod) == 0 );
4241 if (performCheckpoint) {
4242 checkpointML(currExponent,
4245 currLogLikelihoodValues,
4246 currLogTargetValues);
4252 double minLogLike = -INFINITY;
4253 double maxLogLike = INFINITY;
4258 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4259 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4261 <<
", sub minLogLike = " << minLogLike
4262 <<
", sub maxLogLike = " << maxLogLike
4266 m_env.fullComm().Barrier();
4268 minLogLike = -INFINITY;
4269 maxLogLike = INFINITY;
4270 currLogLikelihoodValues.
unifiedMinMaxExtra(m_vectorSpace.numOfProcsForStorage() == 1,
4275 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4276 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4278 <<
", unified minLogLike = " << minLogLike
4279 <<
", unified maxLogLike = " << maxLogLike
4286 while ((currExponent < 1. ) &&
4287 (stopAtEndOfLevel ==
false)) {
4290 struct timeval timevalLevelBegin;
4292 iRC = gettimeofday(&timevalLevelBegin, NULL);
4294 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4295 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4297 <<
", at " << ctime(&timevalLevelBegin.tv_sec)
4298 <<
", after " << timevalLevelBegin.tv_sec - timevalRoutineBegin.tv_sec
4299 <<
" seconds from entering the routine"
4300 <<
", after " << timevalLevelBegin.tv_sec - m_env.timevalBegin().tv_sec
4301 <<
" seconds from queso environment instatiation"
4306 struct timeval timevalLevel;
4307 iRC = gettimeofday(&timevalLevel, NULL);
4308 double cumulativeRawChainRunTime = 0.;
4309 unsigned int cumulativeRawChainRejections = 0;
4311 bool tryExponentEta =
true;
4312 double failedExponent = 0.;
4313 double failedEta = 0.;
4317 unsigned int indexOfFirstWeight = 0;
4318 unsigned int indexOfLastWeight = 0;
4319 P_M* unifiedCovMatrix = NULL;
4320 bool useBalancedChains =
false;
4326 unsigned int exponentEtaTriedAmount = 0;
4327 while (tryExponentEta) {
4328 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4329 *m_env.subDisplayFile() <<
"In IMLSampling<P_V,P_M>::generateSequence()"
4331 <<
", beginning 'do-while(tryExponentEta)"
4332 <<
": failedExponent = " << failedExponent
4333 <<
", failedEta = " << failedEta
4347 unsigned int paramId = *setIt;
4348 if (paramId < m_vectorSpace.dimLocal()) {
4349 m_numDisabledParameters++;
4350 m_parameterEnabledStatus[paramId] =
false;
4355 if (m_env.inter0Rank() >= 0) {
4356 generateSequence_Step01_inter0(currOptions,
4357 currUnifiedRequestedNumSamples);
4364 double prevExponent = currExponent;
4365 double prevEta = currEta;
4366 unsigned int prevUnifiedRequestedNumSamples = currUnifiedRequestedNumSamples;
4369 m_options.m_prefix+
"prev_chain");
4373 indexOfFirstWeight = 0;
4374 indexOfLastWeight = 0;
4377 if (m_env.inter0Rank() >= 0) {
4378 generateSequence_Step02_inter0(currOptions,
4380 currLogLikelihoodValues,
4381 currLogTargetValues,
4383 prevLogLikelihoodValues,
4384 prevLogTargetValues,
4395 if (m_env.inter0Rank() >= 0) {
4396 generateSequence_Step03_inter0(currOptions,
4397 prevLogLikelihoodValues,
4406 "MLSampling<P_V,P_M>::generateSequence()",
4407 "failed MPI.Bcast() for currExponent");
4408 m_debugExponent = currExponent;
4410 if (currExponent == 1.) {
4411 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4412 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4414 <<
", step " << m_currStep
4415 <<
": copying 'last' level options to current options"
4419 currOptions = &lastLevelOptions;
4421 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4422 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4424 <<
", step " << m_currStep
4425 <<
": after copying 'last' level options to current options, the current options are"
4426 <<
"\n" << *currOptions
4430 if (m_env.inter0Rank() >= 0) {
4435 "MLSampling<P_V,P_M>::generateSequence()",
4436 "failed MPI.Allreduce() for requested num samples in step 3");
4444 P_V oneVec(m_vectorSpace.zeroVector());
4447 unifiedCovMatrix = NULL;
4448 if (m_env.inter0Rank() >= 0) {
4449 unifiedCovMatrix = m_vectorSpace.newMatrix();
4452 unifiedCovMatrix =
new P_M(oneVec);
4455 if (m_env.inter0Rank() >= 0) {
4456 generateSequence_Step04_inter0(*prevChain,
4465 std::vector<unsigned int> unifiedIndexCountersAtProc0Only(0);
4466 std::vector<double> unifiedWeightStdVectorAtProc0Only(0);
4467 if (m_env.inter0Rank() >= 0) {
4468 generateSequence_Step05_inter0(currUnifiedRequestedNumSamples,
4470 unifiedIndexCountersAtProc0Only,
4471 unifiedWeightStdVectorAtProc0Only);
4478 useBalancedChains =
false;
4479 std::vector<ExchangeInfoStruct> exchangeStdVec(0);
4481 generateSequence_Step06_all(currOptions,
4484 unifiedIndexCountersAtProc0Only,
4495 if (m_env.inter0Rank() >= 0) {
4496 generateSequence_Step07_inter0(useBalancedChains,
4499 unifiedIndexCountersAtProc0Only,
4500 *unbalancedLinkControl,
4504 *balancedLinkControl);
4515 m_likelihoodFunction,
4523 generateSequence_Step08_all(*currPdf,
4530 generateSequence_Step09_all(*prevChain,
4533 unifiedWeightStdVectorAtProc0Only,
4541 tryExponentEta =
false;
4543 (currEta < currOptions->m_minAcceptableEta)) {
4544 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4545 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4547 <<
", preparing to retry ExponentEta"
4548 <<
": currExponent = " << currExponent
4549 <<
", currEta = " << currEta
4552 exponentEtaTriedAmount++;
4553 tryExponentEta =
true;
4554 failedExponent = currExponent;
4555 failedEta = currEta;
4563 delete balancedLinkControl;
4564 balancedLinkControl = NULL;
4565 delete unbalancedLinkControl;
4566 unbalancedLinkControl = NULL;
4568 delete unifiedCovMatrix;
4569 unifiedCovMatrix = NULL;
4571 currExponent = prevExponent;
4573 currUnifiedRequestedNumSamples = prevUnifiedRequestedNumSamples;
4576 currChain = (*prevChain);
4580 currLogLikelihoodValues = prevLogLikelihoodValues;
4581 currLogTargetValues = prevLogTargetValues;
4585 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4586 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4588 <<
", exited 'do-while(tryExponentEta)"
4589 <<
", failedExponent = " << failedExponent
4590 <<
", failedEta = " << failedEta
4599 generateSequence_Step10_all(*currOptions,
4603 *unbalancedLinkControl,
4606 *balancedLinkControl,
4608 cumulativeRawChainRunTime,
4609 cumulativeRawChainRejections,
4610 &currLogLikelihoodValues,
4611 &currLogTargetValues);
4617 bool performCheckpoint = stopAtEndOfLevel;
4618 if (m_options.m_restartOutput_levelPeriod > 0) {
4619 performCheckpoint = performCheckpoint || ( ((m_currLevel + 1) % m_options.m_restartOutput_levelPeriod) == 0 );
4620 if (currExponent == 1.) {
4621 performCheckpoint =
true;
4624 if (performCheckpoint) {
4625 checkpointML(currExponent,
4628 currLogLikelihoodValues,
4629 currLogTargetValues);
4636 delete unifiedCovMatrix;
4638 for (
unsigned int i = 0; i < balancedLinkControl->
balLinkedChains.size(); ++i) {
4641 "MLSampling<P_V,P_M>::generateSequence()",
4642 "Initial position pointer in step 9 should not be NULL");
4653 unsigned int unifiedNumberOfRejections = 0;
4654 if (m_env.inter0Rank() >= 0) {
4655 generateSequence_Step11_inter0(currOptions,
4656 currUnifiedRequestedNumSamples,
4657 cumulativeRawChainRejections,
4659 currLogLikelihoodValues,
4660 currLogTargetValues,
4661 unifiedNumberOfRejections);
4664 minLogLike = -INFINITY;
4665 maxLogLike = INFINITY;
4670 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4671 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4673 <<
", sub minLogLike = " << minLogLike
4674 <<
", sub maxLogLike = " << maxLogLike
4678 m_env.fullComm().Barrier();
4680 minLogLike = -INFINITY;
4681 maxLogLike = INFINITY;
4682 currLogLikelihoodValues.
unifiedMinMaxExtra(m_vectorSpace.numOfProcsForStorage() == 1,
4687 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4688 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4690 <<
", unified minLogLike = " << minLogLike
4691 <<
", unified maxLogLike = " << maxLogLike
4699 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4700 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4703 <<
" chain positions"
4704 <<
", cumulativeRawChainRunTime = " << cumulativeRawChainRunTime <<
" seconds"
4705 <<
", total level time = " << levelRunTime <<
" seconds"
4706 <<
", cumulativeRawChainRejections = " << cumulativeRawChainRejections
4707 <<
" (" << 100.*((double) cumulativeRawChainRejections)/((double) currOptions->
m_rawChainSize)
4708 <<
"% at this processor)"
4709 <<
" (" << 100.*((double) unifiedNumberOfRejections)/((double) currUnifiedRequestedNumSamples)
4710 <<
"% over all processors)"
4711 <<
", stopAtEndOfLevel = " << stopAtEndOfLevel
4715 if (m_env.inter0Rank() >= 0) {
4716 double minCumulativeRawChainRunTime = 0.;
4718 "MLSampling<P_V,P_M>::generateSequence()",
4719 "failed MPI.Allreduce() for min cumulative raw chain run time");
4721 double maxCumulativeRawChainRunTime = 0.;
4723 "MLSampling<P_V,P_M>::generateSequence()",
4724 "failed MPI.Allreduce() for max cumulative raw chain run time");
4726 double avgCumulativeRawChainRunTime = 0.;
4728 "MLSampling<P_V,P_M>::generateSequence()",
4729 "failed MPI.Allreduce() for sum cumulative raw chain run time");
4730 avgCumulativeRawChainRunTime /= ((double) m_env.inter0Comm().NumProc());
4732 double minLevelRunTime = 0.;
4734 "MLSampling<P_V,P_M>::generateSequence()",
4735 "failed MPI.Allreduce() for min level run time");
4737 double maxLevelRunTime = 0.;
4739 "MLSampling<P_V,P_M>::generateSequence()",
4740 "failed MPI.Allreduce() for max level run time");
4742 double avgLevelRunTime = 0.;
4744 "MLSampling<P_V,P_M>::generateSequence()",
4745 "failed MPI.Allreduce() for sum level run time");
4746 avgLevelRunTime /= ((double) m_env.inter0Comm().NumProc());
4748 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4749 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4751 <<
": min cumul seconds = " << minCumulativeRawChainRunTime
4752 <<
", avg cumul seconds = " << avgCumulativeRawChainRunTime
4753 <<
", max cumul seconds = " << maxCumulativeRawChainRunTime
4754 <<
", min level seconds = " << minLevelRunTime
4755 <<
", avg level seconds = " << avgLevelRunTime
4756 <<
", max level seconds = " << maxLevelRunTime
4761 if (currExponent != 1.)
delete currOptions;
4763 struct timeval timevalLevelEnd;
4765 iRC = gettimeofday(&timevalLevelEnd, NULL);
4767 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4768 *m_env.subDisplayFile() <<
"Getting at the end of level " << m_currLevel+
LEVEL_REF_ID
4769 <<
", as part of a 'while' on levels"
4770 <<
", at " << ctime(&timevalLevelEnd.tv_sec)
4771 <<
", after " << timevalLevelEnd.tv_sec - timevalRoutineBegin.tv_sec
4772 <<
" seconds from entering the routine"
4773 <<
", after " << timevalLevelEnd.tv_sec - m_env.timevalBegin().tv_sec
4774 <<
" seconds from queso environment instatiation"
4788 if (m_env.inter0Rank() >= 0) {
4791 "MLSampling<P_V,P_M>::generateSequence()",
4792 "invalid m_currLevel at the exit of the level loop");
4794 for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
4795 m_logEvidence += m_logEvidenceFactors[i];
4798 #if 1 // prudenci-2012-07-06
4799 m_meanLogLikelihood = currLogLikelihoodValues.
unifiedMeanPlain(m_vectorSpace.numOfProcsForStorage() == 1);
4801 m_meanLogLikelihood = currLogLikelihoodValues.
unifiedMeanExtra(m_vectorSpace.numOfProcsForStorage() == 1,
4806 m_eig = m_meanLogLikelihood - m_logEvidence;
4808 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4809 *m_env.subDisplayFile() <<
"In MLSampling<P_V,P_M>::generateSequence()"
4810 <<
", log(evidence) = " << m_logEvidence
4811 <<
", evidence = " << exp(m_logEvidence)
4812 <<
", meanLogLikelihood = " << m_meanLogLikelihood
4813 <<
", eig = " << m_eig
4819 "MLSampling<P_V,P_M>::generateSequence()",
4820 "failed MPI.Bcast() for m_logEvidence");
4823 "MLSampling<P_V,P_M>::generateSequence()",
4824 "failed MPI.Bcast() for m_meanLogLikelihood");
4827 "MLSampling<P_V,P_M>::generateSequence()",
4828 "failed MPI.Bcast() for m_eig");
4833 workingChain.
clear();
4835 P_V auxVec(m_vectorSpace.zeroVector());
4837 if (m_env.inter0Rank() >= 0) {
4843 if (workingLogLikelihoodValues) *workingLogLikelihoodValues = currLogLikelihoodValues;
4844 if (workingLogTargetValues ) *workingLogTargetValues = currLogTargetValues;
4846 struct timeval timevalRoutineEnd;
4848 iRC = gettimeofday(&timevalRoutineEnd, NULL);
4850 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
4851 *m_env.subDisplayFile() <<
"Leaving MLSampling<P_V,P_M>::generateSequence()"
4852 <<
", at " << ctime(&timevalRoutineEnd.tv_sec)
4853 <<
", after " << timevalRoutineEnd.tv_sec - timevalRoutineBegin.tv_sec
4854 <<
" seconds from entering the routine"
4855 <<
", after " << timevalRoutineEnd.tv_sec - m_env.timevalBegin().tv_sec
4856 <<
" seconds from queso environment instatiation"
4863 template<
class P_V,
class P_M>
4864 std::ostream& operator<<(std::ostream& os, const MLSampling<P_V,P_M>& obj)
4871 template <
class P_V,
class P_M>
4874 return m_logEvidence;
4877 template <
class P_V,
class P_M>
4880 return m_meanLogLikelihood;
4883 template <
class P_V,
class P_M>
void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)
Reads the unified sequence from a file.
int originalNodeOfInitialPosition
bool m_scaleCovMatrix
Whether or not scale proposal covariance matrix.
std::string m_rawChainDataOutputFileType
Type of output file for raw chain.
void restartML(double &currExponent, double &currEta, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues)
Restarts ML algorithm.
bool m_filteredChainGenerate
Whether or not to generate filtered chain.
void scanOptionsValues(const MLSamplingLevelOptions *defaultOptions)
It scans the option values from the options input file.
A templated class that represents a Multilevel generator of samples.
void scanOptionsValues()
It scans the option values from the options input file.
void getPositionValues(unsigned int posId, V &vec) const
Gets the values of the sequence at position posId and stores them at vec.
void generateBalLinkedChains_all(MLSamplingLevelOptions &inputOptions, const P_M &unifiedCovMatrix, const GenericVectorRV< P_V, P_M > &rv, const BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl, SequenceOfVectors< P_V, P_M > &workingChain, double &cumulativeRunTime, unsigned int &cumulativeRejections, ScalarSequence< double > *currLogLikelihoodValues, ScalarSequence< double > *currLogTargetValues)
void setPdf(BaseJointPdf< V, M > &pdf)
Sets the PDF of this vector RV to pdf.
unsigned int m_amAdaptInterval
'am' adaptation interval.
std::vector< double > m_initialValuesOfDisabledParameters
#define RawValue_MPI_DOUBLE
#define RawValue_MPI_UNSIGNED
double meanLogLikelihood() const
Method to calculate the mean of the logarithm of the likelihood.
unsigned int m_rawChainSize
Size of raw chain.
bool decideOnBalancedChains_all(const MLSamplingLevelOptions *currOptions, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, std::vector< ExchangeInfoStruct > &exchangeStdVec)
virtual void setPositionValues(unsigned int posId, const V &vec)=0
Set the values in vec at position posId of the sequence. See template specialization.
double m_filteredChainDiscardedPortion
Initial discarded portion for chain filtering.
const T & unifiedMeanPlain(bool useOnlyInter0Comm) const
Finds the mean value of the unified sequence of scalars.
std::ofstream * ofsVar
Provides a stream interface to write data to files.
double m_covRejectionRate
c.o.v. for judging attempted rejection rate at current level.
const BaseEnvironment & m_env
Queso enviroment.
void setName(const std::string &newName)
Changes the name of the sequence of vectors.
unsigned int unifiedSequenceSize(bool useOnlyInter0Comm) const
Size of the unified sequence of scalars.
virtual void resizeSequence(unsigned int newSubSequenceSize)=0
Resize the sequence. See template specialization.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
void generateUnbLinkedChains_all(MLSamplingLevelOptions &inputOptions, const P_M &unifiedCovMatrix, const GenericVectorRV< P_V, P_M > &rv, const UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl, unsigned int indexOfFirstWeight, const SequenceOfVectors< P_V, P_M > &prevChain, SequenceOfVectors< P_V, P_M > &workingChain, double &cumulativeRunTime, unsigned int &cumulativeRejections, ScalarSequence< double > *currLogLikelihoodValues, ScalarSequence< double > *currLogTargetValues)
int finalNodeOfInitialPosition
#define RawValue_MPI_IN_PLACE
void generateSequence_Step04_inter0(const SequenceOfVectors< P_V, P_M > &prevChain, const ScalarSequence< double > &weightSequence, P_M &unifiedCovMatrix)
Creates covariance matrix for current level (Step 04 from ML algorithm).
MLSamplingOptions m_options
Options for the ML algorithm.
unsigned int m_filteredChainLag
Spacing for chain filtering.
void filter(unsigned int initialPos, unsigned int spacing)
Filters positions in the sequence of vectors.
#define UQ_MH_SG_FILENAME_FOR_NO_FILE
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
void append(const BaseVectorSequence< V, M > &src, unsigned int initialPos, unsigned int numPos)
Appends the vector src to this vector.
unsigned int numberOfPositions
void sampleIndexes_proc0(unsigned int unifiedRequestedNumSamples, const std::vector< double > &unifiedWeightStdVectorAtProc0Only, std::vector< unsigned int > &unifiedIndexCountersAtProc0Only)
GslMatrix matrixProduct(const GslVector &v1, const GslVector &v2)
double m_minRejectionRate
minimum allowed attempted rejection rate at current level
void resizeSequence(unsigned int newSubSequenceSize)
Resizes the sequence.
void clear()
Clears the sequence of scalars.
unsigned int unifiedSequenceSize() const
Calculates the size of the unified sequence of vectors.
A templated class that represents a Metropolis-Hastings generator of samples.
void resizeSequence(unsigned int newSequenceSize)
Resizes the size of the sequence of scalars.
#define ML_CHECKPOINT_FIXED_AMOUNT_OF_DATA
void generateSequence_Step02_inter0(const MLSamplingLevelOptions *currOptions, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues, SequenceOfVectors< P_V, P_M > &prevChain, ScalarSequence< double > &prevLogLikelihoodValues, ScalarSequence< double > &prevLogTargetValues, unsigned int &indexOfFirstWeight, unsigned int &indexOfLastWeight)
Saves chain and corresponding target pdf values from previous level (Step 02 from ML algorithm)...
void generateSequence_Step01_inter0(const MLSamplingLevelOptions *currOptions, unsigned int &unifiedRequestedNumSamples)
Reads options for the ML algorithm (Step 01 from ML algorithm).
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const
Writes the unified sequence to a file.
void prepareUnbLinkedChains_inter0(unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl)
double m_minEffectiveSizeRatio
Minimum allowed effective size ratio wrt previous level.
unsigned int m_drMaxNumExtraStages
'dr' maximum number of extra stages.
std::string m_dataOutputFileName
Name of generic output file.
void subMinMaxExtra(unsigned int initialPos, unsigned int numPos, T &minValue, T &maxValue) const
Finds the minimum and the maximum values of the sub-sequence, considering numPos positions starting a...
void setPositionValues(unsigned int posId, const V &vec)
Set the values in vec at position posId of the sequence.
A struct that represents a Metropolis-Hastings sample.
void generateSequence_Step07_inter0(bool useBalancedChains, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl, const MLSamplingLevelOptions *currOptions, const SequenceOfVectors< P_V, P_M > &prevChain, std::vector< ExchangeInfoStruct > &exchangeStdVec, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
Plans for number of linked chains for each node so that all nodes generate the closest possible to th...
double MiscGetEllapsedSeconds(struct timeval *timeval0)
void generateSequence_Step09_all(const SequenceOfVectors< P_V, P_M > &prevChain, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< double > &unifiedWeightStdVectorAtProc0Only, const ScalarSequence< double > &weightSequence, double prevEta, const GenericVectorRV< P_V, P_M > &currRv, MLSamplingLevelOptions *currOptions, P_M &unifiedCovMatrix, double &currEta)
Scales the unified covariance matrix until min <= rejection rate <= max (Step 09 from ML algorithm)...
MLSampling(const char *prefix, const BaseVectorRV< P_V, P_M > &priorRv, const BaseScalarFunction< P_V, P_M > &likelihoodFunction)
Constructor.
void prepareBalLinkedChains_inter0(const MLSamplingLevelOptions *currOptions, const SequenceOfVectors< P_V, P_M > &prevChain, std::vector< ExchangeInfoStruct > &exchangeStdVec, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
void justBalance_proc0(const MLSamplingLevelOptions *currOptions, std::vector< ExchangeInfoStruct > &exchangeStdVec)
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
std::set< unsigned int > m_parameterDisabledSet
bool m_stopAtEnd
Stop at end of such level.
A templated class for a finite distribution.
void getRawChainInfo(MHRawChainInfoStruct &info) const
Gets information from the raw chain.
void checkpointML(double currExponent, double currEta, const SequenceOfVectors< P_V, P_M > &currChain, const ScalarSequence< double > &currLogLikelihoodValues, const ScalarSequence< double > &currLogTargetValues)
Writes checkpoint data for the ML method.
void generateSequence_Step05_inter0(unsigned int unifiedRequestedNumSamples, const ScalarSequence< double > &weightSequence, std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, std::vector< double > &unifiedWeightStdVectorAtProc0Only)
Creates unified finite distribution for current level (Step 05 from ML algorithm).
std::string m_filteredChainDataOutputFileType
Type of output file for filtered chain.
unsigned int subSequenceSize() const
Size of the sub-sequence of vectors.
void generateSequence_Step06_all(const MLSamplingLevelOptions *currOptions, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, bool &useBalancedChains, std::vector< ExchangeInfoStruct > &exchangeStdVec)
Decides on wheter or not to use balanced chains (Step 06 from ML algorithm).
std::vector< UnbalancedLinkedChainControlStruct > unbLinkedChains
double m_minAcceptableEta
minimum acceptable eta,
unsigned int m_loadBalanceAlgorithmId
Perform load balancing with chosen algorithm (0 = no balancing).
const T & unifiedMaxPlain(bool useOnlyInter0Comm) const
Finds the maximum value of the unified sequence of scalars.
#define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT
void generateSequence_Step10_all(MLSamplingLevelOptions &currOptions, const P_M &unifiedCovMatrix, const GenericVectorRV< P_V, P_M > &currRv, bool useBalancedChains, const UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl, unsigned int indexOfFirstWeight, const SequenceOfVectors< P_V, P_M > &prevChain, const BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl, SequenceOfVectors< P_V, P_M > &currChain, double &cumulativeRawChainRunTime, unsigned int &cumulativeRawChainRejections, ScalarSequence< double > *currLogLikelihoodValues, ScalarSequence< double > *currLogTargetValues)
Samples the vector RV of current level (Step 10 from ML algorithm).
unsigned int numberOfPositions
void append(const ScalarSequence< T > &src, unsigned int srcInitialPos, unsigned int srcNumPos)
Appends the scalar sequence src to this sequence.
double m_maxRejectionRate
maximum allowed attempted rejection rate at current level.
MPI_Status RawType_MPI_Status
double m_maxEffectiveSizeRatio
Maximum allowed effective size ratio wrt previous level.
This class provides options for each level of the Multilevel sequence generator if no input file is a...
void generateSequence_Step11_inter0(const MLSamplingLevelOptions *currOptions, unsigned int unifiedRequestedNumSamples, unsigned int cumulativeRawChainRejections, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues, unsigned int &unifiedNumberOfRejections)
Filters chain (Step 11 from ML algorithm).
double m_loadBalanceTreshold
Perform load balancing if load unbalancing ratio > threshold.
void unifiedMinMaxExtra(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int numPos, T &unifiedMinValue, T &unifiedMaxValue) const
Finds the minimum and the maximum values of the unified sequence, considering numPos positions starti...
Struct for handling data input and output from files.
unsigned int numRejections
void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)
Reads the unified sequence from a file.
bool m_totallyMute
Whether or not to be totally mute (no printout message).
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
unsigned int initialPositionIndexInPreviousChain
void mpiExchangePositions_inter0(const SequenceOfVectors< P_V, P_M > &prevChain, const std::vector< ExchangeInfoStruct > &exchangeStdVec, const std::vector< unsigned int > &finalNumChainsPerNode, const std::vector< unsigned int > &finalNumPositionsPerNode, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
void computeFilterParams(std::ofstream *passedOfs, unsigned int &initialPos, unsigned int &spacing)
Computes the filtering parameters spacing for the sequence of vectors.
void generateSequence_Step08_all(BayesianJointPdf< P_V, P_M > &currPdf, GenericVectorRV< P_V, P_M > &currRv)
Creates a vector RV for current level (Step 08 from ML algorithm).
void clear()
Reset the values and the size of the sequence of vectors.
#define RawValue_MPI_CHAR
VectorSet< V, M > * InstantiateIntersection(const VectorSet< V, M > &domain1, const VectorSet< V, M > &domain2)
This method calculates the intersection of domain1 and domain2.
T unifiedMeanExtra(bool useOnlyInter0Comm, unsigned int initialPos, unsigned int localNumPos) const
Finds the mean value of the unified sequence of numPos positions starting at position initialPos...
void generateSequence_Step03_inter0(const MLSamplingLevelOptions *currOptions, const ScalarSequence< double > &prevLogLikelihoodValues, double prevExponent, double failedExponent, double &currExponent, ScalarSequence< double > &weightSequence)
Computes currExponent and sequence of weights for current level and update 'm_logEvidenceFactors' (St...
unsigned int subSequenceSize() const
Size of the sub-sequence of scalars.
std::string m_rawChainDataOutputFileName
Name of output file for raw chain.
double logEvidence() const
Method to calculate the logarithm of the evidence.
std::vector< BalancedLinkedChainControlStruct< P_V > > balLinkedChains
void generateSequence_Level0_all(const MLSamplingLevelOptions &currOptions, unsigned int &unifiedRequestedNumSamples, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues)
Generates the sequence at the level 0.
unsigned int originalIndexOfInitialPosition
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const
void setName(const std::string &newName)
Sets a new name to the sequence of scalars.
bool MiscCheckForSameValueInAllNodes(T &inputValue, double acceptableTreshold, const MpiComm &comm, const char *whereString)
double eig() const
Calculates the expected information gain value, EIG.
void filter(unsigned int initialPos, unsigned int spacing)
Filters positions in the sequence of vectors.
unsigned int sample() const
Samples.
std::string m_filteredChainDataOutputFileName
Name of output file for filtered chain.
std::set< unsigned int > m_dataOutputAllowedSet
subEnvs that will write to generic output file.
virtual unsigned int subSequenceSize() const =0
Size of the sub-sequence of vectors. See template specialization.
void getUnifiedContentsAtProc0Only(bool useOnlyInter0Comm, std::vector< T > &outputVec) const
Gets the unified contents of processor of rank equals to 0.
Class for handling vector samples (sequence of vectors).