107 using sn_print_detail::mat;
108 using sn_print_detail::names;
109 using sn_print_detail::num;
110 using sn_print_detail::row;
111 using sn_print_detail::tmat;
112 typedef std::vector<double> Row;
113 typedef std::vector<std::vector<double>> Tab;
114 const std::size_t M =
sn.nof_stations(), K =
sn.nclasses, I =
sn.nof_nodes();
115 const std::size_t S =
sn.nof_stateful();
116 const double nan = std::numeric_limits<double>::quiet_NaN();
119 out +=
"nstations: " + num(
static_cast<double>(M)) +
"\n";
120 out +=
"nstateful: " + num(
static_cast<double>(S)) +
"\n";
121 out +=
"nnodes: " + num(
static_cast<double>(I)) +
"\n";
122 out +=
"nclasses: " + num(
static_cast<double>(K)) +
"\n";
123 out +=
"nclosedjobs: " + num(
sn.nclosedjobs()) +
"\n";
124 out +=
"nchains: " + num(
static_cast<double>(
sn.nchains)) +
"\n";
127 Row isstation(I), isstateful(I), nodeToStateful(I), nodeToStation(I);
128 Tab isstatedep(I, Row(3, 0.0));
129 for (std::size_t i = 0; i < I; ++i) {
130 isstation[i] =
sn.nodes[i].station != 0 ? 1.0 : 0.0;
131 isstateful[i] =
sn.nodes[i].stateful ? 1.0 : 0.0;
132 nodeToStateful[i] =
static_cast<double>(
sn.stateful_index(i + 1));
133 nodeToStation[i] =
static_cast<double>(
sn.nodes[i].station);
135 if (
sn.nodes[i].nodetype == qn::NodeType::Cache) isstatedep[i][1] = 1.0;
136 for (std::size_t r = 0; r <
sn.nodes[i].routing.size(); ++r) {
141 isstatedep[i][2] = 1.0;
144 Row stationToNode(M), stationToStateful(M), statefulToStation(S), statefulToNode(S);
145 for (std::size_t i = 0; i < M; ++i) {
146 stationToNode[i] =
static_cast<double>(
sn.node_of_station(i + 1));
147 stationToStateful[i] =
static_cast<double>(
sn.stateful_of_station(i + 1));
149 for (std::size_t f = 0; f < S; ++f) {
150 const std::size_t ind =
sn.stateful_nodes[f];
151 statefulToNode[f] =
static_cast<double>(ind);
152 statefulToStation[f] =
static_cast<double>(ind > 0 ?
sn.nodes[ind - 1].station : 0);
155 Row refstat(K), njobsv =
sn.njobs(), classprio(K);
156 for (std::size_t r = 0; r < K; ++r) {
157 refstat[r] =
static_cast<double>(
sn.classes[r].refstat);
158 classprio[r] =
static_cast<double>(
sn.classes[r].prio);
160 out +=
"refstat: " + row(refstat) +
"\n";
161 out +=
"njobs: " + row(njobsv) +
"\n";
162 Row nservers(M), cap(M);
163 Tab classcap(M, Row(K)), phases(M, Row(K)), phasessz(M, Row(K)), phaseshift(M, Row(K + 1, 0.0));
164 Tab schedparam(M, Row(K, 0.0));
165 Tab droprule(M, Row(K)), procid(M, Row(K));
166 for (std::size_t i = 0; i < M; ++i) {
167 nservers[i] =
sn.stations[i].nservers;
168 cap[i] = i <
sn.cap.size() ?
sn.cap[i] : std::numeric_limits<double>::infinity();
170 for (std::size_t r = 0; r < K; ++r) {
171 classcap[i][r] = i <
sn.classcap.size() && r <
sn.classcap[i].size()
173 : std::numeric_limits<double>::infinity();
174 phases[i][r] =
static_cast<double>(
sn.phases_of(i + 1, r + 1));
175 phasessz[i][r] =
static_cast<double>(
sn.phasessz_of(i + 1, r + 1));
176 cum += phasessz[i][r];
177 phaseshift[i][r + 1] = cum;
178 if (r <
sn.stations[i].schedparam.size())
180 droprule[i][r] = i <
sn.droprule.size() && r <
sn.droprule[i].size()
181 ?
static_cast<double>(
static_cast<int>(
sn.droprule[i][r]))
182 :
static_cast<double>(
static_cast<int>(qn::DropStrategy::WAITQ));
183 procid[i][r] =
static_cast<double>(
static_cast<int>(
sn.procid(i + 1, r + 1)));
186 out +=
"nservers: " + row(nservers) +
"\n";
192 Tab conn(I, Row(I, 0.0));
193 if (
sn.rtnodes.rows() == I * K && K > 0)
194 for (std::size_t a = 0; a < I; ++a)
195 for (std::size_t b = 0; b < I; ++b) {
197 for (std::size_t r = 0; r < K && !any; ++r)
198 for (std::size_t s2 = 0; s2 < K && !any; ++s2)
200 conn[a][b] = any ? 1.0 : 0.0;
202 out +=
"connmatrix: " + (I > 0 ? mat(conn) : std::string(
"[]")) +
"\n";
204 out +=
"scv: " + tmat(
sn.scv) +
"\n";
205 out +=
"isstation: " + row(isstation) +
"\n";
206 out +=
"isstateful: " + row(isstateful) +
"\n";
207 out +=
"isstatedep: " + (I > 0 ? mat(isstatedep) : std::string(
"[]")) +
"\n";
208 out +=
"nodeToStateful: " + row(nodeToStateful) +
"\n";
209 out +=
"nodeToStation: " + row(nodeToStation) +
"\n";
210 out +=
"stationToNode: " + row(stationToNode) +
"\n";
211 out +=
"stationToStateful: " + row(stationToStateful) +
"\n";
212 out +=
"statefulToStation: " + row(statefulToStation) +
"\n";
213 out +=
"statefulToNode: " + row(statefulToNode) +
"\n";
214 out +=
"rates: " + tmat(
sn.rates) +
"\n";
215 out +=
"classprio: " + row(classprio) +
"\n";
216 out +=
"phases: " + mat(phases) +
"\n";
217 out +=
"phasessz: " + mat(phasessz) +
"\n";
218 out +=
"phaseshift: " + mat(phaseshift) +
"\n";
219 out +=
"schedparam: " + mat(schedparam) +
"\n";
221 Tab chains(
sn.chains.size());
222 for (std::size_t c = 0; c <
sn.chains.size(); ++c)
223 for (std::size_t r = 0; r <
sn.chains[c].size(); ++r)
224 chains[c].push_back(
sn.chains[c][r] ? 1.0 : 0.0);
225 out +=
"chains: " + mat(chains) +
"\n";
226 out +=
"rt: " + tmat(
sn.rt) +
"\n";
228 Tab nvars(
sn.nvars.size());
229 for (std::size_t i = 0; i <
sn.nvars.size(); ++i)
230 for (std::size_t v = 0; v <
sn.nvars[i].size(); ++v)
231 nvars[i].push_back(
static_cast<double>(
sn.nvars[i][v]));
232 out +=
"nvars: " + mat(nvars) +
"\n";
233 out +=
"rtnodes: " + tmat(
sn.rtnodes) +
"\n";
237 Tab csmask(K, Row(K, 0.0));
238 for (
typename std::map<std::size_t,
Matrix<T>>::const_iterator it =
sn.csmatrix.begin();
239 it !=
sn.csmatrix.end(); ++it)
240 for (std::size_t r = 0; r < K && r < it->second.rows(); ++r)
241 for (std::size_t s2 = 0; s2 < K && s2 < it->second.cols(); ++s2)
243 out +=
"csmask: " + (K > 0 ? mat(csmask) : std::string(
"[]")) +
"\n";
247 for (std::size_t r = 0; r < K; ++r) isslc[r] =
sn.classes[r].self_looping ? 1.0 : 0.0;
248 out +=
"isslc: " + row(isslc) +
"\n";
250 out +=
"cap: " + row(cap) +
"\n";
251 out +=
"classcap: " + mat(classcap) +
"\n";
253 Row refclass(
sn.refclass.size());
254 for (std::size_t c = 0; c <
sn.refclass.size(); ++c)
255 refclass[c] =
static_cast<double>(
sn.refclass[c]);
256 out +=
"refclass: " + row(refclass) +
"\n";
259 for (std::size_t i = 0; i < M; ++i)
260 if (!
sn.stations[i].lldscaling.empty()) {
262 for (std::size_t n = 0; n <
sn.stations[i].lldscaling.size(); ++n)
266 out +=
"lldscaling: " + (lld.empty() ? std::string(
"[]") : mat(lld)) +
"\n";
268 Tab
fj(
sn.fj.size());
269 for (std::size_t e = 0; e <
sn.fj.size(); ++e) {
270 fj[e].push_back(
static_cast<double>(
sn.fj[e].first));
271 fj[e].push_back(
static_cast<double>(
sn.fj[e].second));
273 out +=
"fj: " + mat(
fj) +
"\n";
276 if (
sn.nodes.empty()) {
280 for (std::size_t i = 0; i < I; ++i) {
281 if (i > 0) out +=
", ";
286 std::vector<std::string> classnames(K), nodenames(I);
287 for (std::size_t r = 0; r < K; ++r) classnames[r] =
sn.classes[r].name;
288 for (std::size_t i = 0; i < I; ++i) nodenames[i] =
sn.nodes[i].name;
289 out +=
"classnames: " + names(classnames) +
"\n";
290 out +=
"nodenames: " + names(nodenames) +
"\n";
299 for (std::size_t f = 0; f < S; ++f) {
300 const std::size_t ind =
sn.stateful_nodes[f];
301 if (!first) out +=
", ";
303 out +=
"\"" +
sn.nodes[ind - 1].name +
"\": ";
304 const typename std::map<std::size_t, Matrix<T>>::const_iterator it =
305 sn.statespace.find(ind);
306 out += (it ==
sn.statespace.end() || it->second.rows() == 0) ? std::string(
"null")
311 out +=
"stateprior: {";
314 for (std::size_t f = 0; f < S; ++f) {
315 const std::size_t ind =
sn.stateful_nodes[f];
316 if (!first) out +=
", ";
318 out +=
"\"" +
sn.nodes[ind - 1].name +
"\": ";
319 const typename std::map<std::size_t, std::vector<T>>::const_iterator it =
320 sn.stateprior.find(ind);
321 if (it ==
sn.stateprior.end() || it->second.empty()) {
325 for (std::size_t a = 0; a < it->second.size(); ++a)
336 for (std::size_t i = 0; i < I; ++i)
337 for (std::size_t r = 0; r < K && r <
sn.nodes[i].routing.size(); ++r)
338 routing[i][r] =
static_cast<double>(
static_cast<int>(
sn.nodes[i].routing[r]));
339 out +=
"routing: " + (I > 0 && K > 0 ? mat(routing) : std::string(
"[]")) +
"\n";
341 out +=
"procid: " + mat(procid) +
"\n";
346 std::string smu =
"mu: {", sphi =
"phi: {", spie =
"pie: {";
347 for (std::size_t i = 0; i < M; ++i) {
353 const std::string head =
"\"" +
sn.stations[i].name +
"\": {";
357 for (std::size_t r = 0; r < K; ++r) {
363 const std::string ch =
"\"" +
sn.classes[r].name +
"\": ";
368 if (d.
disabled || d.
D0.rows() == 0 || d.
D1.rows() != d.
D0.rows()) {
374 const std::size_t n = d.
D0.rows();
375 Row muv(n), phiv(n), piev(n, nan);
376 for (std::size_t a = 0; a < n; ++a) {
379 for (std::size_t b = 0; b < n; ++b) d1 += num_traits<T>::to_double(d.
D1(a, b));
381 phiv[a] = d0 != 0.0 ? d1 / d0 : 0.0;
388 for (std::size_t a = 0; a < n && a < pie.size(); ++a)
390 }
catch (
const std::exception&) {
401 out += smu +
"}\n" + sphi +
"}\n";
403 for (std::size_t i = 0; i < M; ++i) {
404 if (i > 0) out +=
", ";
405 out +=
"\"" +
sn.stations[i].name +
"\": {";
406 for (std::size_t r = 0; r < K; ++r) {
407 if (r > 0) out +=
", ";
409 out +=
"\"" +
sn.classes[r].name +
"\": ";
425 for (std::size_t i = 0; i < M; ++i) {
426 if (i > 0) out +=
", ";
427 out +=
"\"" +
sn.stations[i].name +
"\": \"" +
433 for (std::size_t c = 0; c <
sn.inchain.size(); ++c) {
434 if (c > 0) out +=
", ";
436 for (std::size_t k = 0; k <
sn.inchain[c].size(); ++k)
437 rw.push_back(
static_cast<double>(
sn.inchain[c][k]));
438 out += num(
static_cast<double>(c)) +
": " + row(rw);
443 for (std::size_t c = 0; c <
sn.visits.size(); ++c) {
444 if (c > 0) out +=
", ";
445 out += num(
static_cast<double>(c)) +
": " + tmat(
sn.visits[c]);
448 out +=
"nodevisits: {";
449 for (std::size_t c = 0; c <
sn.nodevisits.size(); ++c) {
450 if (c > 0) out +=
", ";
451 out += num(
static_cast<double>(c)) +
": " + tmat(
sn.nodevisits[c]);
454 out +=
"droprule: " + mat(droprule) +
"\n";
458 out +=
"nodeparam: {";
459 for (std::size_t i = 0; i < I; ++i) {
460 if (i > 0) out +=
", ";
461 out +=
"\"" +
sn.nodes[i].name +
"\": ";
462 const std::size_t ind = i + 1;
465 const typename std::map<std::size_t, qn::CacheParam<T>>::const_iterator it =
466 sn.nodeparam.find(ind);
467 if (it !=
sn.nodeparam.end()) {
468 Row cap_r, hit, miss;
469 for (std::size_t a = 0; a < it->second.itemcap.size(); ++a)
470 cap_r.push_back(it->second.itemcap[a]);
471 for (std::size_t a = 0; a < it->second.hitclass.size(); ++a)
472 hit.push_back(
static_cast<double>(it->second.hitclass[a]));
473 for (std::size_t a = 0; a < it->second.missclass.size(); ++a)
474 miss.push_back(
static_cast<double>(it->second.missclass[a]));
475 blk =
"{\"nitems\": " + num(
static_cast<double>(it->second.nitems)) +
476 ", \"itemcap\": " + row(cap_r) +
", \"hitclass\": " + row(hit) +
477 ", \"missclass\": " + row(miss) +
"}";
481 const typename std::map<std::size_t, typename qn::NetworkStruct<T>::JoinDecl>::const_iterator
482 it =
sn.joindecl.find(ind);
483 if (it !=
sn.joindecl.end())
484 blk =
"{\"joinStrategy\": " +
485 num(
static_cast<double>(
static_cast<int>(it->second.strategy))) +
486 ", \"joinRequired\": " + num(it->second.quorum) +
"}";
489 const typename std::map<std::size_t, qn::TransitionParam<T>>::const_iterator it =
490 sn.transparam.find(ind);
491 if (it !=
sn.transparam.end())
492 blk =
"{\"nmodes\": " + num(
static_cast<double>(it->second.nmodes)) +
493 ", \"modenames\": " + names(it->second.modenames) +
"}";
496 const typename std::map<std::size_t, qn::ForkParam<T>>::const_iterator it =
497 sn.forkparam.find(ind);
498 if (it !=
sn.forkparam.end())
499 blk =
"{\"fanOut\": " + tmat(it->second.fan_out_link) +
"}";
500 else if (
sn.nodes[i].nodetype == qn::NodeType::Fork)
501 blk =
"{\"fanOut\": " + num(
sn.nodes[i].tasks_per_link) +
"}";
503 out += blk.
empty() ? std::string(
"null") : blk;
512 std::string scd =
"cdscaling: {", sjd =
"jdscaling: {";
513 for (std::size_t i = 0; i < M; ++i) {
518 scd +=
"\"" +
sn.stations[i].name +
"\": " +
519 (
static_cast<bool>(
sn.stations[i].cdscaling) ?
"\"<function>\"" :
"null");
520 sjd +=
"\"" +
sn.stations[i].name +
"\": " +
521 (
static_cast<bool>(
sn.stations[i].jdscaling) ?
"\"<function>\"" :
"null");
523 out += scd +
"}\n" + sjd +
"}\n";
527 out +=
"csmatrix: {";
530 for (
typename std::map<std::size_t,
Matrix<T>>::const_iterator it =
sn.csmatrix.begin();
531 it !=
sn.csmatrix.end(); ++it) {
532 if (!first) out +=
", ";
534 out += num(
static_cast<double>(it->first)) +
": " + tmat(it->second);