LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sn_build_fj_sync_map.m
1function fjSyncMap = sn_build_fj_sync_map(sn)
2% FJSYNCMAP = SN_BUILD_FJ_SYNC_MAP(SN)
3%
4% Builds a fork-join synchronization map from LINE's sn structure.
5% For each (Fork, Join) pair, identifies which source nodes feed into the
6% join and must be synchronized using mmap_max.
7%
8% Output:
9% fjSyncMap.nodeSync(joinIdx, srcIdx) = groupId
10% - groupId > 0 means srcIdx belongs to sync group groupId at joinIdx
11% - groupId == 0 means srcIdx is an independent (non-synced) flow
12% fjSyncMap.forkOfGroup(groupId) = forkIdx
13% fjSyncMap.joinOfGroup(groupId) = joinIdx
14% fjSyncMap.nGroups = total number of sync groups
15%
16% Copyright (c) 2012-2026, Imperial College London
17% All rights reserved.
18
19I = sn.nnodes;
20K = sn.nclasses;
21
22% nodeSync is indexed by (destination node, source node)
23nodeSync = zeros(I, I);
24
25groupId = 0;
26forkOfGroup = [];
27joinOfGroup = [];
28
29% Iterate over all (Fork, Join) pairs from sn.fj
30forkIndices = find(any(sn.fj, 2))';
31for forkIdx = forkIndices
32 joinIdx = find(sn.fj(forkIdx, :));
33 if isempty(joinIdx)
34 continue;
35 end
36 for ji = 1:length(joinIdx)
37 jnd = joinIdx(ji);
38 groupId = groupId + 1;
39 forkOfGroup(groupId) = forkIdx;
40 joinOfGroup(groupId) = jnd;
41
42 % Find nodes on the parallel path between this fork and join.
43 % A node is on the parallel path if:
44 % 1. The fork routes to it (for at least one class), AND
45 % 2. It routes to the join (for at least one class)
46 for ind = 1:I
47 if ind == forkIdx || ind == jnd
48 continue;
49 end
50 forkRoutesToNode = false;
51 nodeRoutesToJoin = false;
52 for k = 1:K
53 if sn.rtnodes((forkIdx-1)*K+k, (ind-1)*K+k) > 0
54 forkRoutesToNode = true;
55 end
56 if sn.rtnodes((ind-1)*K+k, (jnd-1)*K+k) > 0
57 nodeRoutesToJoin = true;
58 end
59 end
60 if forkRoutesToNode && nodeRoutesToJoin
61 nodeSync(jnd, ind) = groupId;
62 end
63 end
64 end
65end
66
67fjSyncMap.nodeSync = nodeSync;
68fjSyncMap.forkOfGroup = forkOfGroup;
69fjSyncMap.joinOfGroup = joinOfGroup;
70fjSyncMap.nGroups = groupId;
71end
Definition mmt.m:93