This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpbsscript.cc
162 lines (125 loc) · 6.28 KB
/
pbsscript.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
Copyright 2017 Battelle Energy Alliance, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Description
-----------
PbsScript sub class source code.
Date Created: Mon Nov 30 13:06:42 MST 2015
Author: Cormac Garvey
*/
#include "pbsscript.h"
namespace jobscript {
// f_pbs_script_(j_s_n,std::ios_base::out),
PbsScript::PbsScript(modules::modules_type ms, int t_n_p, int m_n_p_p_n, std::string m_c_n, std::string m_c_a, std::string e_n, std::string e_a, std::string j_s_n, std::string j_n, std::string q_n, std::string c_t, int c_s, std::string w_t, PbsArrangement p_a, PbsSharing p_s): JobScript(t_n_p, m_n_p_p_n, m_c_n, m_c_a, e_n, e_a, j_s_n, j_n, q_n, w_t, ms),
cpu_type_(c_t),
chunk_size_(c_s),
pbs_arrangement_(p_a),
pbs_sharing_(p_s) {
// setDefaultChunkSize();
// generate();
}
//PbsScript::PbsScript(const PbsScript & p_s): JobScript(p_s), f_pbs_script_(p_s.getJobScriptName(),std::ios_base::app) {
PbsScript::PbsScript(const PbsScript & p_s): JobScript(p_s) {
// f_pbs_script_ = p_s.f_pbs_script_;
chunk_size_ = p_s.chunk_size_;
cpu_type_ = p_s.cpu_type_;
pbs_arrangement_ = p_s.pbs_arrangement_;
pbs_sharing_ = p_s.pbs_sharing_;
}
//PbsScript::PbsScript(std::string j_s_n, std::string e_n, std::string e_a, modules::Modules m_o): PbsScript(j_s_n,e_n,e_a,m_o,1,1,"0:01:00",kFree,kExcl) {}
int PbsScript::getChunkSize(void) const {
return chunk_size_;
}
PbsScript::PbsArrangement PbsScript::getPbsArrangement(void) const {
return pbs_arrangement_;
}
PbsScript::PbsSharing PbsScript::getPbsSharing(void) const {
return pbs_sharing_;
}
std::string PbsScript::getPbsArrangementStr(void) const {
switch (pbs_arrangement_) {
case kFree: {
return "free";
break;
}
case kPack: {
return "pack";
break;
}
case kScatter: {
return "scatter";
break;
}
default: {
std::cerr << "Error: (" << __FILE__ << "," << __LINE__ << ") Do not recognize : " << pbs_arrangement_ << std::endl;
exit(EXIT_FAILURE);
}
}
}
std::string PbsScript::getPbsSharingStr(void) const {
switch (pbs_sharing_) {
case kExcl: {
return "excl";
break;
}
case kShared: {
return "shared";
break;
}
default: {
std::cerr << "Error: (" << __FILE__ << "," << __LINE__ << ") Do not recognize : " << pbs_sharing_ << std::endl;
exit(EXIT_FAILURE);
}
}
}
/*void PbsScript::setDefaultChunkSize(void) {
std::string hostname = getHostName();
if (hostname == "service0" || hostname == "service1" || hostname == "service2" ||
hostname == "falcon1" || hostname == "falcon2" || hostname == "falconpbs" ||
hostname == "falconviz") {
chunk_size_ = 36;
} else if (hostname == "fpbs" || hostname == "flogin1" || hostname == "flogin2") {
chunk_size_ = 32;
} else if (hostname == "bechler") {
chunk_size_ = 32;
} else {
std::cerr << "Error: (" << __FILE__ << "," << __LINE__ << ") Do not recognize hostname = " << hostname << std::endl;
exit(EXIT_FAILURE);
}
} */
std::string PbsScript::getCpuType(void) const {
return cpu_type_;
}
void PbsScript::generate(void) {
int select_size;
// std::vector<module_type> m = modules_.getModules();
auto m = getModules();
std::ofstream f_pbs_script(getJobScriptName(),std::ios_base::out);
select_size = getTotalNumProcs() / getMaxNumProcsPerNode();
f_pbs_script << "#PBS -N " << getJobName() << std::endl;
f_pbs_script << "#PBS -q " << getQueueName() << std::endl;
// if (getTotalNumCores() <= getChunkSize()) {
f_pbs_script << "#PBS -l select=" << select_size << ":ncpus=" << getChunkSize() << ":mpiprocs=" << getMaxNumProcsPerNode() << ":cputype=" << getCpuType()<< std::endl;
// }
f_pbs_script << "#PBS -l walltime=" << getWallTime() << std::endl;
f_pbs_script << "#PBS -l place=" << getPbsArrangementStr() << ":" << getPbsSharingStr() << std::endl;
f_pbs_script << "source /etc/profile.d/modules.sh" << std::endl;
for (auto m_p: m) {
f_pbs_script << "module load " << m_p.first << "/" << m_p.second << std::endl;
}
f_pbs_script << "cd $PBS_O_WORKDIR" << std::endl;
if (getMpiCmdName() == "") {
f_pbs_script << getExeName() << " " << getExeArgs() << std::endl;
} else {
f_pbs_script << getMpiCmdName() << " " << getMpiCmdArgs() << " " << getExeName() << " " << getExeArgs() << std::endl;
}
}
} // namespace jobscript