29 #include <queso/MLSampling.h> 
   30 #include <queso/InstantiateIntersection.h> 
   31 #include <queso/GslVector.h> 
   32 #include <queso/GslMatrix.h> 
   33 #include <queso/BayesianJointPdf.h> 
   39 void BIP_routine(glp_tree *tree, 
void *info)
 
   41   const BaseEnvironment& env = *(((BIP_routine_struct *) info)->env);
 
   42   unsigned int currLevel            =   ((BIP_routine_struct *) info)->currLevel;
 
   44   int reason = glp_ios_reason(tree);
 
   46   if ((env.subDisplayFile()) && (env.displayVerbosity() >= 1)) {
 
   47     *env.subDisplayFile() << 
"In BIP_routine()" 
   49                           << 
": glp_ios_reason() = " << reason
 
   52   std::cout << 
"In BIP_routine: reason = " << reason << std::endl;
 
   91 #endif // QUESO_HAS_GLPK 
   93 template <
class P_V,
class P_M>
 
   96   unsigned int               unifiedRequestedNumSamples,        
 
   97   const std::vector<double>& unifiedWeightStdVectorAtProc0Only, 
 
   98   std::vector<unsigned int>& unifiedIndexCountersAtProc0Only)   
 
  100   if (m_env.inter0Rank() != 0) 
return;
 
  102   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  103     *m_env.subDisplayFile() << 
"Entering MLSampling<P_V,P_M>::sampleIndexes_proc0()" 
  105                             << 
", step "  << m_currStep
 
  106                             << 
": unifiedRequestedNumSamples = "               << unifiedRequestedNumSamples
 
  107                             << 
", unifiedWeightStdVectorAtProc0Only.size() = " << unifiedWeightStdVectorAtProc0Only.size()
 
  111 #if 0 // For debug only 
  112   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  113     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::sampleIndexes_proc0()" 
  115                             << 
