1function lsn = getStruct(self, regenerate)
2% LSN = GETSTRUCT(SELF, regenerate)
5% Copyright 2012-2026, Imperial College London
9if ~isempty(self.lsn) && ~regenerate
13lsn = LayeredNetworkStruct();
14lsn.nidx = 0; % total number of hosts, tasks, entries, and activities, except the reference tasks
16lsn.nhosts = length(self.hosts);
17lsn.ntasks = length(self.tasks);
18lsn.nentries = length(self.entries);
19lsn.nacts = length(self.activities);
20lsn.tshift = lsn.nhosts;
21lsn.eshift = lsn.nhosts + lsn.ntasks;
22lsn.ashift = lsn.nhosts + lsn.ntasks + lsn.nentries;
23lsn.cshift = lsn.nhosts + lsn.ntasks + lsn.nentries + lsn.nacts;
25%% analyze
static properties
26lsn.nidx = lsn.nhosts + lsn.ntasks + lsn.nentries + lsn.nacts;
28lsn.tasksof = cell(lsn.nhosts,1);
29lsn.entriesof = cell(lsn.nhosts+lsn.ntasks,1);
30lsn.actsof = cell(lsn.nhosts+lsn.ntasks+lsn.nentries,1);
31lsn.callsof = cell(lsn.nacts,1);
33lsn.hostdem_type = zeros(lsn.nidx, 1);
34lsn.hostdem_params = cell(lsn.nidx, 1);
35lsn.hostdem_mean = nan(lsn.nidx, 1);
36lsn.hostdem_scv = nan(lsn.nidx, 1);
37lsn.hostdem_proc = cell(lsn.nidx, 1);
40lsn.actthink_type = zeros(lsn.nidx, 1);
41lsn.actthink_params = cell(lsn.nidx, 1);
42lsn.actthink_mean = nan(lsn.nidx, 1);
43lsn.actthink_scv = nan(lsn.nidx, 1);
44lsn.actthink_proc = cell(lsn.nidx, 1);
47lsn.think_type = zeros(lsn.nidx, 1);
48lsn.think_params = cell(lsn.nidx, 1);
49lsn.think_mean = nan(lsn.nidx, 1);
50lsn.think_scv = nan(lsn.nidx, 1);
51lsn.think_proc = cell(lsn.nidx, 1);
56lsn.mult = zeros(lsn.nhosts+lsn.ntasks,1);
57lsn.maxmult = zeros(lsn.nhosts+lsn.ntasks,1);
58lsn.repl = zeros(lsn.nhosts+lsn.ntasks,1);
59lsn.type = zeros(lsn.nidx,1);
60lsn.graph = zeros(lsn.nidx,lsn.nidx);
61loop_back_edges =
false(lsn.nidx,lsn.nidx);
63lsn.replygraph =
false(lsn.nacts,lsn.nentries);
64lsn.actphase = ones(lsn.nacts,1); % Phase
for each activity (
default=1)
66lsn.nitems = zeros(lsn.nhosts+lsn.ntasks+lsn.nentries,1);
69lsn.itemproc_type = zeros(lsn.nidx, 1);
70lsn.itemproc_params = cell(lsn.nidx, 1);
71lsn.itemproc_mean = nan(lsn.nidx, 1);
72lsn.itemproc_scv = nan(lsn.nidx, 1);
73lsn.itemproc_proc = cell(lsn.nidx, 1);
75lsn.iscache = zeros(lsn.nhosts+lsn.ntasks,1);
76lsn.setuptime = cell(lsn.nhosts+lsn.ntasks,1);
77lsn.setuptime_type = zeros(lsn.nidx, 1);
78lsn.setuptime_params = cell(lsn.nidx, 1);
79lsn.setuptime_mean = nan(lsn.nidx, 1);
80lsn.setuptime_scv = nan(lsn.nidx, 1);
81lsn.setuptime_proc = cell(lsn.nidx, 1);
84lsn.delayofftime_type = zeros(lsn.nidx, 1);
85lsn.delayofftime_params = cell(lsn.nidx, 1);
86lsn.delayofftime_mean = nan(lsn.nidx, 1);
87lsn.delayofftime_scv = nan(lsn.nidx, 1);
88lsn.delayofftime_proc = cell(lsn.nidx, 1);
90lsn.isfunction = zeros(lsn.nhosts+lsn.ntasks,1);
92% Open arrival distributions
94lsn.arrival_type = zeros(lsn.nidx, 1);
95lsn.arrival_params = cell(lsn.nidx, 1);
96lsn.arrival_mean = nan(lsn.nidx, 1);
97lsn.arrival_scv = nan(lsn.nidx, 1);
98lsn.arrival_proc = cell(lsn.nidx, 1);
101for p=1:lsn.nhosts %
for every processor, scheduling, multiplicity, replication, names, type
102 lsn.sched(idx,1) = SchedStrategy.fromText(self.hosts{p}.scheduling);
103 lsn.mult(idx,1) = self.hosts{p}.multiplicity;
104 lsn.repl(idx,1) = self.hosts{p}.replication;
105 lsn.names{idx,1} = self.hosts{p}.name;
106 lsn.hashnames{idx,1} = [
'P:',lsn.names{idx,1}];
107 %lsn.shortnames{idx,1} = [
'P',num2str(p)];
108 lsn.type(idx,1) = LayeredNetworkElement.HOST; % processor
113 lsn.sched(idx,1) = SchedStrategy.fromText(self.tasks{t}.scheduling);
114 % hostdem
for tasks
is Immediate
115 immDist = Immediate.getInstance();
116 lsn.hostdem{idx,1} = immDist;
117 [lsn.hostdem_type(idx), lsn.hostdem_params{idx}, lsn.hostdem_mean(idx), lsn.hostdem_scv(idx), lsn.hostdem_proc{idx}] = extractDistParams(immDist);
119 thinkDist = self.tasks{t}.thinkTime;
120 lsn.think{idx,1} = thinkDist;
121 [lsn.think_type(idx), lsn.think_params{idx}, lsn.think_mean(idx), lsn.think_scv(idx), lsn.think_proc{idx}] = extractDistParams(thinkDist);
122 lsn.mult(idx,1) = self.tasks{t}.multiplicity;
123 lsn.repl(idx,1) = self.tasks{t}.replication;
124 lsn.names{idx,1} = self.tasks{t}.name;
125 switch lsn.sched(idx,1)
126 case SchedStrategy.REF
127 lsn.hashnames{idx,1} = [
'R:',lsn.names{idx,1}];
128 %lsn.shortnames{idx,1} = [
'R',num2str(idx-tshift)];
130 lsn.hashnames{idx,1} = [
'T:',lsn.names{idx,1}];
131 %lsn.shortnames{idx,1} = [
'T',num2str(idx-tshift)];
133 switch class(self.tasks{t})
135 lsn.nitems(idx,1) = self.tasks{t}.items;
136 lsn.itemcap{idx,1} = self.tasks{t}.itemLevelCap;
137 lsn.replacestrat(idx,1) = self.tasks{t}.replacestrategy;
138 lsn.hashnames{idx,1} = [
'C:',lsn.names{idx,1}];
140 setupDist = self.tasks{t}.SetupTime;
141 lsn.setuptime{idx,1} = setupDist;
142 [lsn.setuptime_type(idx), lsn.setuptime_params{idx}, lsn.setuptime_mean(idx), lsn.setuptime_scv(idx), lsn.setuptime_proc{idx}] = extractDistParams(setupDist);
143 delayoffDist = self.tasks{t}.DelayOffTime;
144 lsn.delayofftime{idx,1} = delayoffDist;
145 [lsn.delayofftime_type(idx), lsn.delayofftime_params{idx}, lsn.delayofftime_mean(idx), lsn.delayofftime_scv(idx), lsn.delayofftime_proc{idx}] = extractDistParams(delayoffDist);
146 lsn.hashnames{idx,1} = [
'F:',lsn.names{idx,1}];
147 %lsn.shortnames{idx,1} = [
'C',num2str(idx-tshift)];
149 pidx = find(cellfun(@(x) strcmp(x.name, self.tasks{t}.parent.name), self.hosts));
150 lsn.parent(idx) = pidx;
151 lsn.graph(idx, pidx) = 1;
152 lsn.type(idx) = LayeredNetworkElement.TASK; % task
156for p=1:lsn.nhosts %
for every processor
158 lsn.tasksof{pidx} = find(lsn.parent == pidx);
162 lsn.names{idx,1} = self.entries{e}.name;
164 % Extract open arrival distribution
if present
165 if ~isempty(self.entries{e}.arrival) && isa(self.entries{e}.arrival,
'Distribution')
166 arrDist = self.entries{e}.arrival;
167 lsn.arrival{idx,1} = arrDist;
168 [lsn.arrival_type(idx), lsn.arrival_params{idx}, lsn.arrival_mean(idx), lsn.arrival_scv(idx), lsn.arrival_proc{idx}] = extractDistParams(arrDist);
171 switch class(self.entries{e})
173 lsn.hashnames{idx,1} = [
'E:',lsn.names{idx,1}];
174 for a=1:length(self.entries{e}.replyActivity)
175 ractname = self.entries{e}.replyActivity{a};
176 ractidx = find(cellfun(@(x) strcmp(x.name, ractname), self.activities));
177 lsn.replygraph(ractidx,e)=
true;
179 %lsn.shortnames{idx,1} = [
'E',num2str(idx-eshift)];
181 lsn.hashnames{idx,1} = [
'I:',lsn.names{idx,1}];
182 %lsn.shortnames{idx,1} = [
'I',num2str(idx-eshift)];
183 lsn.nitems(idx,1) = self.entries{e}.cardinality;
184 itemDist = self.entries{e}.popularity;
185 lsn.itemproc{idx,1} = itemDist;
186 [lsn.itemproc_type(idx), lsn.itemproc_params{idx}, lsn.itemproc_mean(idx), lsn.itemproc_scv(idx), lsn.itemproc_proc{idx}] = extractDistParams(itemDist);
188 % hostdem
for entries
is Immediate
189 immDist = Immediate.getInstance();
190 lsn.hostdem{idx,1} = immDist;
191 [lsn.hostdem_type(idx), lsn.hostdem_params{idx}, lsn.hostdem_mean(idx), lsn.hostdem_scv(idx), lsn.hostdem_proc{idx}] = extractDistParams(immDist);
192 tidx = lsn.nhosts + find(cellfun(@(x) strcmp(x.name, self.entries{e}.parent.name), self.tasks));
193 lsn.parent(idx) = tidx;
194 lsn.graph(tidx,idx) = 1;
195 lsn.entriesof{tidx}(end+1) = idx;
196 lsn.type(idx) = LayeredNetworkElement.ENTRY; % entries
201 lsn.names{idx,1} = self.activities{a}.name;
202 lsn.hashnames{idx,1} = [
'A:',lsn.names{idx,1}];
203 %lsn.shortnames{idx,1} = [
'A',num2str(idx - lsn.ashift)];
204 % hostDemand
for activities
205 hostdemDist = self.activities{a}.hostDemand;
206 lsn.hostdem{idx,1} = hostdemDist;
207 [lsn.hostdem_type(idx), lsn.hostdem_params{idx}, lsn.hostdem_mean(idx), lsn.hostdem_scv(idx), lsn.hostdem_proc{idx}] = extractDistParams(hostdemDist);
208 % thinkTime
for activities
209 actthinkDist = self.activities{a}.thinkTime;
210 lsn.actthink{idx,1} = actthinkDist;
211 [lsn.actthink_type(idx), lsn.actthink_params{idx}, lsn.actthink_mean(idx), lsn.actthink_scv(idx), lsn.actthink_proc{idx}] = extractDistParams(actthinkDist);
212 tidx = lsn.nhosts + find(cellfun(@(x) strcmp(x.name, self.activities{a}.parent.name), self.tasks));
213 lsn.parent(idx) = tidx;
214 lsn.actsof{tidx}(end+1) = idx;
215 lsn.type(idx) = LayeredNetworkElement.ACTIVITY; % activities
216 lsn.actphase(a) = self.activities{a}.phase; % Store activity phase
220nidx = idx - 1; % number of indices
221lsn.graph(nidx,nidx) = 0;
226lsn.calltype = sparse([],lsn.nidx,1);
227lsn.iscaller = sparse(lsn.nidx,lsn.nidx);
228lsn.issynccaller = sparse(lsn.nidx,lsn.nidx);
229lsn.isasynccaller = sparse(lsn.nidx,lsn.nidx);
232lsn.callproc_type = [];
233lsn.callproc_params = {};
234lsn.callproc_mean = [];
235lsn.callproc_scv = [];
236lsn.callproc_proc = {};
238lsn.callhashnames = {};
239%lsn.callshortnames = {};
240lsn.taskgraph = sparse(lsn.tshift+lsn.ntasks, lsn.tshift+lsn.ntasks);
241lsn.actpretype = sparse(lsn.nidx,1);
242lsn.actposttype = sparse(lsn.nidx,1);
244% Track boundToEntry mappings to validate uniqueness
250 for a=1:length(self.tasks{t}.activities)
251 aidx = findstring(lsn.hashnames, ['A:',tasks{t}.activities(a).name]);
252 lsn.callsof{aidx} = [];
253 boundToEntry = tasks{t}.activities(a).boundToEntry;
254 %
for b=1:length(boundToEntry)
255 eidx = findstring(lsn.hashnames, [
'E:',boundToEntry]);
257 eidx = findstring(lsn.hashnames, [
'I:',boundToEntry]);
260 lsn.graph(eidx, aidx) = 1;
262 % Check
if this entry
is already bound to another activity
263 activityName = tasks{t}.activities(a).name;
264 existingIdx = find(strcmp(boundEntries, boundToEntry), 1);
265 if ~isempty(existingIdx)
266 line_error(mfilename, sprintf(
'Multiple activities (%s, %s) are bound to the same entry: %s', ...
267 boundActivities{existingIdx}, activityName, boundToEntry));
269 boundEntries{end+1} = boundToEntry;
270 boundActivities{end+1} = activityName;
275 for s=1:length(tasks{t}.activities(a).syncCallDests)
276 target_eidx = findstring(lsn.hashnames, [
'E:',tasks{t}.activities(a).syncCallDests{s}]);
278 target_eidx = findstring(lsn.hashnames, [
'I:',tasks{t}.activities(a).syncCallDests{s}]);
280 target_tidx = lsn.parent(target_eidx);
282 lsn.calltype(cidx,1) = CallType.SYNC;
283 lsn.callpair(cidx,1:2) = [aidx,target_eidx];
284 if tidx == target_tidx
285 line_error(mfilename,
'An entry on a task cannot call another entry on the same task.');
287 lsn.callnames{cidx,1} = [lsn.names{aidx},
'=>',lsn.names{target_eidx}];
288 lsn.callhashnames{cidx,1} = [lsn.hashnames{aidx},
'=>',lsn.hashnames{target_eidx}];
289 %lsn.callshortnames{cidx,1} = [lsn.shortnames{aidx},
'=>',lsn.shortnames{target_eidx}];
290 callDist = Geometric(1/tasks{t}.activities(a).syncCallMeans(s)); % synch
291 lsn.callproc{cidx,1} = callDist;
292 [lsn.callproc_type(cidx), lsn.callproc_params{cidx}, lsn.callproc_mean(cidx), lsn.callproc_scv(cidx), lsn.callproc_proc{cidx}] = extractDistParams(callDist);
293 lsn.callsof{aidx}(end+1) = cidx;
294 lsn.iscaller(tidx, target_tidx) =
true;
295 lsn.iscaller(aidx, target_tidx) =
true;
296 lsn.iscaller(tidx, target_eidx) =
true;
297 lsn.iscaller(aidx, target_eidx) =
true;
298 lsn.issynccaller(tidx, target_tidx) =
true;
299 lsn.issynccaller(aidx, target_tidx) =
true;
300 lsn.issynccaller(tidx, target_eidx) =
true;
301 lsn.issynccaller(aidx, target_eidx) =
true;
302 lsn.taskgraph(tidx, target_tidx) = 1;
303 lsn.graph(aidx, target_eidx) = 1;
306 for s=1:length(tasks{t}.activities(a).asyncCallDests)
307 target_entry_name = tasks{t}.activities(a).asyncCallDests{s};
308 target_eidx = findstring(lsn.hashnames,[
'E:',target_entry_name]);
310 target_eidx = findstring(lsn.hashnames, [
'I:',target_entry_name]);
312 % Validate that the target entry exists
314 line_error(mfilename, sprintf(
'Activity "%s" has an async call to non-existent entry "%s".', tasks{t}.activities(a).name, target_entry_name));
316 target_tidx = lsn.parent(target_eidx);
317 % Check
for self-referential async calls (task calling itself)
318 if tidx == target_tidx
319 line_error(mfilename, sprintf(
'Activity "%s" in task "%s" has an async call to an entry on the same task. Async self-calls are not supported.', tasks{t}.activities(a).name, tasks{t}.name));
322 lsn.callpair(cidx,1:2) = [aidx,target_eidx];
323 lsn.calltype(cidx,1) = CallType.ASYNC; % async
324 lsn.callnames{cidx,1} = [lsn.names{aidx},
'->',lsn.names{target_eidx}];
325 lsn.callhashnames{cidx,1} = [lsn.hashnames{aidx},
'->',lsn.hashnames{target_eidx}];
326 %lsn.callshortnames{cidx,1} = [lsn.shortnames{aidx},
'->',lsn.shortnames{target_eidx}];
327 callDist = Geometric(1/tasks{t}.activities(a).asyncCallMeans(s)); % asynch
328 lsn.callproc{cidx,1} = callDist;
329 [lsn.callproc_type(cidx), lsn.callproc_params{cidx}, lsn.callproc_mean(cidx), lsn.callproc_scv(cidx), lsn.callproc_proc{cidx}] = extractDistParams(callDist);
330 lsn.callsof{aidx}(end+1) = cidx;
331 lsn.iscaller(aidx, target_tidx) =
true;
332 lsn.iscaller(aidx, target_eidx) =
true;
333 lsn.iscaller(tidx, target_tidx) =
true;
334 lsn.iscaller(tidx, target_eidx) =
true;
335 lsn.isasynccaller(tidx, target_tidx) =
true;
336 lsn.isasynccaller(tidx, target_eidx) =
true;
337 lsn.isasynccaller(aidx, target_tidx) =
true;
338 lsn.isasynccaller(aidx, target_eidx) =
true;
339 lsn.taskgraph(tidx, target_tidx) = 1;
340 lsn.graph(aidx, target_eidx) = 1;
344 for ap=1:length(tasks{t}.precedences)
345 pretype = tasks{t}.precedences(ap).preType;
346 posttype = tasks{t}.precedences(ap).postType;
347 preacts = tasks{t}.precedences(ap).preActs;
348 postacts = tasks{t}.precedences(ap).postActs;
350 % Validate PRE_AND activities exist before processing
351 if pretype == ActivityPrecedenceType.PRE_AND
353 line_error(mfilename, sprintf(
'PRE_AND precedence in task "%s" has no pre activities.', tasks{t}.name));
355 for prea = 1:length(preacts)
356 preaidx = findstring(lsn.hashnames, [
'A:',preacts{prea}]);
358 line_error(mfilename, sprintf(
'PRE_AND precedence references non-existent activity "%s" in task "%s".', preacts{prea}, tasks{t}.name));
360 if preaidx > 0 && lsn.parent(preaidx) ~= tidx
361 line_error(mfilename, sprintf(
'PRE_AND precedence in task "%s" references activity "%s" from a different task.', tasks{t}.name, preacts{prea}));
366 % Validate POST_AND activities exist before processing
367 if posttype == ActivityPrecedenceType.POST_AND
369 line_error(mfilename, sprintf(
'POST_AND precedence in task "%s" has no post activities.', tasks{t}.name));
371 for posta = 1:length(postacts)
372 postaidx = findstring(lsn.hashnames, [
'A:',postacts{posta}]);
374 line_error(mfilename, sprintf(
'POST_AND precedence references non-existent activity "%s" in task "%s".', postacts{posta}, tasks{t}.name));
376 if postaidx > 0 && lsn.parent(postaidx) ~= tidx
377 line_error(mfilename, sprintf(
'POST_AND precedence in task "%s" references activity "%s" from a different task.', tasks{t}.name, postacts{posta}));
382 for prea = 1:length(preacts)
383 preaidx = findstring(lsn.hashnames, [
'A:',tasks{t}.precedences(ap).preActs{prea}]);
385 case ActivityPrecedenceType.PRE_AND
386 quorum = tasks{t}.precedences(ap).preParams;
390 preParam = quorum / length(preacts);
396 case ActivityPrecedenceType.POST_OR
397 for posta = 1:length(postacts)
398 postaidx = findstring(lsn.hashnames, [
'A:',tasks{t}.precedences(ap).postActs{posta}]);
399 probs = tasks{t}.precedences(ap).postParams;
400 postParam = probs(posta);
401 lsn.graph(preaidx, postaidx) = preParam * postParam;
402 lsn.actpretype(preaidx) = sparse(tasks{t}.precedences(ap).preType);
403 lsn.actposttype(postaidx) = sparse(tasks{t}.precedences(ap).postType);
405 case ActivityPrecedenceType.POST_AND
406 for posta = 1:length(postacts)
407 postaidx = findstring(lsn.hashnames, [
'A:',tasks{t}.precedences(ap).postActs{posta}]);
408 lsn.graph(preaidx, postaidx) = 1;
409 lsn.actpretype(preaidx) = sparse(tasks{t}.precedences(ap).preType);
410 lsn.actposttype(postaidx) = sparse(tasks{t}.precedences(ap).postType);
412 case ActivityPrecedenceType.POST_LOOP
413 counts = tasks{t}.precedences(ap).postParams;
414 % add the end activity
415 enda = length(postacts);
416 loopentryaidx = findstring(lsn.hashnames, [
'A:',tasks{t}.precedences(ap).preActs{1}]);
417 loopstartaidx = findstring(lsn.hashnames, [
'A:',tasks{t}.precedences(ap).postActs{1}]);
418 loopendaidx = findstring(lsn.hashnames, [
'A:',tasks{t}.precedences(ap).postActs{enda}]);
421 % When expected iterations < 1, we may skip loop entirely
422 % E[iterations] = counts means
P(enter loop) = counts
423 lsn.graph(loopentryaidx, loopstartaidx) = counts;
424 lsn.graph(loopentryaidx, loopendaidx) = 1.0 - counts;
425 % Process activities inside the loop as serial chain
426 curaidx = loopstartaidx;
427 for posta = 2:(length(postacts)-1)
428 postaidx = findstring(lsn.hashnames, [
'A:',tasks{t}.precedences(ap).postActs{posta}]);
429 lsn.graph(curaidx, postaidx) = 1.0;
430 lsn.actposttype(postaidx) = sparse((tasks{t}.precedences(ap).postType));
433 % After loop body, always exit to end (no looping back)
434 lsn.graph(curaidx, loopendaidx) = 1.0;
435 lsn.actposttype(loopstartaidx) = sparse((tasks{t}.precedences(ap).postType));
437 % When expected iterations >= 1, always enter loop
438 % E[iterations] = 1/(1-p) = counts => p = 1 - 1/counts
439 curaidx = loopentryaidx;
440 for posta = 1:(length(postacts)-1) % last one
is 'end' of loop activity
441 postaidx = findstring(lsn.hashnames, [
'A:',tasks{t}.precedences(ap).postActs{posta}]);
442 lsn.graph(curaidx, postaidx) = 1.0;
443 lsn.actposttype(postaidx) = sparse((tasks{t}.precedences(ap).postType));
446 loop_back_edges(curaidx, loopstartaidx) =
true;
447 lsn.graph(curaidx, loopstartaidx) = 1.0 - 1.0 / counts;
448 lsn.graph(curaidx, loopendaidx) = 1.0 / counts;
450 lsn.actposttype(loopendaidx) = sparse((tasks{t}.precedences(ap).postType));
452 for posta = 1:length(postacts)
453 postaidx = findstring(lsn.hashnames, [
'A:',tasks{t}.precedences(ap).postActs{posta}]);
455 lsn.graph(preaidx, postaidx) = preParam * postParam;
456 lsn.actpretype(preaidx) = sparse(tasks{t}.precedences(ap).preType);
457 lsn.actposttype(postaidx) = sparse(tasks{t}.precedences(ap).postType);
464%% Process forwarding calls from entries
465for e = 1:length(self.entries)
466 entry = self.entries{e};
467 eidx = findstring(lsn.hashnames, [
'E:', entry.name]);
469 eidx = findstring(lsn.hashnames, [
'I:', entry.name]);
474 source_tidx = lsn.parent(eidx);
476 for fw = 1:length(entry.forwardingDests)
477 target_entry_name = entry.forwardingDests{fw};
478 target_eidx = findstring(lsn.hashnames, [
'E:', target_entry_name]);
480 target_eidx = findstring(lsn.hashnames, [
'I:', target_entry_name]);
483 line_error(mfilename, sprintf(
'Entry "%s" forwards to non-existent entry "%s".', entry.name, target_entry_name));
485 target_tidx = lsn.parent(target_eidx);
487 % Validate: cannot forward to same task
488 if source_tidx == target_tidx
489 line_error(mfilename, sprintf(
'Entry "%s" cannot forward to entry "%s" on the same task.', entry.name, target_entry_name));
493 lsn.calltype(cidx, 1) = CallType.FWD;
494 lsn.callpair(cidx, 1:2) = [eidx, target_eidx];
495 lsn.callnames{cidx, 1} = [lsn.names{eidx},
'~>', lsn.names{target_eidx}];
496 lsn.callhashnames{cidx, 1} = [lsn.hashnames{eidx},
'~>', lsn.hashnames{target_eidx}];
498 % Forwarding probability (stored as mean calls)
499 fwdProb = entry.forwardingProbs(fw);
500 callDist = Geometric(1.0 / fwdProb);
501 lsn.callproc{cidx, 1} = callDist;
502 [lsn.callproc_type(cidx), lsn.callproc_params{cidx}, lsn.callproc_mean(cidx), lsn.callproc_scv(cidx), lsn.callproc_proc{cidx}] = extractDistParams(callDist);
504 % Update task graph to reflect forwarding relationship
505 lsn.taskgraph(source_tidx, target_tidx) = 1;
506 lsn.graph(eidx, target_eidx) = 1;
508 % NOTE: We
do NOT set issynccaller
for forwarding calls because:
509 % - Forwarding
is NOT a sync call - the forwarder does NOT wait
for the target
510 % - The forwarder sends the request to the target and the target replies
511 % directly to the original caller (not back to the forwarder)
512 % - The forwarding target
's workload comes from the forwarding probability,
513 % not from a separate closed class in the queueing network decomposition
515 % Setting issynccaller here was causing incorrect throughput calculations
516 % because it created separate closed classes for forwarding targets.
520% Check for entries without boundTo activities
521unbound = find(all(~lsn.graph(lsn.eshift+1 : lsn.eshift+lsn.nentries, ...
522 lsn.ashift+1 : lsn.ashift+lsn.nacts), 2)); %#ok<EFIND>
524 line_error(mfilename, 'An entry does not have any boundTo activity.
');
527%lsn.replies = false(1,lsn.nacts);
528%lsn.replygraph = 0*lsn.graph;
529% Snapshot which entries have explicit replies (from repliesTo calls)
530% before adding implicit ones. This way OrFork branches all get marked.
531hasExplicitReply = any(lsn.replygraph, 1);
534 for aidx = lsn.actsof{tidx}
535 postaidxs = find(lsn.graph(aidx, :));
537 % if no successor is an action of tidx
538 for postaidx = postaidxs
539 if any(lsn.actsof{tidx} == postaidx)
544 % this is a leaf node, search backward for the parent entry,
545 % which is assumed to be unique
546 %lsn.replies(aidx-lsn.nacts) = true;
548 while lsn.type(parentidx) ~= LayeredNetworkElement.ENTRY
549 ancestors = find(lsn.graph(:,parentidx));
550 parentidx = at(ancestors,1); % only choose first ancestor
552 if lsn.type(parentidx) == LayeredNetworkElement.ENTRY
553 eidx = parentidx - lsn.eshift;
554 % Only add implicit reply if no explicit reply exists for this entry
555 % This supports Phase-2 activities (activities after an explicit reply)
556 if ~hasExplicitReply(eidx)
557 lsn.replygraph(aidx-lsn.ashift, eidx) = true;
563lsn.ncalls = size(lsn.calltype,1);
565% correct multiplicity for infinite server stations
566for tidx = find(lsn.sched == SchedStrategy.INF)
567 if lsn.type(tidx) == LayeredNetworkElement.TASK
568 callers = find(lsn.taskgraph(:, tidx));
569 callers_inf = strcmp(lsn.mult(callers), SchedStrategy.INF);
571 % if a caller is also inf, then we would need to recursively
572 % determine the maximum multiplicity, we instead use a
574 lsn.mult(tidx) = sum(lsn.mult(~callers_inf)) + sum(callers_inf)*max(lsn.mult);
576 lsn.mult(tidx) = sum(lsn.mult(callers));
581lsn.refset = zeros(lsn.nidx,1);
582[conncomps, roots]=graph_connected_components(lsn.taskgraph(lsn.nhosts+1:end, lsn.nhosts+1:end));
583lsn.conntasks = conncomps;
585 lsn.conntasks(find(lsn.conntasks == r)) = lsn.tshift+roots(r);
588lsn.isref = lsn.sched == SchedStrategy.REF;
589lsn.iscache(1:(lsn.tshift+lsn.ntasks)) = lsn.nitems(1:(lsn.tshift+lsn.ntasks))>0;
590lsn.isfunction(1:(lsn.tshift+lsn.ntasks)) = ~cellfun(@isempty, lsn.setuptime(1:(lsn.tshift+lsn.ntasks)));
592% the dag differs from the graph:
593% - dag swaps the direction of entry-task edges
594% - dag removes loop edges
597% Reverse edges from TASK to ENTRY if not a reference
599 if lsn.type(i) == LayeredNetworkElement.TASK && ~lsn.isref(i)
601 if lsn.type(j) == LayeredNetworkElement.ENTRY && dag(i,j)
609% Compute entry-to-activity reachability within the same task
610for eoff = 1:lsn.nentries
611 eidx = lsn.eshift + eoff; % global entry index
612 tidx = lsn.parent(eidx); % parent task index
613 visited = false(1,nidx); % global visit mask
615 visited(eidx) = true;
616 while ~isempty(stack)
619 nbrs = find(lsn.graph(v,:));
620 nbrs = nbrs(~visited(nbrs));
621 visited(nbrs) = true;
622 stack = [stack nbrs]; %#ok<AGROW>
624 acts = find(visited & ...
625 lsn.type' == LayeredNetworkElement.ACTIVITY & ...
627 lsn.actsof{lsn.eshift+eoff} = acts;
631dag(loop_back_edges(:)) = 0;
633% Compute bounds on multiplicies
for host processors and non-ref tasks
635 lsn.maxmult = lsn_max_multiplicity(lsn);
636 lsn.maxmult = lsn.maxmult(1:(lsn.tshift+lsn.ntasks));
638 line_error(mfilename,
'A cycle exists in an activity graph.');
640% Check
for non-terminal reply activities
641% An activity that replies to an entry should not have Phase 1 successor activities
642% Phase 2 successors are allowed (post-reply processing)
644 if any(lsn.replygraph(a, :)) % activity
'a' replies to some entry
645 aidx = lsn.ashift + a; % global activity index
646 successors = find(lsn.graph(aidx, :));
647 for succ = successors
648 if succ > lsn.eshift + lsn.nentries % successor
is an activity
649 succ_act_idx = succ - lsn.ashift; % convert to activity array index
650 if lsn.actphase(succ_act_idx) == 1
651 line_error(mfilename,
'Unsupported replyTo in non-terminal activity.');
659if ~isempty(lsn.callpair)
660 target_eidxs = unique(lsn.callpair(:,2));
661 for eidx=target_eidxs(:)'
662 call_types_to_eidx = lsn.calltype(find(lsn.callpair(:,2) == eidx),1);
663 if ~all(call_types_to_eidx == call_types_to_eidx(1))
664 line_error(mfilename, 'An entry
is called both synchronously and asynchronously.');
672function [dtype, params, mean_val, scv_val, proc] = extractDistParams(dist)
673% EXTRACTDISTPARAMS Extract primitive parameters from a Distribution
object
676% dtype - ProcessType enum value
677% params - Vector/cell of primitive parameters
678% mean_val - Precomputed mean (NaN if unavailable)
679% scv_val - Precomputed SCV (NaN if unavailable)
680% proc - Process representation {D0, D1} or []
for non-Markovian
683 dtype = ProcessType.DISABLED;
693 mean_val = dist.getMean();
699 scv_val = dist.getSCV();
704% Get process representation
if available
706 proc = dist.getRepres();
714% Extract parameters based on distribution type
715distClass =
class(dist);
718 dtype = ProcessType.DISABLED;
722 dtype = ProcessType.IMMEDIATE;
728 dtype = ProcessType.EXP;
729 params = dist.getParam(1).paramValue; % lambda
732 dtype = ProcessType.ERLANG;
733 params = [dist.getParam(1).paramValue; dist.getParam(2).paramValue]; % [k; mu]
736 dtype = ProcessType.HYPEREXP;
737 % p1, lambda1, lambda2
738 params = [dist.getParam(1).paramValue; dist.getParam(2).paramValue; dist.getParam(3).paramValue];
741 dtype = ProcessType.COXIAN;
742 mu = dist.getParam(1).paramValue;
743 phi = dist.getParam(2).paramValue;
744 params = [length(mu); mu(:); phi(:)];
747 dtype = ProcessType.COX2;
748 mu1 = dist.getParam(1).paramValue;
749 mu2 = dist.getParam(2).paramValue;
750 phi = dist.getParam(3).paramValue;
751 params = [mu1; mu2; phi];
754 dtype = ProcessType.APH;
755 alpha = dist.getParam(1).paramValue;
756 T = dist.getParam(2).paramValue;
758 params = [n; alpha(:); T(:)];
761 dtype = ProcessType.PH;
762 alpha = dist.getParam(1).paramValue;
763 T = dist.getParam(2).paramValue;
765 params = [n; alpha(:); T(:)];
768 dtype = ProcessType.DET;
769 params = dist.getParam(1).paramValue;
772 dtype = ProcessType.UNIFORM;
773 params = [dist.getParam(1).paramValue; dist.getParam(2).paramValue]; % [a; b]
776 dtype = ProcessType.GAMMA;
777 params = [dist.getParam(1).paramValue; dist.getParam(2).paramValue]; % [shape; scale]
780 dtype = ProcessType.PARETO;
781 params = [dist.getParam(1).paramValue; dist.getParam(2).paramValue]; % [shape; scale]
784 dtype = ProcessType.WEIBULL;
785 params = [dist.getParam(1).paramValue; dist.getParam(2).paramValue]; % [shape; scale]
788 dtype = ProcessType.LOGNORMAL;
789 params = [dist.getParam(1).paramValue; dist.getParam(2).paramValue]; % [mu; sigma]
792 dtype = ProcessType.MAP;
793 D0 = dist.getParam(1).paramValue;
794 D1 = dist.getParam(2).paramValue;
796 params = [n; D0(:); D1(:)];
799 dtype = ProcessType.MMPP2;
800 lambda0 = dist.getParam(1).paramValue;
801 lambda1 = dist.getParam(2).paramValue;
802 sigma0 = dist.getParam(3).paramValue;
803 sigma1 = dist.getParam(4).paramValue;
804 params = [lambda0; lambda1; sigma0; sigma1];
807 dtype = ProcessType.GEOMETRIC;
808 params = dist.getParam(1).paramValue; % p (success probability)
811 dtype = ProcessType.POISSON;
812 params = dist.getParam(1).paramValue; % lambda
815 dtype = ProcessType.BINOMIAL;
816 params = [dist.getParam(1).paramValue; dist.getParam(2).paramValue]; % [n; p]
819 dtype = ProcessType.BERNOULLI;
820 params = dist.getParam(1).paramValue; % p
822 case {
'Replayer',
'Trace'}
823 dtype = ProcessType.REPLAYER;
824 params = []; % Trace data not stored as primitive
826 case 'DiscreteSampler'
827 dtype = ProcessType.GEOMETRIC; % Approximation
831 % Fallback
for unhandled types
832 dtype = ProcessType.DISABLED;