Skip to content

Commit

Permalink
added iter num, lambda and scale fac to infotxt, started to think abo…
Browse files Browse the repository at this point in the history
…ut how to redirect stdout
  • Loading branch information
jtwhite79 committed Dec 7, 2023
1 parent d38be18 commit 0dd9e73
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/libs/common/system_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <sstream>
#include <cmath>
#include <vector>
#include <iostream>
#include "system_variables.h"

#ifdef OS_WIN
Expand All @@ -32,6 +33,7 @@

#ifdef OS_LINUX
#include "stdio.h"
#include <fcntl.h>
#include <unistd.h>

#endif
Expand Down Expand Up @@ -169,11 +171,15 @@ int start(string &cmd_string)
if (pid == 0)
{
setpgid(0, 0);
// int fd = open("stdout.dat", O_CREAT);
// dup2(fd, 1);
// std::cout << "file descrp " << fd << std::endl;
int success = execvp(arg_v[0], const_cast<char* const*>(&(arg_v[0])));
if (success == -1)
{
throw std::runtime_error("execv() failed for command: " + cmd_string);
}

}
else
{
Expand Down
16 changes: 10 additions & 6 deletions src/libs/pestpp_common/EnsembleMethodUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4683,7 +4683,7 @@ pair<Parameters, Observations> save_real_par_rei(Pest& pest_scenario, ParameterE


vector<int> run_ensemble_util(PerformanceLog* performance_log, ofstream& frec,ParameterEnsemble& _pe, ObservationEnsemble& _oe,
RunManagerAbstract* run_mgr_ptr, bool check_pe_consistency, const vector<int>& real_idxs, int da_cycle)
RunManagerAbstract* run_mgr_ptr, bool check_pe_consistency, const vector<int>& real_idxs, int da_cycle, string additional_tag)
{
stringstream ss;
ss << "queuing " << _pe.shape().first << " runs";
Expand All @@ -4692,7 +4692,7 @@ vector<int> run_ensemble_util(PerformanceLog* performance_log, ofstream& frec,Pa
map<int, int> real_run_ids;
try
{
real_run_ids = _pe.add_runs(run_mgr_ptr, real_idxs,da_cycle);
real_run_ids = _pe.add_runs(run_mgr_ptr, real_idxs,da_cycle,additional_tag);
}
catch (const exception& e)
{
Expand Down Expand Up @@ -5139,7 +5139,7 @@ vector<ObservationEnsemble> EnsembleMethod::run_lambda_ensembles(vector<Paramete
for (int i=0;i<pe_lams.size();i++)
{
ss.str("");
ss << " lambda:" << lam_vals[i] << " scale_fac:" << scale_vals[i];
ss << " lambda:" << lam_vals[i] << " scale_fac:" << scale_vals[i] << " iteration:" << iter;
additional_tag = ss.str();
try
{
Expand Down Expand Up @@ -5372,13 +5372,15 @@ vector<int> EnsembleMethod::run_ensemble(ParameterEnsemble& _pe,
ObservationEnsemble& _oe, const vector<int>& real_idxs, int cycle)
{
stringstream ss;
ss.str("");
ss << " iteration:" << iter;
vector<int> failed_real_indices;
try
{
failed_real_indices = run_ensemble_util(performance_log, file_manager.rec_ofstream(),
_pe, _oe, run_mgr_ptr,
pest_scenario.get_pestpp_options().get_debug_check_par_en_consistency(),
real_idxs, cycle);
real_idxs, cycle,ss.str());
}
catch (const exception& e)
{
Expand Down Expand Up @@ -7709,14 +7711,16 @@ bool EnsembleMethod::solve(bool use_mda, vector<double> inflation_factors, vecto
oe_lam_best = oe; //copy

message(0,"running mean-shifted prior realizations: ",new_pe.shape().first);
run_ensemble_util(performance_log,frec,new_pe,oe_lam_best,run_mgr_ptr);
ss.str("");
ss << "iteration:" << iter;
vector<int> temp;
run_ensemble_util(performance_log,frec,new_pe,oe_lam_best,run_mgr_ptr,false,temp,NetPackage::NULL_DA_CYCLE, ss.str());
pe_lams[best_idx] = new_pe;

//make sure we dont try to process the subset stuff below
local_subset_size = pe.shape().first;
}


else if ((best_idx != -1) && (use_subset) && (local_subset_size < pe.shape().first))
{

Expand Down
3 changes: 2 additions & 1 deletion src/libs/pestpp_common/EnsembleMethodUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ pair<Parameters,Observations> save_real_par_rei(Pest& pest_scenario, ParameterEn

vector<int> run_ensemble_util(PerformanceLog* performance_log, ofstream& frec, ParameterEnsemble& _pe,
ObservationEnsemble& _oe, RunManagerAbstract* run_mgr_ptr,
bool check_pe_consistency = false, const vector<int>& real_idxs = vector<int>(),int da_cycle=NetPackage::NULL_DA_CYCLE);
bool check_pe_consistency = false, const vector<int>& real_idxs = vector<int>(),int da_cycle=NetPackage::NULL_DA_CYCLE,
string additional_tag="");

class EnsembleSolver
{
Expand Down
3 changes: 3 additions & 0 deletions src/libs/run_managers/abstract_base/model_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ void ModelInterface::run(pest_utils::thread_flag* terminate, pest_utils::thread_
{
throw PestError("could not add process to job object: " + cmd_string);
}
DWORD pid = GetProcessId(pi);
cout << "...pid: " << pid << endl;
DWORD exitcode;
while (true)
{
Expand Down Expand Up @@ -746,6 +748,7 @@ void ModelInterface::run(pest_utils::thread_flag* terminate, pest_utils::thread_
cout << pest_utils::get_time_string() << " calling forward run command: '" << cmd_string << "' " << endl;
//start the command
int command_pid = start(cmd_string);
cout << "...pid: " << command_pid << endl;
while (true)
{
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_ms));
Expand Down

0 comments on commit 0dd9e73

Please sign in to comment.