CArl
Code Arlequin / C++ implementation
solver_files_setup.cpp
Go to the documentation of this file.
1 #include "solver_files_setup.h"
2 
3 namespace carl
4 {
5 void Solver_Files_Setup::print_feti_setup_finish_params(const std::string& output_filename)
6 {
7  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
8 
9  std::ofstream output_file(output_filename);
10  output_file << "ClusterSchedulerType " << carl::ClusterSchedulerType_to_string(m_input_params.scheduler) << std::endl;
11  output_file << "ScratchFolderPath " << m_input_params.scratch_folder_path << std::endl;
12  output_file << "CouplingMatricesFolder " << m_input_params.coupling_folder_path << std::endl;
13  output_file << "CGPreconditionerType " << carl::BaseCGPrecondType_to_string(m_input_params.CG_precond_type) << std::endl;
14 
16  {
17  output_file << "UseRigidBodyModesB" << std::endl;
18  output_file << "RBVectorBase " << m_input_params.RB_vectors_base << std::endl;
19  output_file << "NbOfRBVectors " << m_input_params.nb_of_rb_vectors << std::endl;
20  }
21  output_file.close();
22 };
23 
24 void Solver_Files_Setup::print_feti_iterate_params(const std::string& output_filename)
25 {
26  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
27 
28  std::ofstream output_file(output_filename);
29  output_file << "ClusterSchedulerType " << carl::ClusterSchedulerType_to_string(m_input_params.scheduler) << std::endl;
30  output_file << "ScratchFolderPath " << m_input_params.scratch_folder_path << std::endl;
31  output_file << "CouplingMatricesFolder " << m_input_params.coupling_folder_path << std::endl;
32 
34  {
35  output_file << "UseRigidBodyModesB" << std::endl;
36  output_file << "RBVectorBase " << m_input_params.RB_vectors_base << std::endl;
37  output_file << "NbOfRBVectors " << m_input_params.nb_of_rb_vectors << std::endl;
38  }
39 
40  output_file << "CGPreconditionerType " << carl::BaseCGPrecondType_to_string(m_input_params.CG_precond_type) << std::endl;
41  output_file << "CoupledConvAbs " << m_input_params.CG_coupled_conv_abs << std::endl;
42  output_file << "CoupledConvRel " << m_input_params.CG_coupled_conv_rel << std::endl;
43  output_file << "CoupledCorrConvRel " << m_input_params.CG_coupled_conv_corr << std::endl;
44  output_file << "CoupledDiv " << m_input_params.CG_coupled_div << std::endl;
45  output_file << "CoupledIterMax " << m_input_params.CG_coupled_conv_max << std::endl;
46  output_file.close();
47 };
48 
49 void Solver_Files_Setup::print_feti_solution_params(const std::string& output_filename)
50 {
51  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
52 
53  std::ofstream output_file(output_filename);
54  output_file << "ScratchFolderPath " << m_input_params.scratch_folder_path << std::endl;
55  output_file << "OutputFolder " << m_input_params.output_folder << std::endl;
56 
58  {
59  output_file << "UseRigidBodyModesB" << std::endl;
60  }
61  output_file.close();
62 };
63 
64 void Solver_Files_Setup::print_PBS_script(const std::string& output_filename, const std::string& job_name, const std::string& output_name, const std::string& error_name, const std::string& common_script, const std::string& command_to_run)
65 {
66  std::ofstream output_script(output_filename);
67  output_script << "#!/bin/bash" << std::endl;
68  output_script << std::endl;
69  output_script << "#PBS -S /bin/bash" << std::endl;
70  output_script << "#PBS -N " << job_name << std::endl;
71  output_script << "#PBS -o " << output_name << std::endl;
72  output_script << "#PBS -e " << error_name << std::endl;
73  output_script << common_script << std::endl;
74  output_script << command_to_run << std::endl;
75  output_script.close();
76 };
77 
79 {
80  m_bInputParamsSet = true;
81  m_input_params = input_params;
82 };
83 
85 {
86  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
87 
89 
90  if(m_comm.rank() == 0)
91  {
92  std::string command_string;
93 
94  command_string = "rm -rf " + m_input_params.scratch_folder_path;
95  carl::exec_command(command_string.c_str());
96 
97  command_string = "mkdir -p " + m_input_params.scratch_folder_path;
98  carl::exec_command(command_string.c_str());
99  std::cout << command_string << std::endl;
100  }
101 };
102 
104 {
105  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
106  homemade_assert_msg(m_bScratchFolderExists,"Scratch folder not set yet!");
107 
110 
113 
114  GetPot field_parser_A, field_parser_B;
115 
116  // Get the first input file
117  field_parser_A.parse_input_file(m_input_params.ext_solver_BIG_input, "#", "\n", " \t\n");
118  field_parser_B.parse_input_file(m_input_params.ext_solver_micro_input, "#", "\n", " \t\n");
119 
120  carl::libmesh_solve_linear_system_input_params solver_A_input_params, solver_B_input_params;
121 
122  carl::get_input_params(field_parser_A, solver_A_input_params);
123  carl::get_input_params(field_parser_B, solver_B_input_params);
124 
125  // Set K_i * u_0,i = F_i
126  solver_A_input_params.output_base = m_input_params.scratch_folder_path + "/ext_solver_u0_A";
127  solver_B_input_params.output_base = m_input_params.scratch_folder_path + "/ext_solver_u0_B";
128 
131 
132  // Set K_i * y(k)_i = C_i^t * p(k) and K_i * x_i(kkk) = C_i^t * phi(kkk)
133  solver_A_input_params.output_base = m_input_params.scratch_folder_path + "/ext_solver_A";
134  solver_B_input_params.output_base = m_input_params.scratch_folder_path + "/ext_solver_B";
135 
136  solver_A_input_params.sys_rhs_vec_file = m_input_params.scratch_folder_path + "/ext_solver_A_rhs.petscvec";
137  solver_B_input_params.sys_rhs_vec_file = m_input_params.scratch_folder_path + "/ext_solver_B_rhs.petscvec";
138 
141 
143 }
144 
146 {
147  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
148  homemade_assert_msg(m_bScratchFolderExists,"Scratch folder not set yet!");
149  homemade_assert_msg(m_bSetExternalSolversInputFiles,"External solver input files not set yet!");
150 
153 
156 
157  switch (m_input_params.scheduler)
158  {
160  break;
161 
163  break;
164 
165  case ClusterSchedulerType::SLURM : homemade_error_msg("Scheduler not implemented yet!");
166  break;
167  default : homemade_error_msg("Invalid scheduler name!");
168  }
169 
171 }
172 
174 {
175  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
176  homemade_assert_msg(m_bScratchFolderExists,"Scratch folder not set yet!");
177  homemade_assert_msg(m_bSetExternalSolversInputFiles,"External solver input files not set yet!");
178 
179  if(m_comm.rank() == 0)
180  {
181  std::string command_to_run;
182 
183  // Set the u0_i scripts
185  std::ofstream output_script(m_ext_solver_u0_A_script_filename);
186  output_script << command_to_run << std::endl;
187  output_script.close();
188 
190  output_script.open(m_ext_solver_u0_B_script_filename);
191  output_script << command_to_run << std::endl;
192  output_script.close();
193 
194  // Set the yk_i scripts
196  output_script.open(m_ext_solver_A_script_filename);
197  output_script << command_to_run << std::endl;
198  output_script.close();
199 
201  output_script.open(m_ext_solver_B_script_filename);
202  output_script << command_to_run << std::endl;
203  output_script.close();
204  }
205 }
206 
208 {
209  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
210  homemade_assert_msg(m_bScratchFolderExists,"Scratch folder not set yet!");
211  homemade_assert_msg(m_bSetExternalSolversInputFiles,"External solver input files not set yet!");
212 
213  if(m_comm.rank() == 0)
214  {
215  // Get the full common script file into a string
216  std::ifstream base_script(m_input_params.script_filename);
217  std::string common_script((std::istreambuf_iterator<char>(base_script)),
218  std::istreambuf_iterator<char>());
219  base_script.close();
220 
221  std::string pbs_output;
222  std::string pbs_error;
223  std::string command_to_run;
224 
225  // Set the u0_i scripts
226  pbs_output = m_input_params.scratch_folder_path + "/output_ext_u0_A.txt";
227  pbs_error = m_input_params.scratch_folder_path + "/error_ext_u0_A.txt";
229 
231  pbs_output, pbs_error, common_script,
232  command_to_run);
233 
234  pbs_output = m_input_params.scratch_folder_path + "/output_ext_u0_B.txt";
235  pbs_error = m_input_params.scratch_folder_path + "/error_ext_u0_B.txt";
237 
239  pbs_output, pbs_error,common_script,
240  command_to_run);
241 
242  // Set the yk_i scripts
243  pbs_output = m_input_params.scratch_folder_path + "/output_ext_A.txt";
244  pbs_error = m_input_params.scratch_folder_path + "/error_ext_A.txt";
246 
248  pbs_output, pbs_error,common_script,
249  command_to_run);
250 
251  pbs_output = m_input_params.scratch_folder_path + "/output_ext_B.txt";
252  pbs_error = m_input_params.scratch_folder_path + "/error_ext_B.txt";
254 
256  pbs_output, pbs_error,common_script,
257  command_to_run);
258  }
259 }
260 
262 {
263  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
264  homemade_assert_msg(m_bScratchFolderExists,"Scratch folder not set yet!");
265 
269 
270  if(m_comm.rank() == 0)
271  {
275  }
276 
277  m_bSetCArlFETIInputs = true;
278 }
279 
281 {
282  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
283  homemade_assert_msg(m_bScratchFolderExists,"Scratch folder not set yet!");
284  homemade_assert_msg(m_bSetCArlFETIInputs,"CArl_FETI input files not set yet!");
285 
286  if(m_comm.rank() == 0)
287  {
288  std::string command_string = "mkdir -p " + m_input_params.output_folder;
289  carl::exec_command(command_string.c_str());
290  }
291 
295 
296  switch (m_input_params.scheduler)
297  {
299  break;
300 
302  break;
303 
304  case ClusterSchedulerType::SLURM : homemade_error_msg("Scheduler not implemented yet!");
305  break;
306  default : homemade_error_msg("Invalid scheduler name!");
307  }
308 
309  m_bSetCArlFETIScripts = true;
310 }
311 
313 {
314  if(m_comm.rank() == 0)
315  {
316  std::string command_to_run;
317 
318  // Set the u0_i scripts
319  command_to_run = "./CArl_FETI_setup_finish -i " + m_CArl_FETI_setup_finish_input_filename;
320  std::ofstream output_script(m_CArl_FETI_setup_finish_script_filename);
321  output_script << "mpirun -n " << m_comm.size() << " " << command_to_run << std::endl;
322  output_script.close();
323 
324 
325  command_to_run = "./CArl_FETI_iterate -i " + m_CArl_FETI_iterate_input_filename;
326  output_script.open(m_CArl_FETI_iterate_script_filename);
327  output_script << "mpirun -n " << m_comm.size() << " " << command_to_run << std::endl;
328  output_script.close();
329 
330  command_to_run = "./CArl_FETI_solution -i " + m_CArl_FETI_solution_input_filename;
331  output_script.open(m_CArl_FETI_solution_script_filename);
332  output_script << "mpirun -n " << m_comm.size() << " " << command_to_run << std::endl;
333  output_script.close();
334  }
335 }
336 
338 {
339  if(m_comm.rank() == 0)
340  {
341  // Get the full common script file into a string
342  std::ifstream base_script(m_input_params.script_filename);
343  std::string common_script((std::istreambuf_iterator<char>(base_script)),
344  std::istreambuf_iterator<char>());
345  base_script.close();
346 
347  std::string pbs_output;
348  std::string pbs_error;
349  std::string command_to_run;
350 
351  // Set the u0_i scripts
352  pbs_output = m_input_params.scratch_folder_path + "/output_CArl_FETI_setup_finish.txt";
353  pbs_error = m_input_params.scratch_folder_path + "/error_CArl_FETI_setup_finish.txt";
354  command_to_run = "mpirun -n " + std::to_string(m_comm.size()) + " ./CArl_FETI_setup_finish -i " +
356 
358  pbs_output, pbs_error, common_script,
359  command_to_run);
360 
361  pbs_output = m_input_params.scratch_folder_path + "/output_CArl_FETI_iterate.txt";
362  pbs_error = m_input_params.scratch_folder_path + "/error_CArl_FETI_iterate.txt";
363  command_to_run = "mpirun -n " + std::to_string(m_comm.size()) + " ./CArl_FETI_iterate -i " +
365 
367  pbs_output, pbs_error, common_script,
368  command_to_run);
369 
370  pbs_output = m_input_params.scratch_folder_path + "/output_CArl_FETI_solution.txt";
371  pbs_error = m_input_params.scratch_folder_path + "/error_CArl_FETI_solution.txt";
372  command_to_run = "mpirun -n " + std::to_string(m_comm.size()) + " ./CArl_FETI_solution -i " +
374 
376  pbs_output, pbs_error, common_script,
377  command_to_run);
378  }
379 }
380 
382 {
383 
384  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
385  homemade_assert_msg(m_bScratchFolderExists,"Scratch folder not set yet!");
386  homemade_assert_msg(m_bSetExternalSolversFiles,"External solver scripts not set yet!");
387  homemade_assert_msg(m_bSetCArlFETIScripts,"CArl_FETI scripts not set yet!");
388 
392 
393  switch (m_input_params.scheduler)
394  {
396  break;
397 
399  break;
400 
401  case ClusterSchedulerType::SLURM : homemade_error_msg("Scheduler not implemented yet!");
402  break;
403  default : homemade_error_msg("Invalid scheduler name!");
404  }
405 
407 };
408 
410 {
411  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
412  homemade_assert_msg(m_bScratchFolderExists,"Scratch folder not set yet!");
413  homemade_assert_msg(m_bSetExternalSolversFiles,"External solver scripts not set yet!");
414  homemade_assert_msg(m_bSetCArlFETIScripts,"CArl_FETI scripts not set yet!");
415 
416  // ONLY WORK ON PROCESSOR 0 !!!
417  if(m_comm.rank() == 0)
418  {
419  std::ofstream FETI_init_script(m_FETI_init_launch_script_filename);
420  FETI_init_script << "#!/bin/bash" << std::endl;
421  FETI_init_script << std::endl;
422  FETI_init_script << ". " << m_ext_solver_u0_A_script_filename << std::endl;
423  FETI_init_script << ". " << m_ext_solver_u0_B_script_filename << std::endl;
424  // --- We will only need job2_i if the rigid body modes are needed
426  {
427  FETI_init_script << ". " << m_ext_solver_A_script_filename << std::endl;
428  FETI_init_script << ". " << m_ext_solver_B_script_filename << std::endl;
429  FETI_init_script << ". " << m_CArl_FETI_setup_finish_script_filename << std::endl;
430  } else {
431  FETI_init_script << ". " << m_CArl_FETI_setup_finish_script_filename << std::endl;
432  }
433  FETI_init_script.close();
434 
435  std::ofstream FETI_iter_script(m_FETI_iter_launch_script_filename);
436  FETI_iter_script << "#!/bin/bash" << std::endl;
437  FETI_iter_script << std::endl;
438  FETI_iter_script << ". " << m_ext_solver_A_script_filename << std::endl;
439  FETI_iter_script << ". " << m_ext_solver_B_script_filename << std::endl;
440  FETI_iter_script << ". " << m_CArl_FETI_iterate_script_filename << std::endl;
441  FETI_iter_script.close();
442 
443  std::ofstream FETI_set_sol_script(m_FETI_sol_launch_script_filename);
444  FETI_set_sol_script << "#!/bin/bash" << std::endl;
445  FETI_set_sol_script << std::endl;
446  FETI_set_sol_script << ". " << m_ext_solver_A_script_filename << std::endl;
447  FETI_set_sol_script << ". " << m_ext_solver_B_script_filename << std::endl;
448  FETI_set_sol_script << ". " << m_CArl_FETI_solution_script_filename << std::endl;
449  FETI_set_sol_script.close();
450  }
451 };
452 
454 {
455  homemade_assert_msg(m_bInputParamsSet,"Input parameters not set yet!");
456  homemade_assert_msg(m_bScratchFolderExists,"Scratch folder not set yet!");
457  homemade_assert_msg(m_bSetExternalSolversFiles,"External solver scripts not set yet!");
458  homemade_assert_msg(m_bSetCArlFETIScripts,"CArl_FETI scripts not set yet!");
459 
460  // ONLY WORK ON PROCESSOR 0 !!!
461  if(m_comm.rank() == 0)
462  {
463  std::ofstream FETI_init_script(m_FETI_init_launch_script_filename);
464  FETI_init_script << "#!/bin/bash" << std::endl;
465  FETI_init_script << std::endl;
466  FETI_init_script << "job1_A=`qsub " << m_ext_solver_u0_A_script_filename << "`" << std::endl;
467  FETI_init_script << "job1_B=`qsub " << m_ext_solver_u0_B_script_filename << "`" << std::endl;
468  // --- We will only need job2_i if the rigid body modes are needed
470  {
471  FETI_init_script << "job2_A=`qsub " << m_ext_solver_A_script_filename << "`" << std::endl;
472  FETI_init_script << "job2_B=`qsub " << m_ext_solver_B_script_filename << "`" << std::endl;
473  FETI_init_script << "job3=`qsub -W depend=afterok:$job1_A:$job1_B:$job2_A:$job2_B "
474  << m_CArl_FETI_setup_finish_script_filename << "`" << std::endl;
475  } else {
476  FETI_init_script << "job3=`qsub -W depend=afterok:$job1_A:$job1_B "
477  << m_CArl_FETI_setup_finish_script_filename << "`" << std::endl;
478  }
479  FETI_init_script.close();
480 
481  std::ofstream FETI_iter_script(m_FETI_iter_launch_script_filename);
482  FETI_iter_script << "#!/bin/bash" << std::endl;
483  FETI_iter_script << std::endl;
484  FETI_iter_script << "job4_A=`qsub " << m_ext_solver_A_script_filename << "`" << std::endl;
485  FETI_iter_script << "job4_B=`qsub " << m_ext_solver_B_script_filename << "`" << std::endl;
486  FETI_iter_script << "job5=`qsub -W depend=afterok:$job4_A:$job4_B "
487  << m_CArl_FETI_iterate_script_filename << "`" << std::endl;
488  FETI_iter_script.close();
489 
490  std::ofstream FETI_set_sol_script(m_FETI_sol_launch_script_filename);
491  FETI_set_sol_script << "#!/bin/bash" << std::endl;
492  FETI_set_sol_script << std::endl;
493  FETI_set_sol_script << "job6_A=`qsub " << m_ext_solver_A_script_filename << "`" << std::endl;
494  FETI_set_sol_script << "job6_B=`qsub " << m_ext_solver_B_script_filename << "`" << std::endl;
495  FETI_set_sol_script << "job7=`qsub -W depend=afterok:$job6_A:$job6_B "
496  << m_CArl_FETI_solution_script_filename << "`" << std::endl;
497  FETI_set_sol_script.close();
498  }
499 };
500 
501 }
std::string m_CArl_FETI_solution_script_filename
std::string m_CArl_FETI_setup_finish_script_filename
std::string m_FETI_iter_launch_script_filename
feti_setup_init_params m_input_params
std::string m_CArl_FETI_iterate_script_filename
bool bUseRigidBodyModes
[RB] Use the rigid body modes for the micro system?
std::string m_CArl_FETI_solution_input_filename
void set_FETI_input_parameters(feti_setup_init_params &input_params)
double CG_coupled_div
[CG] Residual divergence.
#define homemade_error_msg(msg)
Definition: common_header.h:73
std::string m_ext_solver_u0_B_script_filename
void get_input_params(GetPot &field_parser, feti_iterate_params &input_params)
Parser function for the coupled solver test programs.
ClusterSchedulerType scheduler
Cluster scheduler software type. Values: PBS, SLURM (code not implemented for the later yet)...
std::string ext_solver_BIG_input
Path to a file containing the input parameters of the external solve for system A.
std::string m_CArl_FETI_iterate_input_filename
std::string scratch_folder_path
Path to the folder which will be used to save the temporary files during the solve operation...
std::string script_filename
Path to the file used to generate the scripts.
void print_feti_iterate_params(const std::string &output_filename)
std::string exec_command(const std::string &cmd)
std::string ext_solver_micro_input
Path to a file containing the input parameters of the external solve for system B.
carl::BaseCGPrecondType CG_precond_type
[CG] Type of preconditionner.
std::string coupling_folder_path
Path to the folder containing the coupling matrices.
std::string RB_vectors_base
[RB] Common path base for the micro system's rigid body mode vectors.
std::string m_ext_solver_u0_A_input_filename
void print_feti_solution_params(const std::string &output_filename)
std::string m_ext_solver_u0_B_input_filename
double CG_coupled_conv_abs
[CG] Absolute residual convergence.
libMesh::Parallel::Communicator & m_comm
std::string m_FETI_init_launch_script_filename
Structure containing the parameters for the setup initialization of the FETI solver.
int nb_of_rb_vectors
[RB] Number of RB mode vectors.
std::string sys_rhs_vec_file
Path to the system RHS vector file.
std::string ClusterSchedulerType_to_string(ClusterSchedulerType input)
std::string m_ext_solver_B_input_filename
int CG_coupled_conv_max
[CG] Maximum number of iterations.
std::string ext_solver_micro
Command used for the external solver for system B.
double CG_coupled_conv_rel
[CG] Relative residual convergence.
std::string m_ext_solver_A_script_filename
void print_input_params(const std::string &output_filename, libmesh_solve_linear_system_input_params &input_params)
Function used to generate a solver input file from "input_params".
void print_feti_setup_finish_params(const std::string &output_filename)
std::string m_ext_solver_B_script_filename
std::string m_FETI_sol_launch_script_filename
#define homemade_assert_msg(asserted, msg)
Definition: common_header.h:63
std::string ext_solver_BIG
Command used for the external solver for system A.
std::string m_CArl_FETI_setup_finish_input_filename
std::string m_ext_solver_u0_A_script_filename
std::string BaseCGPrecondType_to_string(BaseCGPrecondType input)
std::string m_ext_solver_A_input_filename
void print_PBS_script(const std::string &output_filename, const std::string &job_name, const std::string &output_name, const std::string &error_name, const std::string &common_script, const std::string &command_to_run)
double CG_coupled_conv_corr
[CG] Relative rigid body mode convergence.
std::string output_folder
Path to the coupled solution folder.