32 if (!solver->mpi_partition->get_proc0_world())
return;
37 output_file.open(solver->output_filename.c_str());
38 if (!output_file.is_open()) {
39 std::cerr <<
"output file: " << solver->output_filename << std::endl;
40 throw std::runtime_error(
"Error! Unable to open output file.");
43 output_file <<
"Recorder type:" << std::endl <<
"least_squares" << std::endl <<
"N_parameters:" << std::endl << solver->N_parameters << std::endl <<
"function_evaluation,seconds";
44 for (j=0; j<solver->N_parameters; j++) {
45 output_file <<
",x(" << j+1 <<
")";
47 output_file <<
",objective_function";
48 if (solver->print_residuals_in_output_file) {
49 for (j=0; j<solver->N_terms; j++) {
50 output_file <<
",F(" << j+1 <<
")";
53 output_file << std::endl << std::flush;
57 void mango::Recorder_least_squares::write_file_line(
int function_evaluations, clock_t print_time,
const double* x,
double f,
double* residuals) {
65 double elapsed_time = ((float)(print_time - solver->start_time)) / CLOCKS_PER_SEC;
66 output_file << std::setw(6) << std::right << function_evaluations <<
"," << std::setw(12) << std::setprecision(4) << std::scientific << elapsed_time;
67 for (
int j=0; j<solver->N_parameters; j++) {
68 output_file <<
"," << std::setw(24) << std::setprecision(16) << std::scientific << x[j];
70 output_file <<
"," << std::setw(24) << f;
71 if (solver->print_residuals_in_output_file) {
72 for (
int j=0; j<solver->N_terms; j++) {
73 output_file <<
"," << std::setw(24) << std::setprecision(16) << std::scientific << residuals[j];
76 output_file << std::endl << std::flush;
81 if (!solver->mpi_partition->get_proc0_world())
return;
83 write_file_line(function_evaluations, print_time, x, f, solver->current_residuals);
90 if (!solver->mpi_partition->get_proc0_world())
return;
92 write_file_line(solver->best_function_evaluation, solver->best_time, solver->state_vector, solver->best_objective_function, solver->best_residual_function);