SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
SlurmUtilities.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <carl-settings/settings_utils.h>
4 #include <benchmax/logging.h>
5 
6 #include <chrono>
7 #include <filesystem>
8 #include <string>
9 #include <vector>
10 
11 namespace benchmax {
12 namespace slurm {
13 
14 namespace fs = std::filesystem;
15 
16 /// All properties needed to archive log files.
18  /// Filename of the archive.
19  std::string filename_archive;
20  /// Temporary directory to look for output files.
21  std::string tmp_dir;
22 };
23 /// Put all log files into an archive.
25 
26 /**
27  * Collects all result files in the given base directory for this job id.
28  * @param basedir Base directory to search in.
29  * @param jobid ID of slurm job.
30  * @return List of result files.
31  */
32 std::vector<fs::path> collect_result_files(const fs::path& basedir);
33 
34 /// All properties needed to create a submit file.
36  /// Suffix for job and submit file.
37  std::string file_suffix;
38  /// Filename of the job list file.
39  std::string filename_jobs;
40  /// Temporary directory for log files.
41  std::string tmp_dir;
42  /// Time limit in seconds.
43  carl::settings::duration limit_time;
44  /// Grace time in seconds.
45  carl::settings::duration grace_time;
46  /// Memory limit in megabytes.
47  carl::settings::binary_quantity limit_memory;
48  /// Number of tasks.
49  std::size_t tasks;
50  /// Number of slices.
51  std::size_t slices;
52 };
53 
54 /**
55  * Generate a submit file for Slurm with the given properties.
56  * @param p Collection of all information needed.
57  * @return The filename of the submit file.
58  */
59 std::string generate_submit_file(const SubmitfileProperties& p);
60 
61 /// All properties needed to create a submit file.
63  /// Suffix for job and submit file.
64  std::string file_suffix;
65  /// Filename of the job list file.
66  std::string filename_jobs;
67  /// Temporary directory for log files.
68  std::string tmp_dir;
69  /// Time limit in seconds.
70  carl::settings::duration limit_time;
71  /// Grace time in seconds.
72  carl::settings::duration grace_time;
73  /// Memory limit in megabytes.
74  carl::settings::binary_quantity limit_memory;
75  /// Array size.
76  std::size_t array_size;
77  /// Slice size.
78  std::size_t slice_size;
79  /// This slice size.
80  std::pair<std::size_t,std::size_t> job_range;
81 };
82 
84 
85 template<typename Jobs>
86 void generate_jobs_file(const std::string& filename, std::pair<std::size_t,std::size_t> range, const Jobs& jobs) {
87  BENCHMAX_LOG_DEBUG("benchmax.slurm", "Writing job file to " << filename);
88  std::ofstream jobsfile(filename);
89  BENCHMAX_LOG_DEBUG("benchmax.slurm", "Taking jobs " << range.first << ".." << (range.second-1));
90 
91  for (std::size_t i = range.first; i < range.second; ++i) {
92  const auto& r = jobs[i];
93  jobsfile << std::get<0>(r)->getCommandline(std::get<1>(r)) << std::endl;
94  }
95  jobsfile.close();
96  BENCHMAX_LOG_DEBUG("benchmax.slurm", "Job file is finished.");
97 }
98 
99 /**
100  * Parses the job id from the output of `sbatch`.
101  * @param output Output of `sbatch`.
102  * @return Slurm job id.
103  */
104 int parse_job_id(const std::string& output);
105 
106 /**
107  * Parse a single result information from the output.
108  * @param content Result information output.
109  * @param name Information to be parsed.
110  * @return Information specified in the output.
111  */
112 std::string parse_result_info(const std::string& content, const std::string& name);
113 
114 /**
115  * Remove the given list of files.
116  * @param files List of files.
117  * @param remove Boolean flag whether to actually remove files.
118  */
119 void remove_log_files(const std::vector<fs::path>& files, bool remove);
120 
121 /**
122  * Clear log files from directory
123  * @param basedir Base directory to search in.
124  */
125 void clear_directory(const fs::path& basedir);
126 
127 /**
128  * Checks if the given job is finished.
129  * @param jobid The job id.
130  * @return True if the job is completed.
131  */
132 bool is_job_finished(int jobid);
133 
134 }
135 }
#define BENCHMAX_LOG_DEBUG(channel, msg)
Log debug messages.
Definition: logging.h:55
Represents a set of jobs, constructed as the cartesian product of a set of tools and a set of benchma...
Definition: Jobs.h:70
static void remove(V &ts, const T &t)
Definition: Alg.h:36
void clear_directory(const fs::path &basedir)
Clear log files from directory.
std::string generate_submit_file(const SubmitfileProperties &p)
Generate a submit file for Slurm with the given properties.
void remove_log_files(const std::vector< fs::path > &files, bool remove)
Remove the given list of files.
void archive_log_files(const ArchiveProperties &p)
Put all log files into an archive.
std::string generate_submit_file_chunked(const ChunkedSubmitfileProperties &p)
void generate_jobs_file(const std::string &filename, std::pair< std::size_t, std::size_t > range, const Jobs &jobs)
int parse_job_id(const std::string &output)
Parses the job id from the output of sbatch.
std::vector< fs::path > collect_result_files(const fs::path &basedir)
Collects all result files in the given base directory for this job id.
std::string parse_result_info(const std::string &content, const std::string &name)
Parse a single result information from the output.
bool is_job_finished(int jobid)
Checks if the given job is finished.
All properties needed to archive log files.
std::string filename_archive
Filename of the archive.
std::string tmp_dir
Temporary directory to look for output files.
All properties needed to create a submit file.
carl::settings::duration grace_time
Grace time in seconds.
std::string tmp_dir
Temporary directory for log files.
carl::settings::binary_quantity limit_memory
Memory limit in megabytes.
carl::settings::duration limit_time
Time limit in seconds.
std::string filename_jobs
Filename of the job list file.
std::string file_suffix
Suffix for job and submit file.
std::pair< std::size_t, std::size_t > job_range
This slice size.
All properties needed to create a submit file.
carl::settings::duration grace_time
Grace time in seconds.
carl::settings::duration limit_time
Time limit in seconds.
std::size_t slices
Number of slices.
std::string file_suffix
Suffix for job and submit file.
std::size_t tasks
Number of tasks.
std::string tmp_dir
Temporary directory for log files.
std::string filename_jobs
Filename of the job list file.
carl::settings::binary_quantity limit_memory
Memory limit in megabytes.