", step "  << m_currStep
 
  118     unsigned int numZeros = 0;
 
  119     for (
unsigned int i = 0; i < unifiedWeightStdVectorAtProc0Only.size(); ++i) {
 
  120       *m_env.subDisplayFile() << 
"  unifiedWeightStdVectorAtProc0Only[" << i
 
  121                               << 
"] = " << unifiedWeightStdVectorAtProc0Only[i]
 
  123       if (unifiedWeightStdVectorAtProc0Only[i] == 0.) numZeros++;
 
  125     *m_env.subDisplayFile() << 
"Number of zeros in unifiedWeightStdVectorAtProc0Only = " << numZeros
 
  130   if (m_env.inter0Rank() == 0) {
 
  131     unsigned int resizeSize = unifiedWeightStdVectorAtProc0Only.size();
 
  132     unifiedIndexCountersAtProc0Only.resize(resizeSize,0);
 
  137                                     unifiedWeightStdVectorAtProc0Only);
 
  138     for (
unsigned int i = 0; i < unifiedRequestedNumSamples; ++i) {
 
  139       unsigned int index = tmpFd.
sample();
 
  140       unifiedIndexCountersAtProc0Only[index] += 1;
 
  147 template <
class P_V,
class P_M>
 
  151   unsigned int                         indexOfFirstWeight,              
 
  152   unsigned int                         indexOfLastWeight,               
 
  153   const std::vector<unsigned int>&     unifiedIndexCountersAtProc0Only, 
 
  154   std::vector<ExchangeInfoStruct>&   exchangeStdVec)                  
 
  158   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  159     *m_env.subDisplayFile() << 
"Entering MLSampling<P_V,P_M>::decideOnBalancedChains_all()" 
  161                             << 
", step "  << m_currStep
 
  162                             << 
": indexOfFirstWeight = " << indexOfFirstWeight
 
  163                             << 
", indexOfLastWeight = "  << indexOfLastWeight
 
  169     if (m_env.inter0Rank() >= 0) { 
 
  170       Np = (
unsigned int) m_env.inter0Comm().NumProc();
 
  172     std::vector<unsigned int> allFirstIndexes(Np,0); 
 
  173     std::vector<unsigned int> allLastIndexes(Np,0);  
 
  175     if (m_env.inter0Rank() >= 0) { 
 
  179       unsigned int auxUInt = indexOfFirstWeight;
 
  180       m_env.inter0Comm().template Gather<unsigned int>(&auxUInt, 1, &allFirstIndexes[0], (int) 1, 0, 
 
  181                                 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
 
  182                                 "failed MPI.Gather() for first indexes");
 
  184       if (m_env.inter0Rank() == 0) {
 
  185         queso_require_equal_to_msg(allFirstIndexes[0], indexOfFirstWeight, 
"failed MPI.Gather() result for first indexes, at proc 0");
 
  188       auxUInt = indexOfLastWeight;
 
  189       m_env.inter0Comm().template Gather<unsigned int>(&auxUInt, 1, &allLastIndexes[0], (int) 1, 0, 
 
  190                                 "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
 
  191                                 "failed MPI.Gather() for last indexes");
 
  193       if (m_env.inter0Rank() == 0) { 
 
  202     if (m_env.inter0Rank() == 0) {
 
  203       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  204         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::decideOnBalancedChains_all()" 
  206                                 << 
", step "  << m_currStep
 
  207                                 << 
": original distribution of unified indexes in 'inter0Comm' is as follows" 
  209         for (
unsigned int r = 0; r < Np; ++r) {
 
  210           *m_env.subDisplayFile() << 
"  allFirstIndexes[" << r << 
"] = " << allFirstIndexes[r]
 
  211                                   << 
"  allLastIndexes["  << r << 
"] = " << allLastIndexes[r]
 
  215       for (
unsigned int r = 0; r < (Np-1); ++r) { 
 
  219       for (
unsigned int r = 0; r < (Np-1); ++r) { 
 
  223       std::vector<unsigned int> origNumChainsPerNode   (Np,0);
 
  224       std::vector<unsigned int> origNumPositionsPerNode(Np,0);
 
  226       for (
unsigned int i = 0; i < unifiedIndexCountersAtProc0Only.size(); ++i) {
 
  227         if ((allFirstIndexes[r] <= i) && 
 
  228             (i <= allLastIndexes[r] )) {
 
  233           if ((r < (
int) Np           ) &&
 
  234               (allFirstIndexes[r] <= i) &&
 
  235               (i <= allLastIndexes[r] )) {
 
  239       std::cerr << 
"In MLSampling<P_V,P_M>::decideOnBalancedChains_all()" 
  242                       << 
", allFirstIndexes[r] = " << allFirstIndexes[r]
 
  243                       << 
", allLastIndexes[r] = "  << allLastIndexes[r]
 
  248         if (unifiedIndexCountersAtProc0Only[i] != 0) {
 
  249           origNumChainsPerNode   [r] += 1;
 
  250           origNumPositionsPerNode[r] += unifiedIndexCountersAtProc0Only[i];
 
  257           exchangeStdVec.push_back(auxInfo);
 
  263       unsigned int totalNumberOfChains = 0;
 
  264       for (
unsigned int r = 0; r < Np; ++r) {
 
  265         totalNumberOfChains += origNumChainsPerNode[r];
 
  267       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  268         *m_env.subDisplayFile() << 
"  KEY" 
  270                                 << 
", step "  << m_currStep
 
  272                                 << 
", totalNumberOfChains = " << totalNumberOfChains
 
  277       unsigned int origMinPosPerNode  = *std::min_element(origNumPositionsPerNode.begin(), origNumPositionsPerNode.end());
 
  278       unsigned int origMaxPosPerNode  = *std::max_element(origNumPositionsPerNode.begin(), origNumPositionsPerNode.end());
 
  279       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  280         for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
  281           *m_env.subDisplayFile() << 
"  KEY" 
  283                                   << 
", step "  << m_currStep
 
  284                                   << 
", origNumChainsPerNode["     << nodeId << 
"] = " << origNumChainsPerNode[nodeId]
 
  285                                   << 
", origNumPositionsPerNode["  << nodeId << 
"] = " << origNumPositionsPerNode[nodeId]
 
  289       double origRatioOfPosPerNode = ((double) origMaxPosPerNode ) / ((double) origMinPosPerNode);
 
  290       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  291         *m_env.subDisplayFile() << 
"  KEY" 
  293                                 << 
", step "  << m_currStep
 
  294                                 << 
", origRatioOfPosPerNode = "      << origRatioOfPosPerNode
 
  302           (m_env.numSubEnvironments()            > 1                                 ) && 
 
  303           (Np                                    < totalNumberOfChains               ) &&
 
  310   m_env.fullComm().Barrier();
 
  311   unsigned int tmpValue = result;
 
  313                          "MLSampling<P_V,P_M>::decideOnBalancedChains_all()",
 
  314                          "failed MPI.Bcast() for 'result'");
 
  315   if (m_env.inter0Rank() != 0) result = tmpValue;
 
  317   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  318     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::decideOnBalancedChains_all()" 
  320                             << 
", step "     << m_currStep
 
  321                             << 
": result = " << result
 
  328 template <
class P_V,
class P_M>
 
  337   std::vector<ExchangeInfoStruct>&        exchangeStdVec,      
 
  340   if (m_env.inter0Rank() < 0) 
return;
 
  342   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  343     *m_env.subDisplayFile() << 
"Entering MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()" 
  345                             << 
", step "  << m_currStep
 
  349   unsigned int Np = (
unsigned int) m_env.inter0Comm().NumProc();
 
  350   if (m_env.inter0Rank() == 0) {
 
  353         justBalance_proc0(currOptions,     
 
  359 #ifdef QUESO_HAS_GLPK 
  361         solveBIP_proc0(exchangeStdVec); 
 
  363         if (m_env.subDisplayFile()) {
 
  364           *m_env.subDisplayFile() << 
"WARNING in MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()" 
  366                                   << 
"' has been requested, but this QUESO library has not been built with 'hdf5'" 
  367                                   << 
". Code will therefore process the algorithm id '" << 2
 
  371         if (m_env.subRank() == 0) {
 
  372           std::cerr << 
"WARNING in MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()" 
  374                     << 
"' has been requested, but this QUESO library has not been built with 'hdf5'" 
  375                     << 
". Code will therefore process the algorithm id '" << 2
 
  379         justBalance_proc0(currOptions,     
 
  386   m_env.inter0Comm().Barrier();
 
  391   unsigned int exchangeStdVecSize = exchangeStdVec.size();
 
  393                            "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
 
  394                            "failed MPI.Bcast() for exchangeStdVec size");
 
  395   if (m_env.inter0Rank() > 0) exchangeStdVec.resize(exchangeStdVecSize);
 
  398                            "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
 
  399                            "failed MPI.Bcast() for exchangeStdVec data");
 
  404   std::vector<unsigned int> finalNumChainsPerNode   (Np,0);
 
  405   std::vector<unsigned int> finalNumPositionsPerNode(Np,0);
 
  406   unsigned int Nc = exchangeStdVec.size();
 
  407   for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
  408     unsigned int nodeId = exchangeStdVec[chainId].finalNodeOfInitialPosition;
 
  409     finalNumChainsPerNode   [nodeId] += 1;
 
  410     finalNumPositionsPerNode[nodeId] += exchangeStdVec[chainId].numberOfPositions;
 
  416   unsigned int finalMinPosPerNode = *std::min_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
 
  417   unsigned int finalMaxPosPerNode = *std::max_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
 
  418   double finalRatioOfPosPerNode = ((double) finalMaxPosPerNode) / ((double)finalMinPosPerNode);
 
  421   std::vector<double> auxBuf(1,0.);
 
  422   double minRatio = 0.;
 
  423   auxBuf[0] = finalRatioOfPosPerNode;
 
  424   m_env.inter0Comm().template Allreduce<double>(&auxBuf[0], &minRatio, (int) auxBuf.size(), 
RawValue_MPI_MIN, 
 
  425                                "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
 
  426                                "failed MPI.Allreduce() for min");
 
  430   double maxRatio = 0.;
 
  431   auxBuf[0] = finalRatioOfPosPerNode;
 
  432   m_env.inter0Comm().template Allreduce<double>(&auxBuf[0], &maxRatio, (int) auxBuf.size(), 
RawValue_MPI_MAX, 
 
  433                                "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
 
  434                                "failed MPI.Allreduce() for max");
 
  441   unsigned int finalNumChainsPerNodeSize = finalNumChainsPerNode.size();
 
  443                            "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
 
  444                            "failed MPI.Bcast() for finalNumChainsPerNode size");
 
  445   if (m_env.inter0Rank() > 0) finalNumChainsPerNode.resize(finalNumChainsPerNodeSize);
 
  447   m_env.inter0Comm().Bcast((
void *) &finalNumChainsPerNode[0], (
int) finalNumChainsPerNodeSize, 
RawValue_MPI_UNSIGNED, 0, 
 
  448                            "MLSampling<P_V,P_M>::prepareBalLinkedChains_inter0()",
 
  449                            "failed MPI.Bcast() for finalNumChainsPerNode data");
 
  455   mpiExchangePositions_inter0(prevChain,
 
  458                               prevLogLikelihoodValues,
 
  461                               finalNumChainsPerNode,
 
  462                               finalNumPositionsPerNode, 
 
  463                               balancedLinkControl);
 
  468 template <
class P_V,
class P_M>
 
  471   unsigned int                           indexOfFirstWeight,              
 
  472   unsigned int                           indexOfLastWeight,               
 
  473   const std::vector<unsigned int>&       unifiedIndexCountersAtProc0Only, 
 
  476   if (m_env.inter0Rank() < 0) 
return;
 
  478   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  479     *m_env.subDisplayFile() << 
"Entering MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()" 
  481                             << 
", step "  << m_currStep
 
  482                             << 
": indexOfFirstWeight = " << indexOfFirstWeight
 
  483                             << 
", indexOfLastWeight = "  << indexOfLastWeight
 
  487   unsigned int              subNumSamples = 0;
 
  488   std::vector<unsigned int> unifiedIndexCountersAtAllProcs(0);
 
  491   unsigned int resizeSize = unifiedIndexCountersAtProc0Only.size();
 
  493                            "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
 
  494                            "failed MPI.Bcast() for resizeSize");
 
  495   unifiedIndexCountersAtAllProcs.resize(resizeSize,0);
 
  497   if (m_env.inter0Rank() == 0) unifiedIndexCountersAtAllProcs = unifiedIndexCountersAtProc0Only;
 
  500   m_env.inter0Comm().Bcast((
void *) &unifiedIndexCountersAtAllProcs[0], (
int) unifiedIndexCountersAtAllProcs.size(), 
RawValue_MPI_UNSIGNED, 0,
 
  501                            "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
 
  502                            "failed MPI.Bcast() for unified index counters");
 
  503 #if 0 // Use allgatherv ??? for subNumSamples instead 
  504   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  505     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()" 
  507                             << 
", step "  << m_currStep
 
  510     for (
int r = 0; r < m_env.inter0Comm().NumProc(); ++r) {
 
  511       *m_env.subDisplayFile() << 
"  unifiedIndexCountersAtAllProcs[" << r << 
"] = " << unifiedIndexCountersAtAllProcs[r]
 
  523   queso_require_less_msg(indexOfFirstWeight, unifiedIndexCountersAtAllProcs.size(), 
"invalid indexOfFirstWeight");
 
  524   queso_require_less_msg(indexOfLastWeight, unifiedIndexCountersAtAllProcs.size(), 
"invalid indexOfLastWeight");
 
  526   for (
unsigned int i = indexOfFirstWeight; i <= indexOfLastWeight; ++i) {
 
  527     subNumSamples += unifiedIndexCountersAtAllProcs[i];
 
  530   std::vector<unsigned int> auxBuf(1,0);
 
  532   unsigned int minModifiedSubNumSamples = 0;
 
  533   auxBuf[0] = subNumSamples;
 
  534   m_env.inter0Comm().template Allreduce<unsigned int>(&auxBuf[0], &minModifiedSubNumSamples, (int) auxBuf.size(), 
RawValue_MPI_MIN,
 
  535                                "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
 
  536                                "failed MPI.Allreduce() for min");
 
  538   unsigned int maxModifiedSubNumSamples = 0;
 
  539   auxBuf[0] = subNumSamples;
 
  540   m_env.inter0Comm().template Allreduce<unsigned int>(&auxBuf[0], &maxModifiedSubNumSamples, (int) auxBuf.size(), 
RawValue_MPI_MAX,
 
  541                                "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
 
  542                                "failed MPI.Allreduce() for max");
 
  544   unsigned int sumModifiedSubNumSamples = 0;
 
  545   auxBuf[0] = subNumSamples;
 
  546   m_env.inter0Comm().template Allreduce<unsigned int>(&auxBuf[0], &sumModifiedSubNumSamples, (int) auxBuf.size(), 
RawValue_MPI_SUM,
 
  547                                "MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()",
 
  548                                "failed MPI.Allreduce() for sum");
 
  555   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  556     *m_env.subDisplayFile() << 
"KEY Leaving MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()" 
  558                             << 
", step "                                    << m_currStep
 
  559                             << 
": subNumSamples = "                         << subNumSamples
 
  560                             << 
", unifiedIndexCountersAtAllProcs.size() = " << unifiedIndexCountersAtAllProcs.size()
 
  562     *m_env.subDisplayFile() << 
"KEY Leaving MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()" 
  564                             << 
", step "                       << m_currStep
 
  565                             << 
": minModifiedSubNumSamples = " << minModifiedSubNumSamples
 
  566                             << 
", avgModifiedSubNumSamples = " << ((double) sumModifiedSubNumSamples)/((double) m_env.inter0Comm().NumProc())
 
  567                             << 
", maxModifiedSubNumSamples = " << maxModifiedSubNumSamples
 
  571   unsigned int numberOfPositionsToGuaranteeForNode = subNumSamples;
 
  572   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  573     *m_env.subDisplayFile() << 
"KEY In MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()" 
  575                             << 
", step "                                  << m_currStep
 
  576                             << 
": numberOfPositionsToGuaranteeForNode = " << numberOfPositionsToGuaranteeForNode
 
  579   for (
unsigned int i = indexOfFirstWeight; i <= indexOfLastWeight; ++i) {
 
  581     while (unifiedIndexCountersAtAllProcs[i] != 0) {
 
  582       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 30)) {
 
  583         *m_env.subDisplayFile() << 
", numberOfPositionsToGuaranteeForNode = " << numberOfPositionsToGuaranteeForNode
 
  584                                 << 
", unifiedIndexCountersAtAllProcs["        << i
 
  585                                 << 
"] = "                                     << unifiedIndexCountersAtAllProcs[i]
 
  588       if (unifiedIndexCountersAtAllProcs[i] < numberOfPositionsToGuaranteeForNode) {
 
  594         numberOfPositionsToGuaranteeForNode -= unifiedIndexCountersAtAllProcs[i];
 
  595         unifiedIndexCountersAtAllProcs[i] = 0;
 
  597       else if ((unifiedIndexCountersAtAllProcs[i] == numberOfPositionsToGuaranteeForNode) &&
 
  598                (unifiedIndexCountersAtAllProcs[i] > 0                                   )) {
 
  605         unifiedIndexCountersAtAllProcs[i] -= numberOfPositionsToGuaranteeForNode;
 
  606         numberOfPositionsToGuaranteeForNode = 0;
 
  608       else if ((unifiedIndexCountersAtAllProcs[i] == numberOfPositionsToGuaranteeForNode) &&
 
  609                (unifiedIndexCountersAtAllProcs[i] == 0                                  )) {
 
  617   queso_require_equal_to_msg(numberOfPositionsToGuaranteeForNode, 0, 
"numberOfPositionsToGuaranteeForNode exited loop with wrong value");
 
  620   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  621     *m_env.subDisplayFile() << 
"KEY Leaving MLSampling<P_V,P_M>::prepareUnbLinkedChains_inter0()" 
  623                             << 
", step "                                           << m_currStep
 
  624                             << 
": unbalancedLinkControl.unbLinkedChains.size() = " << unbalancedLinkControl.
unbLinkedChains.size()
 
  631 template <
class P_V,
class P_M>
 
  635   const P_M&                                      unifiedCovMatrix,        
 
  639   double&                                         cumulativeRunTime,       
 
  640   unsigned int&                                   cumulativeRejections,    
 
  644   m_env.fullComm().Barrier();
 
  646   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  647     *m_env.subDisplayFile() << 
"Entering MLSampling<P_V,P_M>::generateBalLinkedChains_all()" 
  648                             << 
": balancedLinkControl.balLinkedChains.size() = " << balancedLinkControl.
balLinkedChains.size()
 
  652   P_V auxInitialPosition(m_vectorSpace.zeroVector());
 
  653   double auxInitialLogPrior;
 
  654   double auxInitialLogLikelihood;
 
  656   unsigned int chainIdMax = 0;
 
  657   if (m_env.inter0Rank() >= 0) {
 
  662                         "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
 
  663                         "failed MPI.Bcast() for chainIdMax");
 
  665   struct timeval timevalEntering;
 
  667   iRC = gettimeofday(&timevalEntering, NULL);
 
  670   if (m_env.inter0Rank() >= 0) {
 
  671     unsigned int numberOfPositions = 0;
 
  672     for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
 
  673       numberOfPositions += balancedLinkControl.
balLinkedChains[chainId].numberOfPositions;
 
  676     std::vector<unsigned int> auxBuf(1,0);
 
  678     unsigned int minNumberOfPositions = 0;
 
  679     auxBuf[0] = numberOfPositions;
 
  680     m_env.inter0Comm().template Allreduce<unsigned int>(&auxBuf[0], &minNumberOfPositions, (int) auxBuf.size(), 
RawValue_MPI_MIN, 
 
  681                                  "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
 
  682                                  "failed MPI.Allreduce() for min");
 
  684     unsigned int maxNumberOfPositions = 0;
 
  685     auxBuf[0] = numberOfPositions;
 
  686     m_env.inter0Comm().template Allreduce<unsigned int>(&auxBuf[0], &maxNumberOfPositions, (int) auxBuf.size(), 
RawValue_MPI_MAX, 
 
  687                                  "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
 
  688                                  "failed MPI.Allreduce() for max");
 
  690     unsigned int sumNumberOfPositions = 0;
 
  691     auxBuf[0] = numberOfPositions;
 
  692     m_env.inter0Comm().template Allreduce<unsigned int>(&auxBuf[0], &sumNumberOfPositions, (int) auxBuf.size(), 
RawValue_MPI_SUM, 
 
  693                                  "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
 
  694                                  "failed MPI.Allreduce() for sum");
 
  696     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  697       *m_env.subDisplayFile() << 
"KEY In MLSampling<P_V,P_M>::generateBalLinkedChains_all()" 
  699                               << 
", step "                << m_currStep
 
  700                               << 
": chainIdMax = "        << chainIdMax
 
  701                               << 
", numberOfPositions = " << numberOfPositions
 
  702                               << 
", at "                  << ctime(&timevalEntering.tv_sec)
 
  704       *m_env.subDisplayFile() << 
"KEY In MLSampling<P_V,P_M>::generateBalLinkedChains_all()" 
  706                               << 
", step "                   << m_currStep
 
  707                               << 
": minNumberOfPositions = " << minNumberOfPositions
 
  708                               << 
", avgNumberOfPositions = " << ((double) sumNumberOfPositions)/((double) m_env.inter0Comm().NumProc())
 
  709                               << 
", maxNumberOfPositions = " << maxNumberOfPositions
 
  715   if ((m_debugExponent == 1.) &&
 
  716       (m_currStep      == 10)) {
 
  719   unsigned int cumulativeNumPositions = 0;
 
  720   for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
 
  721     unsigned int tmpChainSize = 0;
 
  722     if (m_env.inter0Rank() >= 0) {
 
  724       auxInitialPosition = *(balancedLinkControl.
balLinkedChains[chainId].initialPosition); 
 
  725       auxInitialLogPrior = balancedLinkControl.
balLinkedChains[chainId].initialLogPrior;
 
  726       auxInitialLogLikelihood = balancedLinkControl.
balLinkedChains[chainId].initialLogLikelihood;
 
  727       tmpChainSize = balancedLinkControl.
balLinkedChains[chainId].numberOfPositions+1; 
 
  728       if ((m_env.subDisplayFile()       ) &&
 
  729           (m_env.displayVerbosity() >= 3)) {
 
  730         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()" 
  732                                 << 
", step "             << m_currStep
 
  733                                 << 
", chainId = "        << chainId
 
  734                                 << 
" < "                 << chainIdMax
 
  735                                 << 
": begin generating " << tmpChainSize
 
  736                                 << 
" chain positions" 
  740     auxInitialPosition.mpiBcast(0, m_env.subComm()); 
 
  742 #if 0 // For debug only 
  743     for (
int r = 0; r < m_env.subComm().NumProc(); ++r) {
 
  744       if (r == m_env.subComm().MyPID()) {
 
  745   std::cout << 
"Vector 'auxInitialPosition at rank " << r
 
  746                   << 
" has contents "                      << auxInitialPosition
 
  749       m_env.subComm().Barrier();
 
  756                           "MLSampling<P_V,P_M>::generateBalLinkedChains_all()",
 
  757                           "failed MPI.Bcast() for tmpChainSize");
 
  762                                                m_options.m_prefix+
"tmp_chain");
 
  769           "MLSamplingClass<P_V,P_M>::generateBalLinkedChains_all()",
 
  770           "failed MPI.Bcast() for auxInitialLogPrior");
 
  772           "MLSamplingClass<P_V,P_M>::generateBalLinkedChains_all()",
 
  773           "failed MPI.Bcast() for auxInitialLogLikelihood");
 
  779                                                    auxInitialLogLikelihood,
 
  782                                       &tmpLogLikelihoodValues, 
 
  783                                       &tmpLogTargetValues);
 
  792           &tmpLogLikelihoodValues, 
 
  793           &tmpLogTargetValues);
 
  797     cumulativeRunTime    += mcRawInfo.
runTime;
 
  800     if (m_env.inter0Rank() >= 0) {
 
  801       if (m_env.exceptionalCircumstance()) {
 
  802         if ((m_env.subDisplayFile()       ) &&
 
  803             (m_env.displayVerbosity() >= 0)) { 
 
  804           P_V tmpVec(m_vectorSpace.zeroVector());
 
  805           for (
unsigned int i = 0; i < tmpLogLikelihoodValues.
subSequenceSize(); ++i) {
 
  807             *m_env.subDisplayFile() << 
"DEBUG finalChain[" << cumulativeNumPositions+i << 
"] " 
  808                                     << 
"= tmpChain["               << i << 
"] = " << tmpVec
 
  809                                     << 
", tmpLogLikelihoodValues[" << i << 
"] = " << tmpLogLikelihoodValues[i]
 
  810                                     << 
", tmpLogTargetValues["     << i << 
"] = " << tmpLogTargetValues[i]
 
  816       cumulativeNumPositions += tmpChainSize;
 
  817       if (cumulativeNumPositions > 100) m_env.setExceptionalCircumstance(
false);
 
  819       if ((m_env.subDisplayFile()       ) &&
 
  820           (m_env.displayVerbosity() >= 3)) {
 
  821         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()" 
  823                                 << 
", step "                << m_currStep
 
  824                                 << 
", chainId = "           << chainId
 
  825                                 << 
" < "                    << chainIdMax
 
  827                                 << 
" chain positions" 
  833       if (currLogLikelihoodValues) {
 
  834         currLogLikelihoodValues->
append(tmpLogLikelihoodValues,1,tmpLogLikelihoodValues.
subSequenceSize()-1); 
 
  835         if ((m_env.subDisplayFile()        ) &&
 
  836             (m_env.displayVerbosity() >= 99) &&
 
  838           *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()" 
  840                                   << 
", step "      << m_currStep
 
  841                                   << 
", chainId = " << chainId
 
  842                                   << 
", tmpLogLikelihoodValues.subSequenceSize() = " << tmpLogLikelihoodValues.
subSequenceSize()
 
  843                                   << 
", tmpLogLikelihoodValues[0] = "                << tmpLogLikelihoodValues[0]
 
  844                                   << 
", tmpLogLikelihoodValues[1] = "                << tmpLogLikelihoodValues[1]
 
  845                                   << 
", currLogLikelihoodValues[0] = "               << (*currLogLikelihoodValues)[0]
 
  849       if (currLogTargetValues) {
 
  858   struct timeval timevalBarrier;
 
  859   iRC = gettimeofday(&timevalBarrier, NULL);
 
  862   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  863     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateBalLinkedChains_all()" 
  865                             << 
", step "  << m_currStep
 
  866                             << 
": ended chain loop after " << loopTime << 
" seconds" 
  867                             << 
", calling fullComm().Barrier() at " << ctime(&timevalBarrier.tv_sec)
 
  871   m_env.fullComm().Barrier(); 
 
  873   struct timeval timevalLeaving;
 
  874   iRC = gettimeofday(&timevalLeaving, NULL);
 
  877   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  878     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateBalLinkedChains_all()" 
  880                             << 
", step "  << m_currStep
 
  881                             << 
": after " << barrierTime << 
" seconds in fullComm().Barrier()" 
  882                             << 
", at " << ctime(&timevalLeaving.tv_sec)
 
  889 template <
class P_V,
class P_M>
 
  893   const P_M&                                   unifiedCovMatrix,        
 
  896   unsigned int                                 indexOfFirstWeight,      
 
  903   double&                                      cumulativeRunTime,       
 
  904   unsigned int&                                cumulativeRejections,    
 
  908   m_env.fullComm().Barrier();
 
  910   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  911     *m_env.subDisplayFile() << 
"Entering MLSampling<P_V,P_M>::generateUnbLinkedChains_all()" 
  912                             << 
": unbalancedLinkControl.unbLinkedChains.size() = " << unbalancedLinkControl.
unbLinkedChains.size()
 
  913                             << 
", indexOfFirstWeight = "                           << indexOfFirstWeight
 
  917   P_V auxInitialPosition(m_vectorSpace.zeroVector());
 
  918   double auxInitialLogPrior;
 
  919   double auxInitialLogLikelihood;
 
  921   unsigned int chainIdMax = 0;
 
  922   if (m_env.inter0Rank() >= 0) {
 
  927                         "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
 
  928                         "failed MPI.Bcast() for chainIdMax");
 
  930   struct timeval timevalEntering;
 
  932   iRC = gettimeofday(&timevalEntering, NULL);
 
  935   if (m_env.inter0Rank() >= 0) {
 
  936     unsigned int numberOfPositions = 0;
 
  937     for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
 
  938       numberOfPositions += unbalancedLinkControl.
unbLinkedChains[chainId].numberOfPositions;
 
  941     std::vector<unsigned int> auxBuf(1,0);
 
  943     unsigned int minNumberOfPositions = 0;
 
  944     auxBuf[0] = numberOfPositions;
 
  945     m_env.inter0Comm().template Allreduce<unsigned int>(&auxBuf[0], &minNumberOfPositions, (int) auxBuf.size(), 
RawValue_MPI_MIN,
 
  946                                  "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
 
  947                                  "failed MPI.Allreduce() for min");
 
  949     unsigned int maxNumberOfPositions = 0;
 
  950     auxBuf[0] = numberOfPositions;
 
  951     m_env.inter0Comm().template Allreduce<unsigned int>(&auxBuf[0], &maxNumberOfPositions, (int) auxBuf.size(), 
RawValue_MPI_MAX,
 
  952                                  "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
 
  953                                  "failed MPI.Allreduce() for max");
 
  955     unsigned int sumNumberOfPositions = 0;
 
  956     auxBuf[0] = numberOfPositions;
 
  957     m_env.inter0Comm().template Allreduce<unsigned int>(&auxBuf[0], &sumNumberOfPositions, (int) auxBuf.size(), 
RawValue_MPI_SUM,
 
  958                                  "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
 
  959                                  "failed MPI.Allreduce() for sum");
 
  961     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
  962       *m_env.subDisplayFile() << 
"KEY In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()" 
  964                               << 
", step "                << m_currStep
 
  965                               << 
": chainIdMax = "        << chainIdMax
 
  966                               << 
", numberOfPositions = " << numberOfPositions
 
  967                               << 
", at "                  << ctime(&timevalEntering.tv_sec)
 
  969       *m_env.subDisplayFile() << 
"KEY In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()" 
  971                               << 
", step "                   << m_currStep
 
  972                               << 
": minNumberOfPositions = " << minNumberOfPositions
 
  973                               << 
", avgNumberOfPositions = " << ((double) sumNumberOfPositions)/((double) m_env.inter0Comm().NumProc())
 
  974                               << 
", maxNumberOfPositions = " << maxNumberOfPositions
 
  978   if ((m_debugExponent == 1.) &&
 
  979       (m_currStep      == 10)) {
 
  982   double expRatio = currExponent;
 
  983   if (prevExponent > 0.0) {
 
  984     expRatio /= prevExponent;
 
  986   unsigned int cumulativeNumPositions = 0;
 
  987   for (
unsigned int chainId = 0; chainId < chainIdMax; ++chainId) {
 
  988     unsigned int tmpChainSize = 0;
 
  989     if (m_env.inter0Rank() >= 0) {
 
  990       unsigned int auxIndex = unbalancedLinkControl.
unbLinkedChains[chainId].initialPositionIndexInPreviousChain - indexOfFirstWeight; 
 
  992       auxInitialLogPrior = prevLogTargetValues[auxIndex] - prevLogLikelihoodValues[auxIndex];
 
  993       auxInitialLogLikelihood = expRatio * prevLogLikelihoodValues[auxIndex];
 
  994       tmpChainSize = unbalancedLinkControl.
unbLinkedChains[chainId].numberOfPositions+1; 
 
  995       if ((m_env.subDisplayFile()       ) &&
 
  996           (m_env.displayVerbosity() >= 3)) {
 
  997         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()" 
  999                                 << 
", step "             << m_currStep
 
 1000                                 << 
", chainId = "        << chainId
 
 1001                                 << 
" < "                 << chainIdMax
 
 1002                                 << 
": begin generating " << tmpChainSize
 
 1003                                 << 
" chain positions" 
 1007     auxInitialPosition.mpiBcast(0, m_env.subComm()); 
 
 1009 #if 0 // For debug only 
 1010     for (
int r = 0; r < m_env.subComm().NumProc(); ++r) {
 
 1011       if (r == m_env.subComm().MyPID()) {
 
 1012   std::cout << 
"Vector 'auxInitialPosition at rank " << r
 
 1013                   << 
" has contents "                      << auxInitialPosition
 
 1016       m_env.subComm().Barrier();
 
 1023                           "MLSampling<P_V,P_M>::generateUnbLinkedChains_all()",
 
 1024                           "failed MPI.Bcast() for tmpChainSize");
 
 1029                                                m_options.m_prefix+
"tmp_chain");
 
 1037           "MLSamplingClass<P_V,P_M>::generateUnbLinkedChains_all()",
 
 1038           "failed MPI.Bcast() for auxInitialLogPrior");
 
 1040           "MLSamplingClass<P_V,P_M>::generateUnbLinkedChains_all",
 
 1041           "failed MPI.Bcast() for auxInitialLogLikelihood");
 
 1046           auxInitialLogLikelihood,
 
 1049           &tmpLogLikelihoodValues, 
 
 1050           &tmpLogTargetValues);
 
 1059           &tmpLogLikelihoodValues, 
 
 1060           &tmpLogTargetValues);
 
 1064     cumulativeRunTime    += mcRawInfo.
runTime;
 
 1067     if (m_env.inter0Rank() >= 0) {
 
 1068       if (m_env.exceptionalCircumstance()) {
 
 1069         if ((m_env.subDisplayFile()       ) &&
 
 1070             (m_env.displayVerbosity() >= 0)) { 
 
 1071           P_V tmpVec(m_vectorSpace.zeroVector());
 
 1072           for (
unsigned int i = 0; i < tmpLogLikelihoodValues.
subSequenceSize(); ++i) {
 
 1074             *m_env.subDisplayFile() << 
"DEBUG finalChain[" << cumulativeNumPositions+i << 
"] " 
 1075                                     << 
"= tmpChain["               << i << 
"] = " << tmpVec
 
 1076                                     << 
", tmpLogLikelihoodValues[" << i << 
"] = " << tmpLogLikelihoodValues[i]
 
 1077                                     << 
", tmpLogTargetValues["     << i << 
"] = " << tmpLogTargetValues[i]
 
 1083       cumulativeNumPositions += tmpChainSize;
 
 1084       if (cumulativeNumPositions > 100) m_env.setExceptionalCircumstance(
false);
 
 1086       if ((m_env.subDisplayFile()       ) &&
 
 1087           (m_env.displayVerbosity() >= 3)) {
 
 1088         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()" 
 1090                                 << 
", step "                << m_currStep
 
 1091                                 << 
", chainId = "           << chainId
 
 1092                                 << 
" < "                    << chainIdMax
 
 1094                                 << 
" chain positions" 
 1100       if (currLogLikelihoodValues) {
 
 1101         currLogLikelihoodValues->
append(tmpLogLikelihoodValues,1,tmpLogLikelihoodValues.
subSequenceSize()-1); 
 
 1102         if ((m_env.subDisplayFile()        ) &&
 
 1103             (m_env.displayVerbosity() >= 99) &&
 
 1105           *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()" 
 1107                                   << 
", step "      << m_currStep
 
 1108                                   << 
", chainId = " << chainId
 
 1109                                   << 
", tmpLogLikelihoodValues.subSequenceSize() = " << tmpLogLikelihoodValues.
subSequenceSize()
 
 1110                                   << 
", tmpLogLikelihoodValues[0] = "                << tmpLogLikelihoodValues[0]
 
 1111                                   << 
", tmpLogLikelihoodValues[1] = "                << tmpLogLikelihoodValues[1]
 
 1112                                   << 
", currLogLikelihoodValues[0] = "               << (*currLogLikelihoodValues)[0]
 
 1116       if (currLogTargetValues) {
 
 1122   struct timeval timevalBarrier;
 
 1123   iRC = gettimeofday(&timevalBarrier, NULL);
 
 1126   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1127     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateUnbLinkedChains_all()" 
 1129                             << 
", step "  << m_currStep
 
 1130                             << 
": ended chain loop after " << loopTime << 
" seconds" 
 1131                             << 
", calling fullComm().Barrier() at " << ctime(&timevalBarrier.tv_sec)
 
 1135   m_env.fullComm().Barrier(); 
 
 1137   struct timeval timevalLeaving;
 
 1138   iRC = gettimeofday(&timevalLeaving, NULL);
 
 1141   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1142     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateUnbLinkedChains_all()" 
 1144                             << 
", step "  << m_currStep
 
 1145                             << 
": after " << barrierTime << 
" seconds in fullComm().Barrier()" 
 1146                             << 
", at " << ctime(&timevalLeaving.tv_sec)
 
 1153 #ifdef QUESO_HAS_GLPK 
 1154 template <
class P_V,
class P_M>
 
 1157   std::vector<ExchangeInfoStruct>& exchangeStdVec) 
 
 1159   if (m_env.inter0Rank() != 0) 
return;
 
 1162   struct timeval timevalBIP;
 
 1163   iRC = gettimeofday(&timevalBIP, NULL);
 
 1166   unsigned int Np = (
unsigned int) m_env.inter0Comm().NumProc();
 
 1167   unsigned int Nc = exchangeStdVec.size();
 
 1169   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1170     *m_env.subDisplayFile() << 
"Entering MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1172                             << 
", step "  << m_currStep
 
 1182   lp = glp_create_prob();
 
 1183   glp_set_prob_name(lp, 
"sample");
 
 1188   unsigned int m = Nc+Np-1;
 
 1189   unsigned int n = Nc*Np;
 
 1190   unsigned int ne = Nc*Np + 2*Nc*(Np -1);
 
 1192   glp_add_rows(lp, m); 
 
 1193   for (
int i = 1; i <= (int) Nc; ++i) {
 
 1194     glp_set_row_bnds(lp, i, GLP_FX, 1.0, 1.0);
 
 1195     glp_set_row_name(lp, i, 
"");
 
 1197   for (
int i = (Nc+1); i <= (int) (Nc+Np-1); ++i) {
 
 1198     glp_set_row_bnds(lp, i, GLP_UP, 0.0, 0.0);
 
 1199     glp_set_row_name(lp, i, 
"");
 
 1202   glp_add_cols(lp, n); 
 
 1203   for (
int j = 1; j <= (int) n; ++j) {
 
 1205     glp_set_col_kind(lp, j, GLP_IV);
 
 1206     glp_set_col_bnds(lp, j, GLP_DB, 0.0, 1.0);
 
 1207     glp_set_col_name(lp, j, 
"");
 
 1210   glp_set_obj_dir(lp, GLP_MIN);
 
 1211   for (
int chainId = 0; chainId <= (int) (Nc-1); ++chainId) {
 
 1212     glp_set_obj_coef(lp, (chainId*Np)+1, exchangeStdVec[chainId].numberOfPositions);
 
 1215   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1216     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1218                             << 
", step "  << m_currStep
 
 1219                             << 
": finished setting BIP rows and cols" 
 1229   std::vector<int   > iVec(ne+1,0);
 
 1230   std::vector<int   > jVec(ne+1,0);
 
 1231   std::vector<double> aVec(ne+1,0.);
 
 1233   for (
int i = 1; i <= (int) Nc; ++i) {
 
 1234     for (
int j = 1; j <= (int) Np; ++j) {
 
 1236       jVec[coefId] = (i-1)*Np + j;
 
 1241   for (
int i = 1; i <= (int) (Np-1); ++i) {
 
 1242     for (
int j = 1; j <= (int) Nc; ++j) {
 
 1243       iVec[coefId] = Nc+i;
 
 1244       jVec[coefId] = (j-1)*Np + i;
 
 1245       aVec[coefId] = -((double) exchangeStdVec[j-1].numberOfPositions);
 
 1248       iVec[coefId] = Nc+i;
 
 1249       jVec[coefId] = (j-1)*Np + i + 1;
 
 1250       aVec[coefId] = exchangeStdVec[j-1].numberOfPositions;
 
 1254   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1255     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1257                             << 
", step "  << m_currStep
 
 1258                             << 
": finished setting BIP constraint matrix" 
 1260                             << 
", coefId = " << coefId
 
 1266   glp_load_matrix(lp, ne, &iVec[0], &jVec[0], &aVec[0]);
 
 1268   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1269     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1271                             << 
", step "  << m_currStep
 
 1272                             << 
": finished loading BIP constraint matrix" 
 1273                             << 
", glp_get_num_rows(lp) = " << glp_get_num_rows(lp)
 
 1274                             << 
", glp_get_num_cols(lp) = " << glp_get_num_cols(lp)
 
 1275                             << 
", glp_get_num_nz(lp) = "   << glp_get_num_nz(lp)
 
 1276                             << 
", glp_get_num_int(lp) = "  << glp_get_num_int(lp)
 
 1277                             << 
", glp_get_num_bin(lp) = "  << glp_get_num_bin(lp)
 
 1297   for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1298     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1299       int j = chainId*Np + nodeId + 1;
 
 1301         glp_set_col_stat(lp, j, GLP_BS);
 
 1304         glp_set_col_stat(lp, j, GLP_BS);
 
 1309   for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1310     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1311       int j = chainId*Np + nodeId + 1;
 
 1312       int initialState = glp_mip_col_val(lp, j);
 
 1322   for (
int i = 1; i <= (int) Nc; ++i) {
 
 1323     glp_set_row_stat(lp, i, GLP_NS);
 
 1325   for (
int i = (Nc+1); i <= (int) (Nc+Np-1); ++i) {
 
 1326     glp_set_row_stat(lp, i, GLP_BS);
 
 1336   BIP_routine_struct BIP_routine_info;
 
 1337   BIP_routine_info.env = &m_env;
 
 1338   BIP_routine_info.currLevel = m_currLevel;
 
 1340   glp_iocp BIP_params;
 
 1341   glp_init_iocp(&BIP_params);
 
 1342   BIP_params.presolve = GLP_ON;
 
 1347   int BIP_rc = glp_intopt(lp, &BIP_params);
 
 1349   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1350     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1352                             << 
", step "  << m_currStep
 
 1353                             << 
": finished solving BIP" 
 1354                             << 
", BIP_rc = " << BIP_rc
 
 1363   int BIP_Status = glp_mip_status(lp);
 
 1364   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1365     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1367                             << 
", step "  << m_currStep
 
 1368                             << 
": BIP_Status = " << BIP_Status
 
 1372   switch (BIP_Status) {
 
 1375       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1376         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1378                                 << 
", step "  << m_currStep
 
 1379                                 << 
": BIP solution is optimal" 
 1386       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1387         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1389                                 << 
", step "  << m_currStep
 
 1390                                 << 
": BIP solution is guaranteed to be 'only' feasible" 
 1400   for (
int i = 1; i <= (int) Nc; ++i) {
 
 1403   for (
int i = (Nc+1); i <= (int) (Nc+Np-1); ++i) {
 
 1410   std::vector<unsigned int> finalNumChainsPerNode   (Np,0);
 
 1411   std::vector<unsigned int> finalNumPositionsPerNode(Np,0);
 
 1412   for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1413     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1414       int j = chainId*Np + nodeId + 1;
 
 1415       if (glp_mip_col_val(lp, j) == 0) {
 
 1418       else if (glp_mip_col_val(lp, j) == 1) {
 
 1420         exchangeStdVec[chainId].finalNodeOfInitialPosition = nodeId;
 
 1421         finalNumChainsPerNode   [nodeId] += 1;
 
 1422         finalNumPositionsPerNode[nodeId] += exchangeStdVec[chainId].numberOfPositions;
 
 1430   unsigned int finalMinPosPerNode = *std::min_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
 
 1431   unsigned int finalMaxPosPerNode = *std::max_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
 
 1433   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1434     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1436                             << 
", step "  << m_currStep
 
 1437                             << 
": finished preparing output information" 
 1444   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1445     *m_env.subDisplayFile() << 
"KEY In MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1447                             << 
", step "  << m_currStep
 
 1448                             << 
": solution gives the following redistribution" 
 1450     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1451       *m_env.subDisplayFile() << 
"  KEY In MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1453                               << 
", step "  << m_currStep
 
 1454                               << 
", finalNumChainsPerNode["    << nodeId << 
"] = " << finalNumChainsPerNode[nodeId]
 
 1455                               << 
", finalNumPositionsPerNode[" << nodeId << 
"] = " << finalNumPositionsPerNode[nodeId]
 
 1458     *m_env.subDisplayFile() << 
"  KEY In MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1460                             << 
", step "  << m_currStep
 
 1461                             << 
", finalRatioOfPosPerNode = " << ((double) finalMaxPosPerNode) / ((double)finalMinPosPerNode)
 
 1470   for (
unsigned int nodeId = 1; nodeId < Np; ++nodeId) { 
 
 1471     queso_require_greater_equal_msg(finalNumPositionsPerNode[nodeId-1], finalNumPositionsPerNode[nodeId], 
"Next node should have a number of positions equal or less than the current node");
 
 1474   for (
int i = (
int) (Nc+1); i <= (int) (Nc+Np-1); ++i) {
 
 1475     unsigned int nodeId = i - Nc;
 
 1476     int diff = ((int) finalNumPositionsPerNode[nodeId]) - ((int) finalNumPositionsPerNode[nodeId-1]);
 
 1483   glp_delete_prob(lp);
 
 1486   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1487     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::solveBIP_proc0()" 
 1489                             << 
", step "  << m_currStep
 
 1490                             << 
", after " << bipRunTime << 
" seconds" 
 1496 #endif // QUESO_HAS_GLPK 
 1498 template <
class P_V,
class P_M>
 
 1502   std::vector<ExchangeInfoStruct>&   exchangeStdVec) 
 
 1504   if (m_env.inter0Rank() != 0) 
return;
 
 1507   struct timeval timevalBal;
 
 1508   iRC = gettimeofday(&timevalBal, NULL);
 
 1511   unsigned int Np = m_env.numSubEnvironments();
 
 1512   unsigned int Nc = exchangeStdVec.size();
 
 1514   std::vector<ExchangeInfoStruct> currExchangeStdVec(Nc);
 
 1515   for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1516     currExchangeStdVec[chainId] = exchangeStdVec[chainId];
 
 1517     currExchangeStdVec[chainId].finalNodeOfInitialPosition = currExchangeStdVec[chainId].originalNodeOfInitialPosition; 
 
 1523   unsigned int iterIdMax = 0;
 
 1524   std::vector<unsigned int> currNumChainsPerNode   (Np,0);
 
 1525   std::vector<unsigned int> currNumPositionsPerNode(Np,0);
 
 1526   for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1527     unsigned int nodeId = currExchangeStdVec[chainId].finalNodeOfInitialPosition; 
 
 1528     currNumChainsPerNode   [nodeId] += 1;
 
 1529     currNumPositionsPerNode[nodeId] += currExchangeStdVec[chainId].numberOfPositions;
 
 1530     iterIdMax                       += currExchangeStdVec[chainId].numberOfPositions;
 
 1532   unsigned int currMinPosPerNode = *std::min_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
 
 1533   unsigned int currMaxPosPerNode = *std::max_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
 
 1534   double currRatioOfPosPerNode = ((double) currMaxPosPerNode ) / ((double) currMinPosPerNode);
 
 1541   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1542     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::justBalance_proc0()" 
 1544                             << 
", step "  << m_currStep
 
 1545                             << 
", iter "  << iterId
 
 1546                             << 
", currRatioOfPosPerNode = " << currRatioOfPosPerNode
 
 1548     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1549       *m_env.subDisplayFile() << 
"  KEY In MLSampling<P_V,P_M>::justBalance_proc0()" 
 1551                               << 
", step "  << m_currStep
 
 1552                               << 
", iter "  << iterId
 
 1553                               << 
", currNumChainsPerNode["    << nodeId << 
"] = " << currNumChainsPerNode[nodeId]
 
 1554                               << 
", currNumPositionsPerNode[" << nodeId << 
"] = " << currNumPositionsPerNode[nodeId]
 
 1559   std::vector<std::vector<double> > vectorOfChainSizesPerNode(Np);
 
 1560   while ((iterId                < (
int) iterIdMax                   ) &&
 
 1567     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1568       vectorOfChainSizesPerNode[nodeId].clear(); 
 
 1570     for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1571       unsigned int nodeId = currExchangeStdVec[chainId].finalNodeOfInitialPosition; 
 
 1572       vectorOfChainSizesPerNode[nodeId].push_back(currExchangeStdVec[chainId].numberOfPositions);
 
 1575     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1576       std::sort(vectorOfChainSizesPerNode[nodeId].begin(), vectorOfChainSizesPerNode[nodeId].end());
 
 1577       queso_require_equal_to_msg(vectorOfChainSizesPerNode[nodeId].size(), currNumChainsPerNode[nodeId], 
"inconsistent number of chains in node");
 
 1583     unsigned int currBiggestAmountOfPositionsPerNode  = currNumPositionsPerNode[0];
 
 1584     unsigned int currSmallestAmountOfPositionsPerNode = currNumPositionsPerNode[0];
 
 1585     unsigned int currNodeWithMostPositions = 0;
 
 1586     unsigned int currNodeWithLeastPositions = 0;
 
 1587     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1588       if (currNumPositionsPerNode[nodeId] > currBiggestAmountOfPositionsPerNode) {
 
 1589         currBiggestAmountOfPositionsPerNode = currNumPositionsPerNode[nodeId];
 
 1590         currNodeWithMostPositions = nodeId;
 
 1592       if (currNumPositionsPerNode[nodeId] < currSmallestAmountOfPositionsPerNode) {
 
 1593         currSmallestAmountOfPositionsPerNode = currNumPositionsPerNode[nodeId];
 
 1594         currNodeWithLeastPositions = nodeId;
 
 1598     queso_require_equal_to_msg(currMinPosPerNode, currNumPositionsPerNode[currNodeWithLeastPositions], 
"inconsistent currMinPosPerNode");
 
 1600     queso_require_equal_to_msg(currMaxPosPerNode, currNumPositionsPerNode[currNodeWithMostPositions], 
"inconsistent currMaxPosPerNode");
 
 1602     unsigned int numberOfPositionsToMove = vectorOfChainSizesPerNode[currNodeWithMostPositions][0];
 
 1604     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
 
 1605       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::justBalance_proc0()" 
 1607                               << 
", step "  << m_currStep
 
 1608                               << 
", iter "  << iterId
 
 1609                               << 
", before update" 
 1610                               << 
", node w/ most pos is " 
 1611                               << currNodeWithMostPositions  << 
"(cs=" << currNumChainsPerNode[currNodeWithMostPositions ] << 
", ps=" << currNumPositionsPerNode[currNodeWithMostPositions ] << 
")" 
 1612                               << 
", node w/ least pos is " 
 1613                               << currNodeWithLeastPositions << 
"(cs=" << currNumChainsPerNode[currNodeWithLeastPositions] << 
", ps=" << currNumPositionsPerNode[currNodeWithLeastPositions] << 
")" 
 1614                               << 
", number of pos to move = " << numberOfPositionsToMove
 
 1621     std::vector<ExchangeInfoStruct> newExchangeStdVec(Nc);
 
 1622     for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1623       newExchangeStdVec[chainId] = currExchangeStdVec[chainId];
 
 1626     for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1627       if ((newExchangeStdVec[chainId].finalNodeOfInitialPosition == (
int) currNodeWithMostPositions) &&
 
 1628           (newExchangeStdVec[chainId].numberOfPositions          == numberOfPositionsToMove        )) {
 
 1629         newExchangeStdVec[chainId].finalNodeOfInitialPosition = currNodeWithLeastPositions;
 
 1637     std::vector<unsigned int> newNumChainsPerNode   (Np,0);
 
 1638     std::vector<unsigned int> newNumPositionsPerNode(Np,0);
 
 1639     for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1640       unsigned int nodeId = newExchangeStdVec[chainId].finalNodeOfInitialPosition; 
 
 1641       newNumChainsPerNode   [nodeId] += 1;
 
 1642       newNumPositionsPerNode[nodeId] += newExchangeStdVec[chainId].numberOfPositions;
 
 1645     unsigned int newBiggestAmountOfPositionsPerNode  = newNumPositionsPerNode[0];
 
 1646     unsigned int newSmallestAmountOfPositionsPerNode = newNumPositionsPerNode[0];
 
 1647     unsigned int newNodeWithMostPositions = 0;
 
 1648     unsigned int newNodeWithLeastPositions = 0;
 
 1649     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1650       if (newNumPositionsPerNode[nodeId] > newBiggestAmountOfPositionsPerNode) {
 
 1651         newBiggestAmountOfPositionsPerNode = newNumPositionsPerNode[nodeId];
 
 1652         newNodeWithMostPositions = nodeId;
 
 1654       if (newNumPositionsPerNode[nodeId] < newSmallestAmountOfPositionsPerNode) {
 
 1655         newSmallestAmountOfPositionsPerNode = newNumPositionsPerNode[nodeId];
 
 1656         newNodeWithLeastPositions = nodeId;
 
 1660     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
 
 1661       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::justBalance_proc0()" 
 1663                               << 
", step "  << m_currStep
 
 1664                               << 
", iter "  << iterId
 
 1666                               << 
", node w/ most pos is " 
 1667                               << newNodeWithMostPositions  << 
"(cs=" << newNumChainsPerNode[newNodeWithMostPositions ] << 
", ps=" << newNumPositionsPerNode[newNodeWithMostPositions ] << 
")" 
 1668                               << 
", node w/ least pos is " 
 1669                               << newNodeWithLeastPositions << 
"(cs=" << newNumChainsPerNode[newNodeWithLeastPositions] << 
", ps=" << newNumPositionsPerNode[newNodeWithLeastPositions] << 
")" 
 1673     unsigned int newMinPosPerNode = *std::min_element(newNumPositionsPerNode.begin(), newNumPositionsPerNode.end());
 
 1674     unsigned int newMaxPosPerNode = *std::max_element(newNumPositionsPerNode.begin(), newNumPositionsPerNode.end());
 
 1675     double newRatioOfPosPerNode = ((double) newMaxPosPerNode ) / ((double) newMinPosPerNode);
 
 1677     queso_require_equal_to_msg(newMinPosPerNode, newNumPositionsPerNode[newNodeWithLeastPositions], 
"inconsistent newMinPosPerNode");
 
 1679     queso_require_equal_to_msg(newMaxPosPerNode, newNumPositionsPerNode[newNodeWithMostPositions], 
"inconsistent newMaxPosPerNode");
 
 1681     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 3)) {
 
 1682       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::justBalance_proc0()" 
 1684                               << 
", step "  << m_currStep
 
 1685                               << 
", iter "  << iterId
 
 1686                               << 
", newMaxPosPerNode = "     << newMaxPosPerNode
 
 1687                               << 
", newMinPosPerNode = "     << newMinPosPerNode
 
 1688                               << 
", newRatioOfPosPerNode = " << newRatioOfPosPerNode
 
 1690       for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1691         *m_env.subDisplayFile() << 
"  KEY In MLSampling<P_V,P_M>::justBalance_proc0()" 
 1693                                 << 
", step "  << m_currStep
 
 1694                                 << 
", iter "  << iterId
 
 1695                                 << 
", newNumChainsPerNode["    << nodeId << 
"] = " << newNumChainsPerNode   [nodeId]
 
 1696                                 << 
", newNumPositionsPerNode[" << nodeId << 
"] = " << newNumPositionsPerNode[nodeId]
 
 1704     if (newRatioOfPosPerNode > currRatioOfPosPerNode) {
 
 1711     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1712       currNumChainsPerNode   [nodeId] = 0;
 
 1713       currNumPositionsPerNode[nodeId] = 0;
 
 1715     currRatioOfPosPerNode = newRatioOfPosPerNode;
 
 1716     for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1717       currExchangeStdVec[chainId] = newExchangeStdVec[chainId];
 
 1718       unsigned int nodeId = currExchangeStdVec[chainId].finalNodeOfInitialPosition; 
 
 1719       currNumChainsPerNode   [nodeId] += 1;
 
 1720       currNumPositionsPerNode[nodeId] += currExchangeStdVec[chainId].numberOfPositions;
 
 1722     currMinPosPerNode = *std::min_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
 
 1723     currMaxPosPerNode = *std::max_element(currNumPositionsPerNode.begin(), currNumPositionsPerNode.end());
 
 1724     currRatioOfPosPerNode = ((double) currMaxPosPerNode ) / ((double) currMinPosPerNode);
 
 1730   for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1731     exchangeStdVec[chainId].finalNodeOfInitialPosition = currExchangeStdVec[chainId].finalNodeOfInitialPosition; 
 
 1737   std::vector<unsigned int> finalNumChainsPerNode   (Np,0);
 
 1738   std::vector<unsigned int> finalNumPositionsPerNode(Np,0);
 
 1739   for (
unsigned int chainId = 0; chainId < Nc; ++chainId) {
 
 1740     unsigned int nodeId = exchangeStdVec[chainId].finalNodeOfInitialPosition; 
 
 1741     finalNumChainsPerNode   [nodeId] += 1;
 
 1742     finalNumPositionsPerNode[nodeId] += exchangeStdVec[chainId].numberOfPositions;
 
 1744   unsigned int finalMinPosPerNode = *std::min_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
 
 1745   unsigned int finalMaxPosPerNode = *std::max_element(finalNumPositionsPerNode.begin(), finalNumPositionsPerNode.end());
 
 1746   double finalRatioOfPosPerNode = ((double) finalMaxPosPerNode ) / ((double) finalMinPosPerNode);
 
 1748   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1749     *m_env.subDisplayFile() << 
"KEY In MLSampling<P_V,P_M>::justBalance_proc0()" 
 1751                             << 
", step "  << m_currStep
 
 1752                             << 
": solution gives the following redistribution" 
 1754     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1755       *m_env.subDisplayFile() << 
"  KEY In MLSampling<P_V,P_M>::justBalance_proc0()" 
 1757                               << 
", step "  << m_currStep
 
 1758                               << 
", finalNumChainsPerNode["    << nodeId << 
"] = " << finalNumChainsPerNode[nodeId]
 
 1759                               << 
", finalNumPositionsPerNode[" << nodeId << 
"] = " << finalNumPositionsPerNode[nodeId]
 
 1762     *m_env.subDisplayFile() << 
"  KEY In MLSampling<P_V,P_M>::justBalance_proc0()" 
 1764                             << 
", step "  << m_currStep
 
 1765                             << 
", finalRatioOfPosPerNode = " << finalRatioOfPosPerNode
 
 1773   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1774     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::justBalance_proc0()" 
 1776                             << 
", step "                    << m_currStep
 
 1777                             << 
", iterId = "                << iterId
 
 1778                             << 
", currRatioOfPosPerNode = " << currRatioOfPosPerNode
 
 1779                             << 
", after " << balRunTime << 
" seconds" 
 1786 template <
class P_V,
class P_M>
 
 1790   double                             prevExponent,             
 
 1791   double                             currExponent,             
 
 1794   const std::vector<ExchangeInfoStruct>&  exchangeStdVec,           
 
 1795   const std::vector<unsigned int>&          finalNumChainsPerNode,    
 
 1796   const std::vector<unsigned int>&          finalNumPositionsPerNode, 
 
 1799   if (m_env.inter0Rank() < 0) {
 
 1803   unsigned int Np = (
unsigned int) m_env.inter0Comm().NumProc();
 
 1804   unsigned int Nc = exchangeStdVec.size();
 
 1806   double expRatio = currExponent;
 
 1807   if (prevExponent > 0.0) {
 
 1808     expRatio /= prevExponent;
 
 1811   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1812     *m_env.subDisplayFile() << 
"Entering MLSampling<P_V,P_M>::mpiExchangePositions_inter0()" 
 1814                             << 
", step "  << m_currStep
 
 1825   for (
unsigned int r = 0; r < Np; ++r) {
 
 1829     unsigned int              numberOfInitialPositionsNodeRAlreadyHas = 0;
 
 1830     std::vector<unsigned int> numberOfInitialPositionsNodeRHasToReceiveFromNode(Np,0);
 
 1831     std::vector<unsigned int> indexesOfInitialPositionsNodeRHasToReceiveFromMe(0);
 
 1833     unsigned int              sumOfChainLenghtsNodeRAlreadyHas = 0;
 
 1834     std::vector<unsigned int> chainLenghtsNodeRHasToInherit(0);
 
 1836     for (
unsigned int i = 0; i < Nc; ++i) {
 
 1837       if (exchangeStdVec[i].finalNodeOfInitialPosition == (
int) r) {
 
 1838         if (exchangeStdVec[i].originalNodeOfInitialPosition == (
int) r) {
 
 1839           numberOfInitialPositionsNodeRAlreadyHas++;
 
 1840           sumOfChainLenghtsNodeRAlreadyHas += exchangeStdVec[i].numberOfPositions;
 
 1843           numberOfInitialPositionsNodeRHasToReceiveFromNode[exchangeStdVec[i].originalNodeOfInitialPosition]++;
 
 1844           chainLenghtsNodeRHasToInherit.push_back(exchangeStdVec[i].numberOfPositions);
 
 1845           if (m_env.inter0Rank() == exchangeStdVec[i].originalNodeOfInitialPosition) {
 
 1846             indexesOfInitialPositionsNodeRHasToReceiveFromMe.push_back(exchangeStdVec[i].originalIndexOfInitialPosition);
 
 1852     unsigned int totalNumberOfInitialPositionsNodeRHasToReceive = 0;
 
 1853     for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) {
 
 1854       totalNumberOfInitialPositionsNodeRHasToReceive += numberOfInitialPositionsNodeRHasToReceiveFromNode[nodeId];
 
 1857     unsigned int totalNumberOfChainLenghtsNodeRHasToInherit = chainLenghtsNodeRHasToInherit.size();
 
 1858     unsigned int totalSumOfChainLenghtsNodeRHasToInherit = 0;
 
 1859     for (
unsigned int i = 0; i < totalNumberOfChainLenghtsNodeRHasToInherit; ++i) {
 
 1860       totalSumOfChainLenghtsNodeRHasToInherit += chainLenghtsNodeRHasToInherit[i];
 
 1866     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1867       *m_env.subDisplayFile() << 
"KEY In MLSampling<P_V,P_M>::mpiExchangePositions_inter0()" 
 1869                               << 
", step "  << m_currStep
 
 1871                               << 
", finalNumChainsPerNode[r] = "                       << finalNumChainsPerNode[r]
 
 1872                               << 
", totalNumberOfInitialPositionsNodeRHasToReceive = " << totalNumberOfInitialPositionsNodeRHasToReceive
 
 1873                               << 
", numberOfInitialPositionsNodeRAlreadyHas = "        << numberOfInitialPositionsNodeRAlreadyHas
 
 1875       *m_env.subDisplayFile() << 
"KEY In MLSampling<P_V,P_M>::mpiExchangePositions_inter0()" 
 1877                               << 
", step "  << m_currStep
 
 1879                               << 
", finalNumPositionsPerNode[r] = "             << finalNumPositionsPerNode[r]
 
 1880                               << 
", totalSumOfChainLenghtsNodeRHasToInherit = " << totalSumOfChainLenghtsNodeRHasToInherit
 
 1881                               << 
", sumOfChainLenghtsNodeRAlreadyHas = "        << sumOfChainLenghtsNodeRAlreadyHas
 
 1888     queso_require_equal_to_msg(indexesOfInitialPositionsNodeRHasToReceiveFromMe.size(), numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()], 
"inconsistent number of initial positions to send to node 'r'");
 
 1890     queso_require_equal_to_msg(finalNumChainsPerNode[r], (totalNumberOfInitialPositionsNodeRHasToReceive + numberOfInitialPositionsNodeRAlreadyHas), 
"inconsistent number of chains in node 'r'");
 
 1892     queso_require_equal_to_msg(finalNumPositionsPerNode[r], (totalSumOfChainLenghtsNodeRHasToInherit + sumOfChainLenghtsNodeRAlreadyHas), 
"inconsistent sum of chain lenghts in node 'r'");
 
 1894     queso_require_equal_to_msg(totalNumberOfInitialPositionsNodeRHasToReceive, totalNumberOfChainLenghtsNodeRHasToInherit, 
"inconsistent on total number of initial positions to receive in node 'r'");
 
 1897     indexesOfInitialPositionsNodeRHasToReceiveFromMe.resize(numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()]);
 
 1898     chainLenghtsNodeRHasToInherit.resize                   (totalSumOfChainLenghtsNodeRHasToInherit);
 
 1903     unsigned int dimSize = m_vectorSpace.dimLocal();
 
 1904     unsigned int nValuesPerInitialPosition = dimSize + 2;
 
 1905     P_V auxInitialPosition(m_vectorSpace.zeroVector());
 
 1906     std::vector<double> sendbuf(0);
 
 1907     unsigned int sendcnt = 0;
 
 1908     if (m_env.inter0Rank() != (int) r) {
 
 1909       sendcnt = numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()] * nValuesPerInitialPosition;
 
 1910       sendbuf.resize(sendcnt);
 
 1911       for (
unsigned int i = 0; i < numberOfInitialPositionsNodeRHasToReceiveFromNode[m_env.inter0Rank()]; ++i) {
 
 1912         unsigned int auxIndex = indexesOfInitialPositionsNodeRHasToReceiveFromMe[i];
 
 1914         for (
unsigned int j = 0; j < dimSize; ++j) {
 
 1915           sendbuf[i*nValuesPerInitialPosition + j] = auxInitialPosition[j];
 
 1917       sendbuf[i*nValuesPerInitialPosition + dimSize]     = prevLogLikelihoodValues[auxIndex];
 
 1918       sendbuf[i*nValuesPerInitialPosition + dimSize + 1] = prevLogTargetValues[auxIndex];
 
 1922     std::vector<double> recvbuf(0);
 
 1923     std::vector<int> recvcnts(Np,0); 
 
 1924     if (m_env.inter0Rank() == (int) r) {
 
 1925       recvbuf.resize(totalNumberOfInitialPositionsNodeRHasToReceive * nValuesPerInitialPosition);
 
 1926       for (
unsigned int nodeId = 0; nodeId < Np; ++nodeId) { 
 
 1927         recvcnts[nodeId] = numberOfInitialPositionsNodeRHasToReceiveFromNode[nodeId] * nValuesPerInitialPosition;
 
 1931     std::vector<int> displs(Np,0);
 
 1932     for (
unsigned int nodeId = 1; nodeId < Np; ++nodeId) { 
 
 1933       displs[nodeId] = displs[nodeId-1] + recvcnts[nodeId-1];
 
 1937     if (m_env.inter0Rank() == r) {
 
 1939                                  "MLSampling<P_V,P_M>::mpiExchangePositions_inter0(1)",
 
 1940                                  "failed MPI.Gatherv()");
 
 1944                                  "MLSampling<P_V,P_M>::mpiExchangePositions_inter0(2)",
 
 1945                                  "failed MPI.Gatherv()");
 
 1948     m_env.inter0Comm().template Gatherv<double>(&sendbuf[0], (int) sendcnt,
 
 1949         &recvbuf[0], (
int *) &recvcnts[0], (
int *) &displs[0],
 
 1951         "MLSampling<P_V,P_M>::mpiExchangePositions_inter0()",
 
 1952         "failed MPI.Gatherv()");
 
 1964     if (m_env.inter0Rank() == (int) r) {
 
 1966       unsigned int auxIndex = 0;
 
 1968       for (
unsigned int i = 0; i < Nc; ++i) {
 
 1969         if ((exchangeStdVec[i].finalNodeOfInitialPosition    == (
int) r) &&
 
 1970             (exchangeStdVec[i].originalNodeOfInitialPosition == (
int) r)) {
 
 1971           unsigned int originalIndex = exchangeStdVec[i].originalIndexOfInitialPosition;
 
 1973           balancedLinkControl.
balLinkedChains[auxIndex].initialPosition = 
new P_V(auxInitialPosition);
 
 1974           balancedLinkControl.
balLinkedChains[auxIndex].initialLogPrior = prevLogTargetValues[originalIndex] - prevLogLikelihoodValues[originalIndex];
 
 1975           balancedLinkControl.
balLinkedChains[auxIndex].initialLogLikelihood = expRatio*prevLogLikelihoodValues[originalIndex];
 
 1976           balancedLinkControl.
balLinkedChains[auxIndex].numberOfPositions = exchangeStdVec[i].numberOfPositions;
 
 1981       for (
unsigned int i = 0; i < totalNumberOfInitialPositionsNodeRHasToReceive; ++i) {
 
 1982         for (
unsigned int j = 0; j < dimSize; ++j) {
 
 1983           auxInitialPosition[j] = recvbuf[i*nValuesPerInitialPosition + j];
 
 1985         balancedLinkControl.
balLinkedChains[auxIndex].initialPosition = 
new P_V(auxInitialPosition);
 
 1986         double prevLogLikelihood = recvbuf[i*nValuesPerInitialPosition + dimSize];
 
 1987         double prevLogTarget     = recvbuf[i*nValuesPerInitialPosition + dimSize + 1];
 
 1988         balancedLinkControl.
balLinkedChains[auxIndex].initialLogPrior = prevLogTarget - prevLogLikelihood;
 
 1989         balancedLinkControl.
balLinkedChains[auxIndex].initialLogLikelihood = expRatio*prevLogLikelihood;
 
 1990         balancedLinkControl.
balLinkedChains[auxIndex].numberOfPositions = chainLenghtsNodeRHasToInherit[i]; 
 
 1995     m_env.inter0Comm().Barrier();
 
 1998   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 1999     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::mpiExchangePositions_inter0()" 
 2001                             << 
", step "  << m_currStep
 
 2009 template <
class P_V,
class P_M>
 
 2012   double                                   currExponent,            
 
 2018   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2019     *m_env.subDisplayFile() << 
"\n CHECKPOINTING initiating at level " << m_currLevel
 
 2020                             << 
"\n" << std::endl;
 
 2027   unsigned int quantity2 = currLogLikelihoodValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
 
 2028   unsigned int quantity3 = currLogTargetValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
 
 2029   if (m_env.inter0Rank() >= 0) {
 
 2035   if (m_env.fullRank() == 0) {
 
 2036     std::ofstream* ofsVar = 
new std::ofstream((m_options.m_restartOutput_baseNameForFiles + 
"Control.txt").c_str(),
 
 2037                                               std::ofstream::out | std::ofstream::trunc);
 
 2038     *ofsVar << m_currLevel               << std::endl  
 
 2039             << m_vectorSpace.dimGlobal() << std::endl  
 
 2040             << currExponent              << std::endl  
 
 2041             << currEta                   << std::endl  
 
 2042             << quantity1                 << std::endl; 
 
 2043     unsigned int savedPrecision = ofsVar->precision();
 
 2044     ofsVar->precision(16);
 
 2045     for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
 
 2046       *ofsVar << m_logEvidenceFactors[i] << std::endl;
 
 2048     ofsVar->precision(savedPrecision);
 
 2049     *ofsVar << 
"COMPLETE"                << std::endl; 
 
 2053   m_env.fullComm().Barrier();
 
 2058   char levelSufix[256];
 
 2061   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2062     *m_env.subDisplayFile() << 
"\n CHECKPOINTING chain at level " << m_currLevel
 
 2063                             << 
"\n" << std::endl;
 
 2065   currChain.
unifiedWriteContents(m_options.m_restartOutput_baseNameForFiles + 
"Chain_l" + levelSufix,
 
 2066                                  m_options.m_restartOutput_fileType);
 
 2067   m_env.fullComm().Barrier();
 
 2069   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2070     *m_env.subDisplayFile() << 
"\n CHECKPOINTING like at level " << m_currLevel
 
 2071                             << 
"\n" << std::endl;
 
 2073   currLogLikelihoodValues.
unifiedWriteContents(m_options.m_restartOutput_baseNameForFiles + 
"LogLike_l" + levelSufix,
 
 2074                                                m_options.m_restartOutput_fileType);
 
 2075   m_env.fullComm().Barrier();
 
 2077   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2078     *m_env.subDisplayFile() << 
"\n CHECKPOINTING target at level " << m_currLevel
 
 2079                             << 
"\n" << std::endl;
 
 2081   currLogTargetValues.
unifiedWriteContents(m_options.m_restartOutput_baseNameForFiles + 
"LogTarget_l" + levelSufix,
 
 2082                                            m_options.m_restartOutput_fileType);
 
 2083   m_env.fullComm().Barrier();
 
 2088   if (m_env.fullRank() == 0) {
 
 2089     std::ofstream* ofsVar = 
new std::ofstream((m_options.m_restartOutput_baseNameForFiles + 
"Control_l" + levelSufix + 
".txt").c_str(),
 
 2090                                               std::ofstream::out | std::ofstream::trunc);
 
 2091     *ofsVar << m_currLevel               << std::endl  
 
 2092             << m_vectorSpace.dimGlobal() << std::endl  
 
 2093             << currExponent              << std::endl  
 
 2094             << currEta                   << std::endl  
 
 2095             << quantity1                 << std::endl; 
 
 2096     unsigned int savedPrecision = ofsVar->precision();
 
 2097     ofsVar->precision(16);
 
 2098     for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
 
 2099       *ofsVar << m_logEvidenceFactors[i] << std::endl;
 
 2101     ofsVar->precision(savedPrecision);
 
 2102     *ofsVar << 
"COMPLETE"                << std::endl; 
 
 2106   m_env.fullComm().Barrier();
 
 2108   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2109     *m_env.subDisplayFile() << 
"\n CHECKPOINTING done at level " << m_currLevel
 
 2110                             << 
"\n" << std::endl;
 
 2116 template <
class P_V,
class P_M>
 
 2119   double&                            currExponent,            
 
 2125   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2126     *m_env.subDisplayFile() << 
"\n RESTARTING initiating at level " << m_currLevel
 
 2127                             << 
"\n" << std::endl;
 
 2133   unsigned int vectorSpaceDim  = 0;
 
 2134   unsigned int quantity1       = 0;
 
 2135   std::string  checkingString(
"");
 
 2136   if (m_env.fullRank() == 0) {
 
 2137     std::ifstream* ifsVar = 
new std::ifstream((m_options.m_restartInput_baseNameForFiles + 
"Control.txt").c_str(),
 
 2143     unsigned int numLines = std::count(std::istreambuf_iterator<char>(*ifsVar),
 
 2144                                        std::istreambuf_iterator<char>(),
 
 2146     ifsVar->seekg(0,std::ios_base::beg);
 
 2147     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2148       *m_env.subDisplayFile() << 
"Restart input file has " << numLines
 
 2156     *ifsVar >> m_currLevel; 
 
 2159     m_logEvidenceFactors.clear();
 
 2160     m_logEvidenceFactors.resize(m_currLevel,0.);
 
 2161     *ifsVar >> vectorSpaceDim  
 
 2165     for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
 
 2166       *ifsVar >> m_logEvidenceFactors[i];
 
 2168     *ifsVar >> checkingString; 
 
 2171     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2172       *m_env.subDisplayFile() << 
"Restart input file has the following information:" 
 2173                               << 
"\n m_currLevel = "      << m_currLevel
 
 2174                               << 
"\n vectorSpaceDim = "   << vectorSpaceDim
 
 2175                               << 
"\n currExponent = "     << currExponent
 
 2176                               << 
"\n currEta = "          << currEta
 
 2177                               << 
"\n quantity1 = "        << quantity1;
 
 2178       for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
 
 2179         *m_env.subDisplayFile() << 
"\n [" << i << 
"] = " << m_logEvidenceFactors[i];
 
 2181       *m_env.subDisplayFile() << std::endl;
 
 2184 #if 0 // For debug only 
 2185     std::string tmpString;
 
 2186     for (
unsigned int i = 0; i < 2; ++i) {
 
 2187       *ifsVar >> tmpString;
 
 2188       std::cout << 
"Just read '" << tmpString << 
"'" << std::endl;
 
 2190     while ((lineId < numLines) && (ifsVar->eof() == 
false)) {
 
 2192     ifsVar->ignore(maxCharsPerLine,
'\n');
 
 2197   m_env.fullComm().Barrier();
 
 2202   unsigned int tmpUint = (
unsigned int) m_currLevel;
 
 2204                          "MLSampling<P_V,P_M>::restartML()",
 
 2205                          "failed MPI.Bcast() for m_currLevel");
 
 2206   if (m_env.fullRank() != 0) {
 
 2207     m_currLevel = tmpUint;
 
 2214   if (m_env.fullRank() == 0) {
 
 2215     tmpData[0] = vectorSpaceDim;
 
 2216     tmpData[1] = currExponent;
 
 2217     tmpData[2] = currEta;
 
 2218     tmpData[3] = quantity1;
 
 2219     for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
 
 2220       tmpData[4+i] = m_logEvidenceFactors[i];
 
 2224     m_logEvidenceFactors.clear();
 
 2225     m_logEvidenceFactors.resize(m_currLevel,0.);
 
 2227   m_env.fullComm().Bcast((
void *) &tmpData[0], (
int) tmpData.size(), 
RawValue_MPI_DOUBLE, 0, 
 
 2228                          "MLSampling<P_V,P_M>::restartML()",
 
 2229                          "failed MPI.Bcast() for rest of information read from input file");
 
 2230   if (m_env.fullRank() != 0) {
 
 2231     vectorSpaceDim = tmpData[0];
 
 2232     currExponent   = tmpData[1];
 
 2233     currEta        = tmpData[2];
 
 2234     quantity1      = tmpData[3];
 
 2235     for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
 
 2236       m_logEvidenceFactors[i] = tmpData[4+i];
 
 2244   queso_require_msg(!((currExponent < 0.) || (currExponent > 1.)), 
"read currExponent is not consistent");
 
 2245   queso_require_equal_to_msg((quantity1 % m_env.numSubEnvironments()), 0, 
"read size of chain should be a multiple of the number of subenvironments");
 
 2246   unsigned int subSequenceSize = 0;
 
 2247   subSequenceSize = ((double) quantity1) / ((double) m_env.numSubEnvironments());
 
 2249   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2250     *m_env.subDisplayFile() << 
"Restart input file has the following information" 
 2251                             << 
": subSequenceSize = " << subSequenceSize
 
 2258   char levelSufix[256];
 
 2261   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2262     *m_env.subDisplayFile() << 
"\n RESTARTING chain at level " << m_currLevel
 
 2263                             << 
"\n" << std::endl;
 
 2265   currChain.
unifiedReadContents(m_options.m_restartInput_baseNameForFiles + 
"Chain_l" + levelSufix,
 
 2266                                 m_options.m_restartInput_fileType,
 
 2268   m_env.fullComm().Barrier();
 
 2270   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2271     *m_env.subDisplayFile() << 
"\n RESTARTING like at level " << m_currLevel
 
 2272                             << 
"\n" << std::endl;
 
 2274   currLogLikelihoodValues.
unifiedReadContents(m_options.m_restartInput_baseNameForFiles + 
"LogLike_l" + levelSufix,
 
 2275                                               m_options.m_restartInput_fileType,
 
 2277   m_env.fullComm().Barrier();
 
 2279   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2280     *m_env.subDisplayFile() << 
"\n RESTARTING target at level " << m_currLevel
 
 2281                             << 
"\n" << std::endl;
 
 2283   currLogTargetValues.
unifiedReadContents(m_options.m_restartInput_baseNameForFiles + 
"LogTarget_l" + levelSufix,
 
 2284                                           m_options.m_restartInput_fileType,
 
 2286   m_env.fullComm().Barrier();
 
 2288   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 2)) {
 
 2289     *m_env.subDisplayFile() << 
"\n RESTARTING done at level " << m_currLevel
 
 2290                             << 
"\n" << std::endl;
 
 2296 template <
class P_V,
class P_M>
 
 2300   unsigned int&                        unifiedRequestedNumSamples, 
 
 2305     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2306       *m_env.subDisplayFile() << 
"KEY In MLSampling<P_V,P_M>::generateSequence()" 
 2308                               << 
", currOptions.m_rawChainSize = " << currOptions.
m_rawChainSize  
 2313     struct timeval timevalLevel;
 
 2314     iRC = gettimeofday(&timevalLevel, NULL);
 
 2317     if (m_env.inter0Rank() >= 0) {
 
 2319       m_env.inter0Comm().template Allreduce<unsigned int>(&tmpSize, &unifiedRequestedNumSamples, (int) 1, 
RawValue_MPI_SUM,
 
 2320                                    "MLSampling<P_V,P_M>::generateSequence()",
 
 2321                                    "failed MPI.Allreduce() for requested num samples in level 0");
 
 2328     currLogLikelihoodValues.
setName(currOptions.
m_prefix + 
"rawLogLikelihood");
 
 2335     P_V auxVec(m_vectorSpace.zeroVector());
 
 2339       bool outOfSupport = 
true;
 
 2342         m_priorRv.realizer().realization(auxVec);  
 
 2343         if (m_numDisabledParameters > 0) { 
 
 2344           unsigned int disabledCounter = 0;
 
 2345           for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
 
 2346             if (m_parameterEnabledStatus[paramId] == 
false) {
 
 2352         auxVec.mpiBcast(0, m_env.subComm()); 
 
 2354         outOfSupport = !(m_targetDomain->contains(auxVec));
 
 2355       } 
while (outOfSupport); 
 
 2359 #if 1 // prudencio 2010-08-01 
 2360       currLogLikelihoodValues[i] = likelihoodSynchronizer.callFunction(&auxVec,NULL,NULL,NULL,NULL,NULL,NULL); 
 
 2362       currLogLikelihoodValues[i] = m_likelihoodFunction.lnValue(auxVec,NULL,NULL,NULL,NULL); 
 
 2364       currLogTargetValues[i]     = m_priorRv.pdf().lnValue(auxVec,NULL,NULL,NULL,NULL) + currLogLikelihoodValues[i];
 
 2368     if (m_env.inter0Rank() >= 0) { 
 
 2369 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 2370       if (currOptions.m_rawChainComputeStats) {
 
 2379         currChain.computeStatistics(*currOptions.m_rawChainStatisticalOptionsObj,
 
 2396       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2397         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2400                                 << 
" chain positions" 
 2416 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 2417         if (currOptions.m_filteredChainComputeStats) {
 
 2433     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2434       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2436                               << 
", total level time = " << levelRunTime << 
" seconds" 
 2443 template <
class P_V,
class P_M>
 
 2447   unsigned int&                        unifiedRequestedNumSamples) 
 
 2450   struct timeval timevalStep;
 
 2451   iRC = gettimeofday(&timevalStep, NULL);
 
 2454       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2455         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2457                                 << 
", step "  << m_currStep
 
 2458                                 << 
": beginning step 1 of 11" 
 2465       m_env.inter0Comm().template Allreduce<unsigned int>(&tmpSize, &unifiedRequestedNumSamples, (int) 1, 
RawValue_MPI_SUM,
 
 2466                                    "MLSampling<P_V,P_M>::generateSequence()",
 
 2467                                    "failed MPI.Allreduce() for requested num samples in step 1");
 
 2469       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2470         *m_env.subDisplayFile() << 
"KEY In MLSampling<P_V,P_M>::generateSequence()" 
 2472                                 << 
", step "  << m_currStep
 
 2473                                 << 
", currOptions->m_rawChainSize = " << currOptions->
m_rawChainSize  
 2478   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2479     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()" 
 2481                             << 
", step "  << m_currStep
 
 2482                             << 
", after " << stepRunTime << 
" seconds" 
 2489 template <
class P_V,
class P_M>
 
 2499   unsigned int&                        indexOfFirstWeight,      
 
 2500   unsigned int&                        indexOfLastWeight)       
 
 2503   struct timeval timevalStep;
 
 2504   iRC = gettimeofday(&timevalStep, NULL);
 
 2507       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2508         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2510                                 << 
", step "  << m_currStep
 
 2511                                 << 
": beginning step 2 of 11" 
 2515       prevChain = currChain;
 
 2519       prevLogLikelihoodValues = currLogLikelihoodValues; 
 
 2520       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2521         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step()" 
 2523                                 << 
", step "  << m_currStep
 
 2524                                 << 
", prevLogLikelihoodValues[0] = " << prevLogLikelihoodValues[0]
 
 2527       prevLogTargetValues     = currLogTargetValues;
 
 2529       currLogLikelihoodValues.
clear();
 
 2530       currLogLikelihoodValues.
setName(currOptions->
m_prefix + 
"rawLogLikelihood");
 
 2532       currLogTargetValues.
clear();
 
 2535 #if 0 // For debug only 
 2536       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2537         P_V prevPosition(m_vectorSpace.zeroVector());
 
 2538         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2540                                 << 
", step "  << m_currStep
 
 2545           *m_env.subDisplayFile() << 
"  prevChain[" << i
 
 2546                                   << 
"] = " << prevPosition
 
 2547                                   << 
", prevLogLikelihoodValues[" << i
 
 2548                                   << 
"] = " << prevLogLikelihoodValues[i]
 
 2549                                   << 
", prevLogTargetValues[" << i
 
 2550                                   << 
"] = " << prevLogTargetValues[i]
 
 2558       unsigned int quantity3 = prevLogLikelihoodValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
 
 2559       unsigned int quantity4 = currLogLikelihoodValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
 
 2560       unsigned int quantity5 = prevLogTargetValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
 
 2561       unsigned int quantity6 = currLogTargetValues.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
 
 2562       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2563         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2565                                 << 
", step "  << m_currStep
 
 2566                                 << 
": prevChain.unifiedSequenceSize() = " << quantity1
 
 2567                                 << 
", currChain.unifiedSequenceSize() = " << quantity2
 
 2568                                 << 
", prevLogLikelihoodValues.unifiedSequenceSize() = " << quantity3
 
 2569                                 << 
", currLogLikelihoodValues.unifiedSequenceSize() = " << quantity4
 
 2570                                 << 
", prevLogTargetValues.unifiedSequenceSize() = " << quantity5
 
 2571                                 << 
", currLogTargetValues.unifiedSequenceSize() = " << quantity6
 
 2580       indexOfFirstWeight = 0;
 
 2581       indexOfLastWeight  = indexOfFirstWeight + prevChain.
subSequenceSize()-1;
 
 2584         int r = m_env.inter0Rank();
 
 2586         m_env.inter0Comm().Barrier();
 
 2587         unsigned int auxUint = 0;
 
 2592                                   "MLSampling<P_V,P_M>::generateSequence()",
 
 2593                                   "failed MPI.Recv()");
 
 2595           indexOfFirstWeight = auxUint;
 
 2596           indexOfLastWeight = indexOfFirstWeight + prevChain.
subSequenceSize()-1;
 
 2598         if (r < (m_env.inter0Comm().NumProc()-1)) {
 
 2599           auxUint = indexOfLastWeight + 1;
 
 2602                                   "MLSampling<P_V,P_M>::generateSequence()",
 
 2603                                   "failed MPI.Send()");
 
 2606         m_env.inter0Comm().Barrier();
 
 2610   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2611     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()" 
 2613                             << 
", step "  << m_currStep
 
 2614                             << 
", after " << stepRunTime << 
" seconds" 
 2621 template <
class P_V,
class P_M>
 
 2626   double                               prevExponent,            
 
 2627   double                               failedExponent,          
 
 2628   double&                              currExponent,            
 
 2632   struct timeval timevalStep;
 
 2633   iRC = gettimeofday(&timevalStep, NULL);
 
 2636       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2637         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2639                                 << 
", step "  << m_currStep
 
 2640                                 << 
", failedExponent = " << failedExponent 
 
 2641                                 << 
": beginning step 3 of 11" 
 2645       std::vector<double> exponents(2,0.);
 
 2646       exponents[0] = prevExponent;
 
 2649       double nowExponent = 1.; 
 
 2650       double nowEffectiveSizeRatio = 0.; 
 
 2652       unsigned int nowAttempt = 0;
 
 2653       bool testResult = 
false;
 
 2657       double nowUnifiedEvidenceLnFactor = 0.;
 
 2659         if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2660           *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2662                                   << 
", step "  << m_currStep
 
 2663                                   << 
", failedExponent = " << failedExponent 
 
 2664                                   << 
": entering loop for computing next exponent" 
 2665                                   << 
", with nowAttempt = " << nowAttempt
 
 2669         if (failedExponent > 0.) { 
 
 2670           nowExponent = .5*(prevExponent+failedExponent);
 
 2673           if (nowAttempt > 0) {
 
 2674             if (nowEffectiveSizeRatio > meanEffectiveSizeRatio) {
 
 2675               exponents[0] = nowExponent;
 
 2678               exponents[1] = nowExponent;
 
 2680             nowExponent = .5*(exponents[0] + exponents[1]);
 
 2683         double auxExponent = nowExponent;
 
 2684         if (prevExponent != 0.) {
 
 2685           auxExponent /= prevExponent;
 
 2688         double subWeightRatioSum     = 0.;
 
 2689         double unifiedWeightRatioSum = 0.;
 
 2692           omegaLnDiffSequence[i] = prevLogLikelihoodValues[i]*auxExponent; 
 
 2695 #if 1 // prudenci-2012-07-06 
 2697         double unifiedOmegaLnMax = omegaLnDiffSequence.
unifiedMaxPlain(m_vectorSpace.numOfProcsForStorage() == 1);
 
 2699         double unifiedOmegaLnMin = 0.;
 
 2700         double unifiedOmegaLnMax = 0.;
 
 2701         omegaLnDiffSequence.unifiedMinMaxExtra(m_vectorSpace.numOfProcsForStorage() == 1, 
 
 2703                                                omegaLnDiffSequence.subSequenceSize(),
 
 2708           omegaLnDiffSequence[i] -= unifiedOmegaLnMax;
 
 2709           weightSequence[i] = exp(omegaLnDiffSequence[i]);
 
 2710           subWeightRatioSum += weightSequence[i];
 
 2711 #if 0 // For debug only 
 2712           if ((m_currLevel == 1) && (nowAttempt == 6))  {
 
 2713             if (m_env.subDisplayFile() && (m_env.displayVerbosity() >= 99)) {
 
 2714               *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2716                                       << 
", step "                         << m_currStep
 
 2718                                       << 
", prevLogLikelihoodValues[i] = " << prevLogLikelihoodValues[i]
 
 2719                                       << 
", omegaLnDiffSequence[i] = "     << omegaLnDiffSequence[i]
 
 2720                                       << 
", weightSequence[i] = "          << weightSequence[i]
 
 2727         m_env.inter0Comm().template Allreduce<double>(&subWeightRatioSum, &unifiedWeightRatioSum, (int) 1, 
RawValue_MPI_SUM,
 
 2728                                      "MLSampling<P_V,P_M>::generateSequence()",
 
 2729                                      "failed MPI.Allreduce() for weight ratio sum");
 
 2731         unsigned int auxQuantity = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
 
 2732         nowUnifiedEvidenceLnFactor = log(unifiedWeightRatioSum) + unifiedOmegaLnMax - log(auxQuantity);
 
 2734         double effectiveSampleSize = 0.;
 
 2736           weightSequence[i] /= unifiedWeightRatioSum;
 
 2737           effectiveSampleSize += weightSequence[i]*weightSequence[i];
 
 2748         if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2749           *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2751                                   << 
", step "                                   << m_currStep
 
 2752                                   << 
": nowAttempt = "                           << nowAttempt
 
 2753                                   << 
", prevExponent = "                         << prevExponent
 
 2754                                   << 
", exponents[0] = "                         << exponents[0]
 
 2755                                   << 
", nowExponent = "                          << nowExponent
 
 2756                                   << 
", exponents[1] = "                         << exponents[1]
 
 2757                                   << 
", subWeightRatioSum = "                    << subWeightRatioSum
 
 2758                                   << 
", unifiedWeightRatioSum = "                << unifiedWeightRatioSum
 
 2759                                   << 
", unifiedOmegaLnMax = "                    << unifiedOmegaLnMax
 
 2760                                   << 
", weightSequence.unifiedSequenceSize() = " << auxQuantity
 
 2761                                   << 
", nowUnifiedEvidenceLnFactor = "           << nowUnifiedEvidenceLnFactor
 
 2762                                   << 
", effectiveSampleSize = "                  << effectiveSampleSize
 
 2766 #if 0 // For debug only 
 2767         if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2768           *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2770                                   << 
", step "  << m_currStep
 
 2775           if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2776             *m_env.subDisplayFile() << 
"  weightSequence[" << i
 
 2777                                     << 
"] = "              << weightSequence[i]
 
 2783         double subQuantity = effectiveSampleSize;
 
 2784         effectiveSampleSize = 0.;
 
 2785         m_env.inter0Comm().template Allreduce<double>(&subQuantity, &effectiveSampleSize, (int) 1, 
RawValue_MPI_SUM,
 
 2786                                      "MLSampling<P_V,P_M>::generateSequence()",
 
 2787                                      "failed MPI.Allreduce() for effective sample size");
 
 2789         effectiveSampleSize = 1./effectiveSampleSize;
 
 2790         nowEffectiveSizeRatio = effectiveSampleSize/((double) weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1));
 
 2797         if (failedExponent > 0.) { 
 
 2802           bool aux2 = (nowExponent == 1.                             )
 
 2804                       (nowEffectiveSizeRatio > meanEffectiveSizeRatio);
 
 2807                       (nowEffectiveSizeRatio <= currOptions->m_maxEffectiveSizeRatio);
 
 2808           testResult = aux2 || aux3;
 
 2811         if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2812           *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2814                                   << 
", step "                    << m_currStep
 
 2815                                   << 
": nowAttempt = "            << nowAttempt
 
 2816                                   << 
", prevExponent = "          << prevExponent
 
 2817                                   << 
", failedExponent = "        << failedExponent 
 
 2818                                   << 
", exponents[0] = "          << exponents[0]
 
 2819                                   << 
", nowExponent = "           << nowExponent
 
 2820                                   << 
", exponents[1] = "          << exponents[1]
 
 2821                                   << 
", effectiveSampleSize = "   << effectiveSampleSize
 
 2824                                   << 
", nowEffectiveSizeRatio = " << nowEffectiveSizeRatio
 
 2828                                   << 
", testResult = "            << testResult
 
 2837                                               "MLSampling<P_V,P_M>::generateSequence(), step 3, nowExponent") == 
false) {
 
 2838           if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2839             *m_env.subDisplayFile() << 
"WARNING, In MLSampling<P_V,P_M>::generateSequence()" 
 2841                                     << 
", step "         << m_currStep
 
 2842                                     << 
": nowAttempt = " << nowAttempt
 
 2843                                     << 
", MiscCheck for 'nowExponent' detected a problem" 
 2852                                               "MLSampling<P_V,P_M>::generateSequence(), step 3, testResult") == 
false) {
 
 2853           if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2854             *m_env.subDisplayFile() << 
"WARNING, In MLSampling<P_V,P_M>::generateSequence()" 
 2856                                     << 
", step "         << m_currStep
 
 2857                                     << 
": nowAttempt = " << nowAttempt
 
 2858                                     << 
", MiscCheck for 'testResult' detected a problem" 
 2862       } 
while (testResult == 
false);
 
 2863       currExponent = nowExponent;
 
 2864       if (failedExponent > 0.) { 
 
 2865         m_logEvidenceFactors[m_logEvidenceFactors.size()-1] = nowUnifiedEvidenceLnFactor;
 
 2868         m_logEvidenceFactors.push_back(nowUnifiedEvidenceLnFactor); 
 
 2871       unsigned int quantity1 = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
 
 2872       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2873         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2875                                 << 
", step "                                   << m_currStep
 
 2876                                 << 
": weightSequence.subSequenceSize() = "     << weightSequence.
subSequenceSize()
 
 2877                                 << 
", weightSequence.unifiedSequenceSize() = " << quantity1
 
 2878                                 << 
", failedExponent = "                       << failedExponent 
 
 2879                                 << 
", currExponent = "                         << currExponent
 
 2880                                 << 
", effective ratio = "                      << nowEffectiveSizeRatio
 
 2881                                 << 
", log(evidence factor) = "                 << m_logEvidenceFactors[m_logEvidenceFactors.size()-1]
 
 2882                                 << 
", evidence factor = "                      << exp(m_logEvidenceFactors[m_logEvidenceFactors.size()-1])
 
 2900                                             "MLSampling<P_V,P_M>::generateSequence(), step 3, logEvidenceFactor") == 
false) {
 
 2901         if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2902           *m_env.subDisplayFile() << 
"WARNING, In MLSampling<P_V,P_M>::generateSequence()" 
 2904                                   << 
", step "         << m_currStep
 
 2905                                   << 
", failedExponent = " << failedExponent 
 
 2906                                   << 
": nowAttempt = " << nowAttempt
 
 2907                                   << 
", MiscCheck for 'logEvidenceFactor' detected a problem" 
 2913   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2914     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()" 
 2916                             << 
", step "  << m_currStep
 
 2917                             << 
", failedExponent = " << failedExponent 
 
 2918                             << 
", after " << stepRunTime << 
" seconds" 
 2925 template <
class P_V,
class P_M>
 
 2930   P_M&                                     unifiedCovMatrix) 
 
 2933   struct timeval timevalStep;
 
 2934   iRC = gettimeofday(&timevalStep, NULL);
 
 2937       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 2938         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 2940                                 << 
", step "  << m_currStep
 
 2941                                 << 
": beginning step 4 of 11" 
 2945       P_V auxVec(m_vectorSpace.zeroVector());
 
 2946       P_V subWeightedMeanVec(m_vectorSpace.zeroVector());
 
 2949         subWeightedMeanVec += weightSequence[i]*auxVec;
 
 2953       P_V unifiedWeightedMeanVec(m_vectorSpace.zeroVector());
 
 2954       if (m_env.inter0Rank() >= 0) {
 
 2955         subWeightedMeanVec.mpiAllReduce(
RawValue_MPI_SUM,m_env.inter0Comm(),unifiedWeightedMeanVec);
 
 2958         unifiedWeightedMeanVec = subWeightedMeanVec;
 
 2961       P_V diffVec(m_vectorSpace.zeroVector());
 
 2962       P_M subCovMatrix(m_vectorSpace.zeroVector());
 
 2965         diffVec = auxVec - unifiedWeightedMeanVec;
 
 2966         subCovMatrix += weightSequence[i]*
matrixProduct(diffVec,diffVec);
 
 2969       for (
unsigned int i = 0; i < unifiedCovMatrix.numRowsLocal(); ++i) { 
 
 2970         for (
unsigned int j = 0; j < unifiedCovMatrix.numCols(); ++j) {
 
 2971           double localValue = subCovMatrix(i,j);
 
 2972           double sumValue = 0.;
 
 2973           if (m_env.inter0Rank() >= 0) {
 
 2974             m_env.inter0Comm().template Allreduce<double>(&localValue, &sumValue, (int) 1, 
RawValue_MPI_SUM,
 
 2975                                          "MLSampling<P_V,P_M>::generateSequence()",
 
 2976                                          "failed MPI.Allreduce() for cov matrix");
 
 2979             sumValue = localValue;
 
 2981           unifiedCovMatrix(i,j) = sumValue;
 
 2985       if (m_numDisabledParameters > 0) { 
 
 2986         for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
 
 2987           if (m_parameterEnabledStatus[paramId] == 
false) {
 
 2988             for (
unsigned int i = 0; i < m_vectorSpace.dimLocal(); ++i) {
 
 2989               unifiedCovMatrix(i,paramId) = 0.;
 
 2991             for (
unsigned int j = 0; j < m_vectorSpace.dimLocal(); ++j) {
 
 2992               unifiedCovMatrix(paramId,j) = 0.;
 
 2994             unifiedCovMatrix(paramId,paramId) = 1.;
 
 2999       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3000         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 3002                                 << 
", step "               << m_currStep
 
 3003                                 << 
": unifiedCovMatrix = " << unifiedCovMatrix
 
 3008   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3009     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()" 
 3011                             << 
", step "  << m_currStep
 
 3012                             << 
", after " << stepRunTime << 
" seconds" 
 3019 template <
class P_V,
class P_M>
 
 3022   unsigned int                         unifiedRequestedNumSamples,        
 
 3024   std::vector<unsigned int>&           unifiedIndexCountersAtProc0Only,   
 
 3025   std::vector<double>&                 unifiedWeightStdVectorAtProc0Only) 
 
 3028   struct timeval timevalStep;
 
 3029   iRC = gettimeofday(&timevalStep, NULL);
 
 3032       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3033         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 3035                                 << 
", step "  << m_currStep
 
 3036                                 << 
": beginning step 5 of 11" 
 3040 #if 0 // For debug only 
 3041       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3042         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 3044                                 << 
", step "  << m_currStep
 
 3045                                 << 
", before weightSequence.getUnifiedContentsAtProc0Only()" 
 3050         if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3051           *m_env.subDisplayFile() << 
", weightSequence[" << i
 
 3052                                   << 
"] = "              << weightSequence[i]
 
 3059                                                    unifiedWeightStdVectorAtProc0Only);
 
 3061 #if 0 // For debug only 
 3062       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3063         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 3065                                 << 
", step "  << m_currStep
 
 3066                                 << 
", after weightSequence.getUnifiedContentsAtProc0Only()" 
 3070       for (
unsigned int i = 0; i < unifiedWeightStdVectorAtProc0Only.size(); ++i) {
 
 3071         if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3072           *m_env.subDisplayFile() << 
"  unifiedWeightStdVectorAtProc0Only[" << i
 
 3073                                   << 
"] = "                                 << unifiedWeightStdVectorAtProc0Only[i]
 
 3078       sampleIndexes_proc0(unifiedRequestedNumSamples,        
 
 3079                           unifiedWeightStdVectorAtProc0Only, 
 
 3080                           unifiedIndexCountersAtProc0Only);  
 
 3082       unsigned int auxUnifiedSize = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
 
 3083       if (m_env.inter0Rank() == 0) {
 
 3084         queso_require_equal_to_msg(unifiedIndexCountersAtProc0Only.size(), auxUnifiedSize, 
"wrong output from sampleIndexesAtProc0() in step 5");
 
 3088   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3089     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()" 
 3091                             << 
", step "  << m_currStep
 
 3092                             << 
", after " << stepRunTime << 
" seconds" 
 3099 template <
class P_V,
class P_M>
 
 3103   unsigned int                         indexOfFirstWeight,              
 
 3104   unsigned int                         indexOfLastWeight,               
 
 3105   const std::vector<unsigned int>&     unifiedIndexCountersAtProc0Only, 
 
 3106   bool&                                useBalancedChains,               
 
 3107   std::vector<ExchangeInfoStruct>&   exchangeStdVec)                  
 
 3110   struct timeval timevalStep;
 
 3111   iRC = gettimeofday(&timevalStep, NULL);
 
 3114   useBalancedChains = decideOnBalancedChains_all(currOptions,                     
 
 3117                                                  unifiedIndexCountersAtProc0Only, 
 
 3121   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3122     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()" 
 3124                             << 
", step "  << m_currStep
 
 3125                             << 
", after " << stepRunTime << 
" seconds" 
 3132 template <
class P_V,
class P_M>
 
 3135   bool                                      useBalancedChains,               
 
 3136   unsigned int                              indexOfFirstWeight,              
 
 3137   unsigned int                              indexOfLastWeight,               
 
 3138   const std::vector<unsigned int>&          unifiedIndexCountersAtProc0Only, 
 
 3142   double                                  prevExponent,               
 
 3143   double                                  currExponent,               
 
 3146   std::vector<ExchangeInfoStruct>&        exchangeStdVec,                  
 
 3150   struct timeval timevalStep;
 
 3151   iRC = gettimeofday(&timevalStep, NULL);
 
 3154       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3155         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 3157                                 << 
", step "  << m_currStep
 
 3158                                 << 
": beginning step 7 of 11" 
 3162       if (useBalancedChains) {
 
 3163         prepareBalLinkedChains_inter0(currOptions,                     
 
 3167                                       prevLogLikelihoodValues,         
 
 3168                                       prevLogTargetValues,             
 
 3170                                       balancedLinkControl);            
 
 3173         prepareUnbLinkedChains_inter0(indexOfFirstWeight,              
 
 3175                                       unifiedIndexCountersAtProc0Only, 
 
 3176                                       unbalancedLinkControl);          
 
 3179       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3180         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 3182                                 << 
", step "  << m_currStep
 
 3183                                 << 
": balancedLinkControl.balLinkedChains.size() = "   << balancedLinkControl.
balLinkedChains.size()
 
 3184                                 << 
", unbalancedLinkControl.unbLinkedChains.size() = " << unbalancedLinkControl.
unbLinkedChains.size()
 
 3189   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3190     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()" 
 3192                             << 
", step "  << m_currStep
 
 3193                             << 
", after " << stepRunTime << 
" seconds" 
 3200 template <
class P_V,
class P_M>
 
 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 8 of 11" 
 3222   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3223     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()" 
 3225                             << 
", step "  << m_currStep
 
 3226                             << 
", after " << stepRunTime << 
" seconds" 
 3233 template <
class P_V,
class P_M>
 
 3237   double                                   prevExponent,                      
 
 3238   double                                   currExponent,                      
 
 3241   unsigned int                             indexOfFirstWeight,                
 
 3242   unsigned int                             indexOfLastWeight,                 
 
 3243   const std::vector<double>&               unifiedWeightStdVectorAtProc0Only, 
 
 3248   P_M&                                     unifiedCovMatrix,                  
 
 3252   struct timeval timevalStep;
 
 3253   iRC = gettimeofday(&timevalStep, NULL);
 
 3257       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3258         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 3260                                 << 
", step "  << m_currStep
 
 3261                                 << 
": skipping step 9 of 11" 
 3266       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3267         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()" 
 3269                                 << 
", step "  << m_currStep
 
 3270                                 << 
": beginning step 9 of 11" 
 3274       double beforeEta           = prevEta;
 
 3275       double beforeRejectionRate = 0.;               
 
 3276       bool   beforeRejectionRateIsBelowRange = 
true; 
 
 3278       double nowEta           = prevEta;
 
 3279       double nowRejectionRate = 0.;               
 
 3280       bool   nowRejectionRateIsBelowRange = 
true; 
 
 3282       std::vector<double> etas(2,0.);
 
 3283       etas[0] = beforeEta;
 
 3286       std::vector<double> rejs(2,0.);
 
 3290       unsigned int nowAttempt = 0;
 
 3291       bool testResult = 
false;
 
 3293       bool useMiddlePointLogicForEta = 
false;
 
 3294       P_M nowCovMatrix(unifiedCovMatrix);
 
 3295 #if 0 // KAUST, to check 
 3296       std::vector<double> unifiedWeightStdVectorAtProc0Only(0);
 
 3298                                                    unifiedWeightStdVectorAtProc0Only);
 
 3301         if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3302           *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()" 
 3304                                   << 
", step "  << m_currStep
 
 3305                                   << 
": entering loop for assessing rejection rate" 
 3306                                   << 
", with nowAttempt = "  << nowAttempt
 
 3307                                   << 
", nowRejectionRate = " << nowRejectionRate
 
 3310         nowCovMatrix = unifiedCovMatrix;
 
 3312         if (nowRejectionRate < currOptions->m_minRejectionRate) {
 
 3313           nowRejectionRateIsBelowRange = 
true;
 
 3316           nowRejectionRateIsBelowRange = 
false;
 
 3319           queso_error_msg(
"nowRejectionRate should be out of the requested range at this point of the logic");
 
 3322         if (m_env.inter0Rank() >= 0) { 
 
 3323           if (nowAttempt > 0) {
 
 3324             if (useMiddlePointLogicForEta == 
false) {
 
 3325               if (nowAttempt == 1) {
 
 3328               else if ((beforeRejectionRateIsBelowRange == 
true) &&
 
 3329                        (nowRejectionRateIsBelowRange    == 
true)) {
 
 3332               else if ((beforeRejectionRateIsBelowRange == 
false) &&
 
 3333                        (nowRejectionRateIsBelowRange    == 
false)) {
 
 3336               else if ((beforeRejectionRateIsBelowRange == 
true ) &&
 
 3337                        (nowRejectionRateIsBelowRange    == 
false)) {
 
 3338                 useMiddlePointLogicForEta = 
true;
 
 3341                 etas[0] = std::min(beforeEta,nowEta);
 
 3342                 etas[1] = std::max(beforeEta,nowEta);
 
 3344                 if (etas[0] == beforeEta) {
 
 3345                   rejs[0] = beforeRejectionRate;
 
 3346                   rejs[1] = nowRejectionRate;
 
 3349                   rejs[0] = nowRejectionRate;
 
 3350                   rejs[1] = beforeRejectionRate;
 
 3353               else if ((beforeRejectionRateIsBelowRange == 
false) &&
 
 3354                        (nowRejectionRateIsBelowRange    == 
true )) {
 
 3355                 useMiddlePointLogicForEta = 
true;
 
 3358                 etas[0] = std::min(beforeEta,nowEta);
 
 3359                 etas[1] = std::max(beforeEta,nowEta);
 
 3367             beforeRejectionRate             = nowRejectionRate;
 
 3368             beforeRejectionRateIsBelowRange = nowRejectionRateIsBelowRange;
 
 3369             if (useMiddlePointLogicForEta == 
false) {
 
 3370               if (beforeRejectionRateIsBelowRange) nowEta *= 4.;
 
 3372               if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3373                 *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()" 
 3375                                         << 
", step "  << m_currStep
 
 3376                                         << 
": in loop for assessing rejection rate" 
 3377                                         << 
", with nowAttempt = "  << nowAttempt
 
 3378                                         << 
", useMiddlePointLogicForEta = false" 
 3379                                         << 
", nowEta just updated to value (to be tested) " << nowEta
 
 3384               if (nowRejectionRate > meanRejectionRate) {
 
 3385                 if (rejs[0] > meanRejectionRate) {
 
 3395                 if (rejs[0] < meanRejectionRate) {
 
 3404               nowEta = .5*(etas[0] + etas[1]);
 
 3405               if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3406                 *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()" 
 3408                                         << 
", step "  << m_currStep
 
 3409                                         << 
": in loop for assessing rejection rate" 
 3410                                         << 
", with nowAttempt = " << nowAttempt
 
 3411                                         << 
", useMiddlePointLogicForEta = true" 
 3412                                         << 
", nowEta just updated to value (to be tested) " << nowEta
 
 3413                                         << 
", etas[0] = " << etas[0]
 
 3414                                         << 
", etas[1] = " << etas[1]
 
 3421         nowCovMatrix *= nowEta;
 
 3425         unsigned int originalSubNumSamples = 1 + (
unsigned int) (doubSubNumSamples); 
 
 3426         double       auxDouble             = (double) originalSubNumSamples; 
 
 3427         if ((auxDouble - doubSubNumSamples) < 1.e-8) { 
 
 3428           originalSubNumSamples += 1;
 
 3431         if (m_env.inter0Rank() >= 0) { 
 
 3432           if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3433             *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()" 
 3435                                     << 
", step "  << m_currStep
 
 3436                                     << 
": in loop for assessing rejection rate" 
 3437                                     << 
", about to sample "     << originalSubNumSamples << 
" indexes" 
 3438                                     << 
", meanRejectionRate = " << meanRejectionRate
 
 3444         std::vector<unsigned int> nowUnifiedIndexCountersAtProc0Only(0); 
 
 3445         if (m_env.inter0Rank() >= 0) { 
 
 3446           unsigned int tmpUnifiedNumSamples = originalSubNumSamples*m_env.inter0Comm().NumProc();
 
 3447           sampleIndexes_proc0(tmpUnifiedNumSamples,                
 
 3448                               unifiedWeightStdVectorAtProc0Only,   
 
 3449                               nowUnifiedIndexCountersAtProc0Only); 
 
 3451           unsigned int auxUnifiedSize = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
 
 3452           if (m_env.inter0Rank() == 0) {
 
 3453             queso_require_equal_to_msg(nowUnifiedIndexCountersAtProc0Only.size(), auxUnifiedSize, 
"wrong output from sampleIndexesAtProc0() in step 9");
 
 3456           if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3457             *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()" 
 3459                                     << 
", step "  << m_currStep
 
 3460                                     << 
": in loop for assessing rejection rate" 
 3461                                     << 
", about to distribute sampled assessment indexes" 
 3466         std::vector<ExchangeInfoStruct>        exchangeStdVec(0);
 
 3471         bool useBalancedChains = decideOnBalancedChains_all(currOptions,                        
 
 3474                                                             nowUnifiedIndexCountersAtProc0Only, 
 
 3477         if (m_env.inter0Rank() >= 0) { 
 
 3478           if (useBalancedChains) {
 
 3479             prepareBalLinkedChains_inter0(currOptions,                        
 
 3483                                           prevLogLikelihoodValues,            
 
 3484                                           prevLogTargetValues,                
 
 3489             prepareUnbLinkedChains_inter0(indexOfFirstWeight,                 
 
 3491                                           nowUnifiedIndexCountersAtProc0Only, 
 
 3496         if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3497           *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()" 
 3499                                   << 
", step "  << m_currStep
 
 3500                                   << 
": in loop for assessing rejection rate" 
 3501                                   << 
", about to generate assessment chain" 
 3507                                                    m_options.m_prefix+
"now_chain");
 
 3508         double       nowRunTime    = 0.;
 
 3509         unsigned int nowRejections = 0;
 
 3514 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 3515         bool         savedRawChainComputeStats  = currOptions->m_rawChainComputeStats;
 
 3522         if (m_env.displayVerbosity() >= 999999) {
 
 3526 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 3527         currOptions->m_rawChainComputeStats  = 
false;
 
 3534         if (useBalancedChains) {
 
 3535           generateBalLinkedChains_all(*currOptions,       
 
 3546           generateUnbLinkedChains_all(*currOptions,       
 
 3554                                       prevLogLikelihoodValues,  
 
 3555                                       prevLogTargetValues,      
 
 3566 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 3567         currOptions->m_rawChainComputeStats  = savedRawChainComputeStats;
 
 3573         for (
unsigned int i = 0; i < nowBalLinkControl.
balLinkedChains.size(); ++i) {
 
 3580         if (m_env.inter0Rank() >= 0) { 
 
 3582           unsigned int nowUnifiedRejections = 0;
 
 3583           m_env.inter0Comm().template Allreduce<unsigned int>(&nowRejections, &nowUnifiedRejections, (int) 1, 
RawValue_MPI_SUM,
 
 3584                                        "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
 
 3585                                        "failed MPI.Allreduce() for now rejections");
 
 3587 #if 0 // Round Rock 2009 12 29 
 3588           unsigned int tmpUnifiedNumSamples = 0;
 
 3590                                        "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
 
 3591                                        "failed MPI.Allreduce() for num samples in step 9");
 
 3594           unsigned int tmpUnifiedNumSamples = originalSubNumSamples*m_env.inter0Comm().NumProc();
 
 3595           nowRejectionRate = ((double) nowUnifiedRejections) / ((double) tmpUnifiedNumSamples);
 
 3600                       (nowRejectionRate <= currOptions->m_maxRejectionRate);
 
 3607                                                 "MLSampling<P_V,P_M>::generateSequence_Step09_all(), step 9, testResult") == 
false) {
 
 3608             if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3609               *m_env.subDisplayFile() << 
"WARNING, In MLSampling<P_V,P_M>::generateSequence()" 
 3611                                       << 
", step "         << m_currStep
 
 3612                                       << 
": nowAttempt = " << nowAttempt
 
 3613                                       << 
", MiscCheck for 'testResult' detected a problem" 
 3620         unsigned int tmpUint = (
unsigned int) testResult;
 
 3622                               "MLSampling<P_V,P_M>::generateSequence_Step09_all()",
 
 3623                               "failed MPI.Bcast() for testResult");
 
 3624         testResult = (bool) tmpUint;
 
 3626         if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3627           *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step09_all()" 
 3629                                   << 
", step "               << m_currStep
 
 3630                                   << 
": in loop for assessing rejection rate" 
 3631                                   << 
", nowAttempt = "       << nowAttempt
 
 3632                                   << 
", beforeEta = "        << beforeEta
 
 3633                                   << 
", etas[0] = "          << etas[0]
 
 3634                                   << 
", nowEta = "           << nowEta
 
 3635                                   << 
", etas[1] = "          << etas[1]
 
 3637                                   << 
", nowRejectionRate = " << nowRejectionRate
 
 3643         if (m_env.inter0Rank() >= 0) { 
 
 3648                                                 "MLSampling<P_V,P_M>::generateSequence_Step09_all(), step 9, nowEta") == 
false) {
 
 3649             if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3650               *m_env.subDisplayFile() << 
"WARNING, In MLSampling<P_V,P_M>::generateSequence()" 
 3652                                       << 
", step "         << m_currStep
 
 3653                                       << 
": nowAttempt = " << nowAttempt
 
 3654                                       << 
", MiscCheck for 'nowEta' detected a problem" 
 3659       } 
while (testResult == 
false);
 
 3661       if (currEta != 1.) {
 
 3662         unifiedCovMatrix *= currEta;
 
 3663         if (m_numDisabledParameters > 0) { 
 
 3664           for (
unsigned int paramId = 0; paramId < m_vectorSpace.dimLocal(); ++paramId) {
 
 3665             if (m_parameterEnabledStatus[paramId] == 
false) {
 
 3666               for (
unsigned int i = 0; i < m_vectorSpace.dimLocal(); ++i) {
 
 3667                 unifiedCovMatrix(i,paramId) = 0.;
 
 3669               for (
unsigned int j = 0; j < m_vectorSpace.dimLocal(); ++j) {
 
 3670                 unifiedCovMatrix(paramId,j) = 0.;
 
 3672               unifiedCovMatrix(paramId,paramId) = 1.;
 
 3678       unsigned int quantity1 = weightSequence.
unifiedSequenceSize(m_vectorSpace.numOfProcsForStorage() == 1);
 
 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                                 << 
": weightSequence.subSequenceSize() = "     << weightSequence.
subSequenceSize()
 
 3684                                 << 
", weightSequence.unifiedSequenceSize() = " << quantity1
 
 3685                                 << 
", currEta = "                              << currEta
 
 3686                                 << 
", assessed rejection rate = "              << nowRejectionRate
 
 3692   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3693     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()" 
 3695                             << 
", step "  << m_currStep
 
 3696                             << 
", after " << stepRunTime << 
" seconds" 
 3703 template <
class P_V,
class P_M>
 
 3707   const P_M&                                      unifiedCovMatrix,             
 
 3709   bool                                            useBalancedChains,            
 
 3711   unsigned int                                    indexOfFirstWeight,           
 
 3713   double                                   prevExponent,                       
 
 3714   double                                   currExponent,                       
 
 3719   double&                                         cumulativeRawChainRunTime,    
 
 3720   unsigned int&                                   cumulativeRawChainRejections, 
 
 3725   struct timeval timevalStep;
 
 3726   iRC = gettimeofday(&timevalStep, NULL);
 
 3729       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3730         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 3732                                 << 
", step "  << m_currStep
 
 3733                                 << 
": beginning step 10 of 11" 
 3734                                 << 
", currLogLikelihoodValues = " << currLogLikelihoodValues
 
 3741 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 3742       bool         savedRawChainComputeStats  = currOptions.m_rawChainComputeStats;
 
 3747       if (m_env.displayVerbosity() >= 999999) {
 
 3751 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 3752       currOptions.m_rawChainComputeStats  = 
false;
 
 3757       if (useBalancedChains) {
 
 3758         generateBalLinkedChains_all(currOptions,                  
 
 3761                                     balancedLinkControl,          
 
 3763                                     cumulativeRawChainRunTime,    
 
 3764                                     cumulativeRawChainRejections, 
 
 3765                                     currLogLikelihoodValues,      
 
 3766                                     currLogTargetValues);         
 
 3769         generateUnbLinkedChains_all(currOptions,                  
 
 3772                                     unbalancedLinkControl,        
 
 3777                                     prevLogLikelihoodValues,      
 
 3778                                     prevLogTargetValues,          
 
 3780                                     cumulativeRawChainRunTime,    
 
 3781                                     cumulativeRawChainRejections, 
 
 3782                                     currLogLikelihoodValues,      
 
 3783                                     currLogTargetValues);         
 
 3786       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3787         double tmpValue = INFINITY;
 
 3788         if (currLogLikelihoodValues) tmpValue = (*currLogLikelihoodValues)[0];
 
 3789         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step()" 
 3791                                 << 
", step "  << m_currStep
 
 3792                                 << 
", after chain generatrion" 
 3793                                 << 
", currLogLikelihoodValues[0] = " << tmpValue
 
 3800 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 3801       currOptions.m_rawChainComputeStats  = savedRawChainComputeStats;
 
 3806   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3807     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()" 
 3809                             << 
", step "  << m_currStep
 
 3810                             << 
", after " << stepRunTime << 
" seconds" 
 3817 template <
class P_V,
class P_M>
 
 3821   unsigned int                         unifiedRequestedNumSamples,   
 
 3822   unsigned int                         cumulativeRawChainRejections, 
 
 3826   unsigned int&                        unifiedNumberOfRejections)    
 
 3829   struct timeval timevalStep;
 
 3830   iRC = gettimeofday(&timevalStep, NULL);
 
 3833   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3834     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 3836                             << 
", step "  << m_currStep
 
 3837                             << 
": beginning step 11 of 11" 
 3843 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 3844   if (currOptions->m_rawChainComputeStats) {
 
 3852     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) { 
 
 3853       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step()" 
 3855                               << 
", step "  << m_currStep
 
 3856                               << 
", calling computeStatistics for raw chain" 
 3857                               << 
". Ofstream pointer value = " << filePtrSet.
ofsVar 
 3858                               << 
", statistical options are" 
 3859                               << 
"\n" << *currOptions->m_rawChainStatisticalOptionsObj
 
 3863     currChain.computeStatistics(*currOptions->m_rawChainStatisticalOptionsObj,
 
 3874     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3875       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step()" 
 3877                               << 
", step "  << m_currStep
 
 3878                               << 
", before calling currLogLikelihoodValues.unifiedWriteContents()" 
 3879                               << 
", currLogLikelihoodValues[0] = " << currLogLikelihoodValues[0]
 
 3898     if (filterSpacing == 0) {
 
 3905     currChain.
filter(filterInitialPos,
 
 3909     currLogLikelihoodValues.
filter(filterInitialPos,
 
 3911     currLogLikelihoodValues.
setName(currOptions->
m_prefix + 
"filtLogLikelihood");
 
 3913     currLogTargetValues.
filter(filterInitialPos,
 
 3917 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 3918     if (currOptions->m_filteredChainComputeStats) {
 
 3919       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 10)) { 
 
 3920         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence_Step()" 
 3922                                 << 
", step "  << m_currStep
 
 3923                                 << 
", calling computeStatistics for filtered chain" 
 3924                                 << 
". Ofstream pointer value = " << filePtrSet.
ofsVar 
 3925                                 << 
", statistical options are" 
 3926                                 << 
"\n" << *currOptions->m_rawChainStatisticalOptionsObj
 
 3931       currChain.computeStatistics(*currOptions->m_filteredChainStatisticalOptionsObj,
 
 3956     unsigned int unifiedGeneratedNumSamples = 0;
 
 3957     m_env.inter0Comm().template Allreduce<unsigned int>(&tmpSize, &unifiedGeneratedNumSamples, (int) 1, 
RawValue_MPI_SUM,
 
 3958                                  "MLSampling<P_V,P_M>::generateSequence()",
 
 3959                                  "failed MPI.Allreduce() for generated num samples in step 11");
 
 3963     queso_require_equal_to_msg(unifiedGeneratedNumSamples, unifiedRequestedNumSamples, 
"currChain (linked one) has been generated with invalid size");
 
 3967   m_env.inter0Comm().template Allreduce<unsigned int>(&cumulativeRawChainRejections, &unifiedNumberOfRejections, (int) 1, 
RawValue_MPI_SUM,
 
 3968                                "MLSampling<P_V,P_M>::generateSequence()",
 
 3969                                "failed MPI.Allreduce() for number of rejections");
 
 3972   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 3973     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence_Step()" 
 3975                             << 
", step "  << m_currStep
 
 3976                             << 
", after " << stepRunTime << 
" seconds" 
 3984 template<
class P_V,
class P_M>
 
 3990   m_env               (priorRv.env()),
 
 3991   m_priorRv           (priorRv),
 
 3992   m_likelihoodFunction(likelihoodFunction),
 
 3993   m_vectorSpace       (m_priorRv.imageSet().vectorSpace()),
 
 3995   m_numDisabledParameters (0), 
 
 3996   m_parameterEnabledStatus(m_vectorSpace.dimLocal(),true), 
 
 3997   m_options           (m_env,prefix),
 
 4000   m_debugExponent     (0.),
 
 4001   m_logEvidenceFactors(0),
 
 4003   m_meanLogLikelihood (0.),
 
 4017 template<
class P_V,
class P_M>
 
 4020   m_numDisabledParameters = 0; 
 
 4021   m_parameterEnabledStatus.clear(); 
 
 4022   if (m_targetDomain) 
delete m_targetDomain;
 
 4028 template <
class P_V,
class P_M>
 
 4035   struct timeval timevalRoutineBegin;
 
 4037   iRC = gettimeofday(&timevalRoutineBegin, NULL);
 
 4040   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4041     *m_env.subDisplayFile() << 
"Entering MLSampling<P_V,P_M>::generateSequence()" 
 4042                             << 
", at  "   << ctime(&timevalRoutineBegin.tv_sec)
 
 4043                             << 
", after " << timevalRoutineBegin.tv_sec - m_env.timevalBegin().tv_sec
 
 4044                             << 
" seconds from queso environment instatiation..." 
 4051   double                            currExponent                   = 0.;   
 
 4052   double                            currEta                        = 1.;   
 
 4053   unsigned int                      currUnifiedRequestedNumSamples = 0;
 
 4056                                                             m_options.m_prefix+
"curr_chain");
 
 4064   bool stopAtEndOfLevel = 
false;
 
 4065   char levelPrefix[256];
 
 4076   if (m_options.m_restartInput_baseNameForFiles != 
".") {
 
 4077     restartML(currExponent,            
 
 4080               currLogLikelihoodValues, 
 
 4081               currLogTargetValues);    
 
 4083     if (currExponent == 1.) {
 
 4084       if (lastLevelOptions.m_parameterDisabledSet.size() > 0) { 
 
 4085         for (std::set<unsigned int>::iterator setIt = lastLevelOptions.m_parameterDisabledSet.begin(); setIt != lastLevelOptions.m_parameterDisabledSet.end(); ++setIt) {
 
 4086           unsigned int paramId = *setIt;
 
 4087           if (paramId < m_vectorSpace.dimLocal()) {
 
 4088             m_numDisabledParameters++;
 
 4089             m_parameterEnabledStatus[paramId] = 
false;
 
 4094 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 4095       if (lastLevelOptions.m_rawChainComputeStats) {
 
 4097         m_env.openOutputFile(lastLevelOptions.m_dataOutputFileName,
 
 4099                              lastLevelOptions.m_dataOutputAllowedSet,
 
 4103         currChain.computeStatistics(*lastLevelOptions.m_rawChainStatisticalOptionsObj,
 
 4113         currChain.
unifiedWriteContents              (lastLevelOptions.m_rawChainDataOutputFileName,lastLevelOptions.m_rawChainDataOutputFileType);
 
 4114         currLogLikelihoodValues.
unifiedWriteContents(lastLevelOptions.m_rawChainDataOutputFileName,lastLevelOptions.m_rawChainDataOutputFileType);
 
 4115         currLogTargetValues.
unifiedWriteContents    (lastLevelOptions.m_rawChainDataOutputFileName,lastLevelOptions.m_rawChainDataOutputFileType);
 
 4118       if (lastLevelOptions.m_filteredChainGenerate) {
 
 4120         m_env.openOutputFile(lastLevelOptions.m_dataOutputFileName,
 
 4122                              lastLevelOptions.m_dataOutputAllowedSet,
 
 4126         unsigned int filterInitialPos = (
unsigned int) (lastLevelOptions.m_filteredChainDiscardedPortion * (
double) currChain.
subSequenceSize());
 
 4127         unsigned int filterSpacing    = lastLevelOptions.m_filteredChainLag;
 
 4128         if (filterSpacing == 0) {
 
 4135         currChain.
filter(filterInitialPos,
 
 4137         currChain.
setName(lastLevelOptions.m_prefix + 
"filtChain");
 
 4139         currLogLikelihoodValues.
filter(filterInitialPos,
 
 4141         currLogLikelihoodValues.
setName(lastLevelOptions.m_prefix + 
"filtLogLikelihood");
 
 4143         currLogTargetValues.
filter(filterInitialPos,
 
 4145         currLogTargetValues.
setName(lastLevelOptions.m_prefix + 
"filtLogTarget");
 
 4147 #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS 
 4148         if (lastLevelOptions.m_filteredChainComputeStats) {
 
 4149           currChain.computeStatistics(*lastLevelOptions.m_filteredChainStatisticalOptionsObj,
 
 4158           currChain.
unifiedWriteContents              (lastLevelOptions.m_filteredChainDataOutputFileName,lastLevelOptions.m_filteredChainDataOutputFileType);
 
 4159           currLogLikelihoodValues.
unifiedWriteContents(lastLevelOptions.m_filteredChainDataOutputFileName,lastLevelOptions.m_filteredChainDataOutputFileType);
 
 4160           currLogTargetValues.
unifiedWriteContents    (lastLevelOptions.m_filteredChainDataOutputFileName,lastLevelOptions.m_filteredChainDataOutputFileType);
 
 4170     if (currOptions.m_parameterDisabledSet.size() > 0) { 
 
 4171       for (std::set<unsigned int>::iterator setIt = currOptions.m_parameterDisabledSet.begin(); setIt != currOptions.m_parameterDisabledSet.end(); ++setIt) {
 
 4172         unsigned int paramId = *setIt;
 
 4173         if (paramId < m_vectorSpace.dimLocal()) {
 
 4174           m_numDisabledParameters++;
 
 4175           m_parameterEnabledStatus[paramId] = 
false;
 
 4180     generateSequence_Level0_all(currOptions,                    
 
 4181                                 currUnifiedRequestedNumSamples, 
 
 4183                                 currLogLikelihoodValues,        
 
 4184                                 currLogTargetValues);           
 
 4186     stopAtEndOfLevel = currOptions.m_stopAtEnd;
 
 4187     bool performCheckpoint = stopAtEndOfLevel;
 
 4188     if (m_options.m_restartOutput_levelPeriod > 0) {
 
 4189       performCheckpoint = performCheckpoint || ( ((m_currLevel + 1) % m_options.m_restartOutput_levelPeriod) == 0 );
 
 4191     if (performCheckpoint) {
 
 4192       checkpointML(currExponent,            
 
 4195                    currLogLikelihoodValues, 
 
 4196                    currLogTargetValues);    
 
 4202   double minLogLike = -INFINITY;
 
 4203   double maxLogLike =  INFINITY;
 
 4208   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4209     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4211                             << 
", sub minLogLike = " << minLogLike
 
 4212                             << 
", sub maxLogLike = " << maxLogLike
 
 4216   m_env.fullComm().Barrier();
 
 4218   minLogLike = -INFINITY;
 
 4219   maxLogLike =  INFINITY;
 
 4220   currLogLikelihoodValues.
unifiedMinMaxExtra(m_vectorSpace.numOfProcsForStorage() == 1,
 
 4225   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4226     *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4228                             << 
", unified minLogLike = " << minLogLike
 
 4229                             << 
", unified maxLogLike = " << maxLogLike
 
 4236   while ((currExponent     <  1.   ) && 
 
 4237          (stopAtEndOfLevel == 
false)) {
 
 4240     struct timeval timevalLevelBegin;
 
 4242     iRC = gettimeofday(&timevalLevelBegin, NULL);
 
 4244     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4245       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4247                               << 
", at  "   << ctime(&timevalLevelBegin.tv_sec)
 
 4248                               << 
", after " << timevalLevelBegin.tv_sec - timevalRoutineBegin.tv_sec
 
 4249                               << 
" seconds from entering the routine" 
 4250                               << 
", after " << timevalLevelBegin.tv_sec - m_env.timevalBegin().tv_sec
 
 4251                               << 
" seconds from queso environment instatiation" 
 4256     struct timeval timevalLevel;
 
 4257     iRC = gettimeofday(&timevalLevel, NULL);
 
 4258     double       cumulativeRawChainRunTime    = 0.;
 
 4259     unsigned int cumulativeRawChainRejections = 0;
 
 4261     bool   tryExponentEta = 
true; 
 
 4262     double failedExponent = 0.;   
 
 4263     double failedEta      = 0.;   
 
 4269     double                             prevExponent          = 0.;    
 
 4270     unsigned int                              indexOfFirstWeight    = 0;     
 
 4271     unsigned int                              indexOfLastWeight     = 0;     
 
 4272     P_M*                                      unifiedCovMatrix      = NULL;  
 
 4273     bool                                      useBalancedChains     = 
false; 
 
 4279     unsigned int exponentEtaTriedAmount = 0;
 
 4280     while (tryExponentEta) { 
 
 4281       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4282         *m_env.subDisplayFile() << 
"In IMLSampling<P_V,P_M>::generateSequence()" 
 4284                                 << 
", beginning 'do-while(tryExponentEta)" 
 4285                                 << 
": failedExponent = " << failedExponent
 
 4286                                 << 
", failedEta = "      << failedEta
 
 4300         unsigned int paramId = *setIt;
 
 4301         if (paramId < m_vectorSpace.dimLocal()) {
 
 4302           m_numDisabledParameters++;
 
 4303           m_parameterEnabledStatus[paramId] = 
false;
 
 4308     if (m_env.inter0Rank() >= 0) {
 
 4309       generateSequence_Step01_inter0(currOptions,                     
 
 4310                                      currUnifiedRequestedNumSamples); 
 
 4317     prevExponent                   = currExponent;
 
 4318     double       prevEta                        = currEta;
 
 4319     unsigned int prevUnifiedRequestedNumSamples = currUnifiedRequestedNumSamples;
 
 4322                                                       m_options.m_prefix+
"prev_chain");
 
 4324     indexOfFirstWeight = 0;
 
 4325     indexOfLastWeight  = 0;
 
 4328     if (m_env.inter0Rank() >= 0) {
 
 4329       generateSequence_Step02_inter0(currOptions,             
 
 4331                                      currLogLikelihoodValues, 
 
 4333                                      currLogTargetValues,     
 
 4335                                      prevLogLikelihoodValues, 
 
 4336                                      prevLogTargetValues,     
 
 4347     if (m_env.inter0Rank() >= 0) {
 
 4348       generateSequence_Step03_inter0(currOptions,             
 
 4349                                      prevLogLikelihoodValues, 
 
 4358                           "MLSampling<P_V,P_M>::generateSequence()",
 
 4359                           "failed MPI.Bcast() for currExponent");
 
 4360     m_debugExponent = currExponent;
 
 4362     if (currExponent == 1.) {
 
 4363       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4364         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4366                                 << 
", step "  << m_currStep
 
 4367                                 << 
": copying 'last' level options to current options"  
 4371       currOptions = &lastLevelOptions;
 
 4373       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4374         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4376                                 << 
", step "  << m_currStep
 
 4377                                 << 
": after copying 'last' level options to current options, the current options are" 
 4378                                 << 
"\n" << *currOptions
 
 4382       if (m_env.inter0Rank() >= 0) {
 
 4386         m_env.inter0Comm().template Allreduce<unsigned int>(&tmpSize, &currUnifiedRequestedNumSamples, (int) 1, 
RawValue_MPI_SUM,
 
 4387                                      "MLSampling<P_V,P_M>::generateSequence()",
 
 4388                                      "failed MPI.Allreduce() for requested num samples in step 3");
 
 4396     P_V oneVec(m_vectorSpace.zeroVector());
 
 4399     unifiedCovMatrix = NULL;
 
 4400     if (m_env.inter0Rank() >= 0) {
 
 4401       unifiedCovMatrix = m_vectorSpace.newMatrix();
 
 4404       unifiedCovMatrix = 
new P_M(oneVec);
 
 4407     if (m_env.inter0Rank() >= 0) {
 
 4408       generateSequence_Step04_inter0(*prevChain,         
 
 4417     std::vector<unsigned int> unifiedIndexCountersAtProc0Only(0);
 
 4418     std::vector<double>       unifiedWeightStdVectorAtProc0Only(0); 
 
 4419     if (m_env.inter0Rank() >= 0) {
 
 4420       generateSequence_Step05_inter0(currUnifiedRequestedNumSamples,     
 
 4422                                      unifiedIndexCountersAtProc0Only,    
 
 4423                                      unifiedWeightStdVectorAtProc0Only); 
 
 4430     useBalancedChains = 
false;
 
 4431     std::vector<ExchangeInfoStruct> exchangeStdVec(0);
 
 4433     generateSequence_Step06_all(currOptions,                     
 
 4436                                 unifiedIndexCountersAtProc0Only, 
 
 4447     if (m_env.inter0Rank() >= 0) {
 
 4448       generateSequence_Step07_inter0(useBalancedChains,               
 
 4451                                      unifiedIndexCountersAtProc0Only, 
 
 4452                                      *unbalancedLinkControl,          
 
 4457                                      prevLogLikelihoodValues,         
 
 4458                                      prevLogTargetValues,             
 
 4460                                      *balancedLinkControl);           
 
 4471                                                     m_likelihoodFunction,
 
 4479     generateSequence_Step08_all(*currPdf,
 
 4486     generateSequence_Step09_all(*prevChain,                        
 
 4489                                 prevLogLikelihoodValues,         
 
 4490                                 prevLogTargetValues,             
 
 4493                                 unifiedWeightStdVectorAtProc0Only, 
 
 4501     tryExponentEta = 
false; 
 
 4503         (currEta < currOptions->m_minAcceptableEta)) {
 
 4504       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4505         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4507                                 << 
", preparing to retry ExponentEta" 
 4508                                 << 
": currExponent = " << currExponent
 
 4509                                 << 
", currEta = "      << currEta
 
 4512       exponentEtaTriedAmount++;
 
 4513       tryExponentEta = 
true;
 
 4514       failedExponent = currExponent;
 
 4515       failedEta      = currEta;
 
 4523       delete balancedLinkControl;    
 
 4524       balancedLinkControl   = NULL;  
 
 4525       delete unbalancedLinkControl;  
 
 4526       unbalancedLinkControl = NULL;  
 
 4528       delete unifiedCovMatrix;       
 
 4529       unifiedCovMatrix = NULL;       
 
 4531       currExponent                   = prevExponent;
 
 4533       currUnifiedRequestedNumSamples = prevUnifiedRequestedNumSamples;
 
 4536       currChain = (*prevChain);      
 
 4540       currLogLikelihoodValues        = prevLogLikelihoodValues;
 
 4541       currLogTargetValues            = prevLogTargetValues;
 
 4545     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) { 
 
 4546       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4548                               << 
", exited 'do-while(tryExponentEta)" 
 4549                               << 
", failedExponent = " << failedExponent
 
 4550                               << 
", failedEta = "      << failedEta
 
 4559     generateSequence_Step10_all(*currOptions,                 
 
 4563                                 *unbalancedLinkControl,       
 
 4568                                 prevLogLikelihoodValues,      
 
 4569                                 prevLogTargetValues,          
 
 4570                                 *balancedLinkControl,         
 
 4572                                 cumulativeRawChainRunTime,    
 
 4573                                 cumulativeRawChainRejections, 
 
 4574                                 &currLogLikelihoodValues,     
 
 4575                                 &currLogTargetValues);        
 
 4581     bool performCheckpoint = stopAtEndOfLevel;
 
 4582     if (m_options.m_restartOutput_levelPeriod > 0) {
 
 4583       performCheckpoint = performCheckpoint || ( ((m_currLevel + 1) % m_options.m_restartOutput_levelPeriod) == 0 );
 
 4584       if (currExponent == 1.) {
 
 4585         performCheckpoint = 
true;
 
 4588     if (performCheckpoint) {
 
 4589       checkpointML(currExponent,            
 
 4592                    currLogLikelihoodValues, 
 
 4593                    currLogTargetValues);    
 
 4600       delete unifiedCovMatrix;
 
 4602       for (
unsigned int i = 0; i < balancedLinkControl->
balLinkedChains.size(); ++i) {
 
 4614     unsigned int unifiedNumberOfRejections = 0;
 
 4615     if (m_env.inter0Rank() >= 0) {
 
 4616       generateSequence_Step11_inter0(currOptions,                      
 
 4617                                      currUnifiedRequestedNumSamples,   
 
 4618                                      cumulativeRawChainRejections,     
 
 4620                                      currLogLikelihoodValues,          
 
 4621                                      currLogTargetValues,              
 
 4622                                      unifiedNumberOfRejections);       
 
 4625     minLogLike = -INFINITY;
 
 4626     maxLogLike =  INFINITY;
 
 4631     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4632       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4634                               << 
", sub minLogLike = " << minLogLike
 
 4635                               << 
", sub maxLogLike = " << maxLogLike
 
 4639     m_env.fullComm().Barrier();
 
 4641     minLogLike = -INFINITY;
 
 4642     maxLogLike =  INFINITY;
 
 4643     currLogLikelihoodValues.
unifiedMinMaxExtra(m_vectorSpace.numOfProcsForStorage() == 1,
 
 4648     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4649       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4651                               << 
", unified minLogLike = " << minLogLike
 
 4652                               << 
", unified maxLogLike = " << maxLogLike
 
 4660     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4661       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4664                               << 
" chain positions" 
 4665                               << 
", cumulativeRawChainRunTime = "    << cumulativeRawChainRunTime << 
" seconds" 
 4666                               << 
", total level time = "             << levelRunTime              << 
" seconds" 
 4667                               << 
", cumulativeRawChainRejections = " << cumulativeRawChainRejections
 
 4668                               << 
" (" << 100.*((double) cumulativeRawChainRejections)/((double) currOptions->
m_rawChainSize)
 
 4669                               << 
"% at this processor)" 
 4670                               << 
" (" << 100.*((double) unifiedNumberOfRejections)/((double) currUnifiedRequestedNumSamples)
 
 4671                               << 
"% over all processors)" 
 4672                               << 
", stopAtEndOfLevel = " << stopAtEndOfLevel
 
 4676     if (m_env.inter0Rank() >= 0) {
 
 4677       double minCumulativeRawChainRunTime = 0.;
 
 4678       m_env.inter0Comm().template Allreduce<double>(&cumulativeRawChainRunTime, &minCumulativeRawChainRunTime, (int) 1, 
RawValue_MPI_MIN,
 
 4679                                    "MLSampling<P_V,P_M>::generateSequence()",
 
 4680                                    "failed MPI.Allreduce() for min cumulative raw chain run time");
 
 4682       double maxCumulativeRawChainRunTime = 0.;
 
 4683       m_env.inter0Comm().template Allreduce<double>(&cumulativeRawChainRunTime, &maxCumulativeRawChainRunTime, (int) 1, 
RawValue_MPI_MAX,
 
 4684                                    "MLSampling<P_V,P_M>::generateSequence()",
 
 4685                                    "failed MPI.Allreduce() for max cumulative raw chain run time");
 
 4687       double avgCumulativeRawChainRunTime = 0.;
 
 4688       m_env.inter0Comm().template Allreduce<double>(&cumulativeRawChainRunTime, &avgCumulativeRawChainRunTime, (int) 1, 
RawValue_MPI_SUM,
 
 4689                                    "MLSampling<P_V,P_M>::generateSequence()",
 
 4690                                    "failed MPI.Allreduce() for sum cumulative raw chain run time");
 
 4691       avgCumulativeRawChainRunTime /= ((double) m_env.inter0Comm().NumProc());
 
 4693       double minLevelRunTime = 0.;
 
 4694       m_env.inter0Comm().template Allreduce<double>(&levelRunTime, &minLevelRunTime, (int) 1, 
RawValue_MPI_MIN,
 
 4695                                    "MLSampling<P_V,P_M>::generateSequence()",
 
 4696                                    "failed MPI.Allreduce() for min level run time");
 
 4698       double maxLevelRunTime = 0.;
 
 4699       m_env.inter0Comm().template Allreduce<double>(&levelRunTime, &maxLevelRunTime, (int) 1, 
RawValue_MPI_MAX,
 
 4700                                    "MLSampling<P_V,P_M>::generateSequence()",
 
 4701                                    "failed MPI.Allreduce() for max level run time");
 
 4703       double avgLevelRunTime = 0.;
 
 4704       m_env.inter0Comm().template Allreduce<double>(&levelRunTime, &avgLevelRunTime, (int) 1, 
RawValue_MPI_SUM,
 
 4705                                    "MLSampling<P_V,P_M>::generateSequence()",
 
 4706                                    "failed MPI.Allreduce() for sum level run time");
 
 4707       avgLevelRunTime /= ((double) m_env.inter0Comm().NumProc());
 
 4709       if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4710         *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4712                                 << 
": min cumul seconds = " << minCumulativeRawChainRunTime
 
 4713                                 << 
", avg cumul seconds = " << avgCumulativeRawChainRunTime
 
 4714                                 << 
", max cumul seconds = " << maxCumulativeRawChainRunTime
 
 4715                                 << 
", min level seconds = " << minLevelRunTime
 
 4716                                 << 
", avg level seconds = " << avgLevelRunTime
 
 4717                                 << 
", max level seconds = " << maxLevelRunTime
 
 4722     if (currExponent != 1.) 
delete currOptions;
 
 4724     struct timeval timevalLevelEnd;
 
 4726     iRC = gettimeofday(&timevalLevelEnd, NULL);
 
 4728     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4729       *m_env.subDisplayFile() << 
"Getting at the end of level " << m_currLevel+
LEVEL_REF_ID 
 4730                               << 
", as part of a 'while' on levels" 
 4731                               << 
", at  "   << ctime(&timevalLevelEnd.tv_sec)
 
 4732                               << 
", after " << timevalLevelEnd.tv_sec - timevalRoutineBegin.tv_sec
 
 4733                               << 
" seconds from entering the routine" 
 4734                               << 
", after " << timevalLevelEnd.tv_sec - m_env.timevalBegin().tv_sec
 
 4735                               << 
" seconds from queso environment instatiation" 
 4749   if (m_env.inter0Rank() >= 0) { 
 
 4752     for (
unsigned int i = 0; i < m_logEvidenceFactors.size(); ++i) {
 
 4753       m_logEvidence += m_logEvidenceFactors[i];
 
 4756 #if 1 // prudenci-2012-07-06 
 4757     m_meanLogLikelihood = currLogLikelihoodValues.
unifiedMeanPlain(m_vectorSpace.numOfProcsForStorage() == 1);
 
 4759     m_meanLogLikelihood = currLogLikelihoodValues.
unifiedMeanExtra(m_vectorSpace.numOfProcsForStorage() == 1,
 
 4764     m_eig = m_meanLogLikelihood - m_logEvidence;
 
 4766     if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4767       *m_env.subDisplayFile() << 
"In MLSampling<P_V,P_M>::generateSequence()" 
 4768                               << 
", log(evidence) = "     << m_logEvidence
 
 4769                               << 
", evidence = "          << exp(m_logEvidence)
 
 4770                               << 
", meanLogLikelihood = " << m_meanLogLikelihood
 
 4771                               << 
", eig = "               << m_eig
 
 4777                         "MLSampling<P_V,P_M>::generateSequence()",
 
 4778                         "failed MPI.Bcast() for m_logEvidence");
 
 4781                         "MLSampling<P_V,P_M>::generateSequence()",
 
 4782                         "failed MPI.Bcast() for m_meanLogLikelihood");
 
 4785                         "MLSampling<P_V,P_M>::generateSequence()",
 
 4786                         "failed MPI.Bcast() for m_eig");
 
 4791   workingChain.
clear();
 
 4793   P_V auxVec(m_vectorSpace.zeroVector());
 
 4795     if (m_env.inter0Rank() >= 0) {
 
 4801   if (workingLogLikelihoodValues) *workingLogLikelihoodValues = currLogLikelihoodValues;
 
 4802   if (workingLogTargetValues    ) *workingLogTargetValues     = currLogTargetValues;
 
 4804   struct timeval timevalRoutineEnd;
 
 4806   iRC = gettimeofday(&timevalRoutineEnd, NULL);
 
 4808   if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) {
 
 4809     *m_env.subDisplayFile() << 
"Leaving MLSampling<P_V,P_M>::generateSequence()" 
 4810                             << 
", at  "   << ctime(&timevalRoutineEnd.tv_sec)
 
 4811                             << 
", after " << timevalRoutineEnd.tv_sec - timevalRoutineBegin.tv_sec
 
 4812                             << 
" seconds from entering the routine" 
 4813                             << 
", after " << timevalRoutineEnd.tv_sec - m_env.timevalBegin().tv_sec
 
 4814                             << 
" seconds from queso environment instatiation" 
 4821 template<
class P_V,
class P_M>
 
 4822 std::ostream& operator<<(std::ostream& os, const MLSampling<P_V,P_M>& obj)
 
 4829 template <
class P_V,
class P_M>
 
 4832   return m_logEvidence;
 
 4835 template <
class P_V,
class P_M>
 
 4838   return m_meanLogLikelihood;
 
 4841 template <
class P_V,
class P_M>
 
double m_filteredChainDiscardedPortion
Initial discarded portion for chain filtering. 
 
double logEvidence() const 
Method to calculate the logarithm of the evidence. 
 
void generateSequence_Step01_inter0(const MLSamplingLevelOptions *currOptions, unsigned int &unifiedRequestedNumSamples)
Reads options for the ML algorithm (Step 01 from ML algorithm). 
 
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, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, 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). 
 
double m_maxEffectiveSizeRatio
Maximum allowed effective size ratio wrt previous level. 
 
void setPositionValues(unsigned int posId, const V &vec)
Set the values in vec at position posId of the sequence. 
 
bool m_filteredChainGenerate
Whether or not to generate filtered chain. 
 
void setName(const std::string &newName)
Changes the name of the sequence of vectors. 
 
virtual unsigned int subSequenceSize() const =0
Size of the sub-sequence of vectors. See template specialization. 
 
unsigned int numberOfPositions
 
double MiscGetEllapsedSeconds(struct timeval *timeval0)
 
bool MiscCheckForSameValueInAllNodes(T &inputValue, double acceptableTreshold, const MpiComm &comm, const char *whereString)
 
unsigned int originalIndexOfInitialPosition
 
std::ofstream * subDisplayFile() const 
Access function for m_subDisplayFile (displays file on stream). 
 
#define queso_require_greater_equal_msg(expr1, expr2, msg)
 
double m_covRejectionRate
c.o.v. for judging attempted rejection rate at current level. 
 
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...
 
const T & unifiedMeanPlain(bool useOnlyInter0Comm) const 
Finds the mean value of the unified sequence of scalars. 
 
double m_minEffectiveSizeRatio
Minimum allowed effective size ratio wrt previous level. 
 
A templated class for a finite distribution. 
 
double meanLogLikelihood() const 
Method to calculate the mean of the logarithm of the likelihood. 
 
std::string m_dataOutputFileName
Name of generic output file. 
 
void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)
Reads the unified sequence from a file. 
 
double m_minRejectionRate
minimum allowed attempted rejection rate at current level 
 
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...
 
void getPositionValues(unsigned int posId, V &vec) const 
Gets the values of the sequence at position posId and stores them at vec. 
 
bool m_initialPositionUsePreviousLevelLikelihood
Use previous level likelihood for initial chain position instead of re-computing it from target pdf...
 
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). 
 
void clear()
Clears the sequence of scalars. 
 
void append(const ScalarSequence< T > &src, unsigned int srcInitialPos, unsigned int srcNumPos)
Appends the scalar sequence src to this sequence. 
 
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)
 
VectorSet< V, M > * InstantiateIntersection(const VectorSet< V, M > &domain1, const VectorSet< V, M > &domain2)
This method calculates the intersection of domain1 and domain2. 
 
void filter(unsigned int initialPos, unsigned int spacing)
Filters positions in the sequence of vectors. 
 
virtual void setPositionValues(unsigned int posId, const V &vec)=0
Set the values in vec at position posId of the sequence. See template specialization. 
 
int originalNodeOfInitialPosition
 
void prepareUnbLinkedChains_inter0(unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl)
 
unsigned int unifiedSequenceSize() const 
Calculates the size of the unified sequence of vectors. 
 
void getRawChainInfo(MHRawChainInfoStruct &info) const 
Gets information from the raw chain. 
 
unsigned int m_rawChainSize
Size of raw chain. 
 
bool m_scaleCovMatrix
Whether or not scale proposal covariance matrix. 
 
bool decideOnBalancedChains_all(const MLSamplingLevelOptions *currOptions, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, std::vector< ExchangeInfoStruct > &exchangeStdVec)
 
void sampleIndexes_proc0(unsigned int unifiedRequestedNumSamples, const std::vector< double > &unifiedWeightStdVectorAtProc0Only, std::vector< unsigned int > &unifiedIndexCountersAtProc0Only)
 
unsigned int m_filteredChainLag
Spacing for chain filtering. 
 
unsigned int subSequenceSize() const 
Size of the sub-sequence of vectors. 
 
virtual void resizeSequence(unsigned int newSubSequenceSize)=0
Resize the sequence. See template specialization. 
 
#define queso_require_equal_to_msg(expr1, expr2, msg)
 
unsigned int numRejections
 
#define queso_require_less_msg(expr1, expr2, msg)
 
void resizeSequence(unsigned int newSubSequenceSize)
Resizes the sequence. 
 
void setPdf(BaseJointPdf< V, M > &pdf)
Sets the PDF of this vector RV to pdf. 
 
void unifiedReadContents(const std::string &fileName, const std::string &fileType, const unsigned int subSequenceSize)
Reads the unified sequence from a file. 
 
unsigned int unifiedSequenceSize(bool useOnlyInter0Comm) const 
Size of the unified sequence of scalars. 
 
void setName(const std::string &newName)
Sets a new name to the sequence of scalars. 
 
double m_loadBalanceTreshold
Perform load balancing if load unbalancing ratio > threshold. 
 
Struct for handling data input and output from files. 
 
void filter(unsigned int initialPos, unsigned int spacing)
Filters positions in the sequence of vectors. 
 
void append(const BaseVectorSequence< V, M > &src, unsigned int initialPos, unsigned int numPos)
Appends the vector src to this vector. 
 
A templated class that represents a Metropolis-Hastings generator of samples. 
 
unsigned int sample() const 
Samples. 
 
const BaseEnvironment & m_env
Queso enviroment. 
 
#define RawValue_MPI_DOUBLE
 
#define RawValue_MPI_UNSIGNED
 
int finalNodeOfInitialPosition
 
unsigned int m_drMaxNumExtraStages
'dr' maximum number of extra stages. 
 
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). 
 
double m_minAcceptableEta
minimum acceptable eta, 
 
std::set< unsigned int > m_parameterDisabledSet
 
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). 
 
bool m_totallyMute
Whether or not to be totally mute (no printout message). 
 
unsigned int initialPositionIndexInPreviousChain
 
#define RawValue_MPI_CHAR
 
std::string m_rawChainDataOutputFileName
Name of output file for raw chain. 
 
std::vector< UnbalancedLinkedChainControlStruct > unbLinkedChains
 
double m_maxRejectionRate
maximum allowed attempted rejection rate at current level. 
 
#define UQ_MH_SG_FILENAME_FOR_NO_FILE
 
void getUnifiedContentsAtProc0Only(bool useOnlyInter0Comm, std::vector< T > &outputVec) const 
Gets the unified contents of processor of rank equals to 0. 
 
This class provides options for each level of the Multilevel sequence generator if no input file is a...
 
bool m_stopAtEnd
Stop at end of such level. 
 
const T & unifiedMaxPlain(bool useOnlyInter0Comm) const 
Finds the maximum value of the unified sequence of scalars. 
 
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). 
 
if the work is an executable linked with the with the complete machine readable work that uses the as object code and or source so that the user can modify the Library and then relink to produce a modified executable containing the modified rather than copying library functions into the if the user installs as long as the modified version is interface compatible with the version that the work was made with c Accompany the work with a written valid for at least three to give the same user the materials specified in for a charge no more than the cost of performing this distribution d If distribution of the work is made by offering access to copy from a designated offer equivalent access to copy the above specified materials from the same place e Verify that the user has already received a copy of these materials or that you have already sent this user a copy For an the required form of the work that uses the Library must include any data and utility programs needed for reproducing the executable from it as a special the materials to be distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system Such a contradiction means you cannot use both them and the Library together in an executable that you distribute You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities not covered by this and distribute such a combined provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise and provided that you do these two uncombined with any other library facilities This must be distributed under the terms of the Sections above b Give prominent notice with the combined library of the fact that part of it is a work based on the and explaining where to find the accompanying uncombined form of the same work You may not link or distribute the Library except as expressly provided under this License Any attempt otherwise to link or distribute the Library is and will automatically terminate your rights under this License parties who have received or from you under this License will not have their licenses terminated so long as such parties remain in full compliance You are not required to accept this since you have not signed it nothing else grants you permission to modify or distribute the Library or its derivative works These actions are prohibited by law if you do not accept this License by modifying or distributing the you indicate your acceptance of this License to do and all its terms and conditions for distributing or modifying the Library or works based on it Each time you redistribute the the recipient automatically receives a license from the original licensor to link with or modify the Library subject to these terms and conditions You may not impose any further restrictions on the recipients exercise of the rights granted herein You are not responsible for enforcing compliance by third parties with this License as a consequence of a court judgment or allegation of patent infringement or for any other reason(not limited to patent issues)
 
double eig() const 
Calculates the expected information gain value, EIG. 
 
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain. 
 
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const 
Writes the unified sequence to a file. 
 
std::ofstream * ofsVar
Provides a stream interface to write data to files. 
 
A struct that represents a Metropolis-Hastings sample. 
 
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)...
 
std::set< unsigned int > m_dataOutputAllowedSet
subEnvs that will write to generic output file. 
 
void unifiedWriteContents(const std::string &fileName, const std::string &fileType) const 
 
void resizeSequence(unsigned int newSequenceSize)
Resizes the size of the sequence of scalars. 
 
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, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, 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...
 
#define queso_require_less_equal_msg(expr1, expr2, msg)
 
unsigned int numberOfPositions
 
std::string m_filteredChainDataOutputFileType
Type of output file for filtered chain. 
 
void clear()
Reset the values and the size of the sequence of vectors. 
 
std::string m_filteredChainDataOutputFileName
Name of output file for filtered chain. 
 
#define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT
 
#define queso_require_msg(asserted, msg)
 
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. 
 
std::vector< BalancedLinkedChainControlStruct< P_V > > balLinkedChains
 
void mpiExchangePositions_inter0(const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, const std::vector< ExchangeInfoStruct > &exchangeStdVec, const std::vector< unsigned int > &finalNumChainsPerNode, const std::vector< unsigned int > &finalNumPositionsPerNode, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
 
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 scanOptionsValues(const MLSamplingLevelOptions *defaultOptions)
 
MLSampling(const char *prefix, const BaseVectorRV< P_V, P_M > &priorRv, const BaseScalarFunction< P_V, P_M > &likelihoodFunction)
Constructor. 
 
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...
 
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...
 
#define queso_error_msg(msg)
 
unsigned int m_amAdaptInterval
'am' adaptation interval. 
 
void justBalance_proc0(const MLSamplingLevelOptions *currOptions, std::vector< ExchangeInfoStruct > &exchangeStdVec)
 
void computeFilterParams(std::ofstream *passedOfs, unsigned int &initialPos, unsigned int &spacing)
Computes the filtering parameters spacing for the sequence of vectors. 
 
unsigned int m_loadBalanceAlgorithmId
Perform load balancing with chosen algorithm (0 = no balancing). 
 
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain. 
 
A templated class that represents a Multilevel generator of samples. 
 
void prepareBalLinkedChains_inter0(const MLSamplingLevelOptions *currOptions, const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, std::vector< ExchangeInfoStruct > &exchangeStdVec, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
 
unsigned int subSequenceSize() const 
Size of the sub-sequence of scalars. 
 
void generateSequence_Step09_all(const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, 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)...
 
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. 
 
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, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, SequenceOfVectors< P_V, P_M > &workingChain, double &cumulativeRunTime, unsigned int &cumulativeRejections, ScalarSequence< double > *currLogLikelihoodValues, ScalarSequence< double > *currLogTargetValues)
 
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). 
 
std::vector< double > m_initialValuesOfDisabledParameters
 
GslMatrix matrixProduct(const GslVector &v1, const GslVector &v2)
 
#define ML_CHECKPOINT_FIXED_AMOUNT_OF_DATA