85 const std::size_t NT = lqn.tshift + lqn.ntasks;
87 for (std::size_t idx = 1; idx <= NT; ++idx) {
89 anydead = anydead || zc.dead[idx];
91 if (!anydead)
return zc;
96 state.assign(N + 1, 0);
97 reach.assign(N + 1,
false);
98 blockAct.assign(N + 1, 0);
99 next.assign(N + 1, 0);
100 for (std::size_t e = lqn.eshift + 1; e <= lqn.eshift + lqn.nentries; ++e) {
102 if (!zc.reason.empty())
return zc;
106 for (std::size_t c = 1; c <= lqn.ncalls; ++c) {
107 const std::size_t tgt = lqn.callpair_dst[c];
108 if (lqn.calltype[c] == CallType::FWD && reach[tgt]) {
109 zc.reason =
"Entry " + lqn.names[lqn.callpair_src[c]] +
" forwards requests to " + lqn.names[tgt] +
110 ", which reaches a zero-capacity element: forwarding into a blocked call path is "
115 std::vector<bool> arv(N + 1,
false);
116 for (std::size_t e = lqn.eshift + 1; e <= lqn.eshift + lqn.nentries && e < lqn.has_arrival.size(); ++e) {
117 arv[e] = lqn.has_arrival[e];
118 if (arv[e] && reach[e]) {
119 zc.reason =
"Entry " + lqn.names[e] +
" has an open arrival stream and reaches a zero-capacity "
120 "element, where its requests accumulate without bound: the model has no steady state.";
126 std::vector<std::size_t> refs;
127 for (std::size_t t = 1; t <= lqn.ntasks; ++t)
128 if (lqn.isref[lqn.tshift + t]) refs.push_back(lqn.tshift + t);
129 std::vector<double> incoming(N + 1, 0.0), nroutes(N + 1, 0.0);
130 for (std::size_t t : refs) {
131 std::vector<std::size_t> ents;
132 for (std::size_t e : lqn.entriesof[t])
133 if (reach[e]) ents.push_back(e);
134 if (ents.empty())
continue;
135 if (ents.size() > 1) {
136 zc.reason =
"Reference task " + lqn.names[t] +
" reaches a zero-capacity element from " +
137 std::to_string(ents.size()) +
138 " of its entries: how its users divide between the blocked paths depends on the "
142 zc.trapped[t] =
true;
143 double h = lqn.mult[t];
145 std::size_t e = ents[0];
148 const std::size_t tt = lqn.parent[e];
157 h = std::min(h, task_cap(tt));
162 mark(blockAct[e], h);
164 zc.onroute[lqn.parent[tt]] =
true;
167 e = std::size_t(next[e]);
170 for (std::size_t tt = 1; tt <= N; ++tt)
171 if (nroutes[tt] > 1.0 && incoming[tt] > task_cap(tt)) {
172 zc.reason =
"Task " + lqn.names[tt] +
" has " +
fmt_g(lqn.mult[tt]) +
173 " threads and is on the blocked call paths of several reference tasks that send it " +
174 fmt_g(incoming[tt]) +
" requests: which of them hold its threads depends on the "
178 for (std::size_t idx = 1; idx <= NT; ++idx)
179 if (zc.onroute[idx] && lqn.repl[idx] > 1.0) {
180 zc.reason = lqn.names[idx] +
181 " is replicated and on a call path blocked at a zero-capacity element, which is not "
187 std::vector<std::size_t> starts;
188 for (std::size_t t : refs)
189 if (!zc.trapped[t]) starts.push_back(t);
190 for (std::size_t e = 1; e <= N; ++e)
191 if (arv[e]) starts.push_back(e);
192 const std::vector<bool> live = reach_from(starts);
193 for (std::size_t c = 1; c <= lqn.ncalls; ++c) {
194 const std::size_t tgt = lqn.callpair_dst[c];
195 if (lqn.calltype[c] == CallType::ASYNC && live[lqn.callpair_src[c]] &&
196 (reach[tgt] || zc.dead[lqn.parent[tgt]])) {
197 zc.reason =
"Activity " + lqn.names[lqn.callpair_src[c]] +
" calls " + lqn.names[tgt] +
198 " asynchronously, which reaches a zero-capacity element where its requests accumulate "
199 "without bound: the model has no steady state.";
203 for (std::size_t idx = 1; idx <= N; ++idx)
204 if (live[idx] && zc.dead[idx]) {
205 zc.reason = lqn.names[idx] +
206 " has zero capacity and is reached by a reference task that is not trapped there, "
207 "through a call that cannot block it.";
210 for (std::size_t tt = lqn.tshift + 1; tt <= NT; ++tt)
211 if (live[tt] && zc.held[tt] > 0.0 && std::isfinite(task_cap(tt)) && !lqn.isref[tt]) {
212 zc.reason =
"Task " + lqn.names[tt] +
213 " is reached by a reference task that is not trapped, while " +
fmt_g(zc.held[tt]) +
214 " of its " +
fmt_g(lqn.mult[tt]) +
215 " threads are held forever by requests blocked at a zero-capacity element.";
219 for (std::size_t i = 1; i <= N; ++i) zc.live = zc.live || live[i];
222 std::vector<std::size_t> tstarts;
223 for (std::size_t t : refs)
224 if (zc.trapped[t]) tstarts.push_back(t);
225 const std::vector<bool> fromTrapped = reach_from(tstarts);
226 std::vector<bool> drop(N + 1,
false);
227 for (std::size_t i = 1; i <= NT; ++i) drop[i] = (fromTrapped[i] || zc.dead[i]) && !live[i];
228 for (std::size_t idx = lqn.eshift + 1; idx <= lqn.ashift + lqn.nacts; ++idx) drop[idx] = drop[lqn.parent[idx]];