Download presentation

Presentation is loading. Please wait.

Published byDomenic Burns Modified about 1 year ago

1
1 An Associative Program for the MST Problem using ClearSpeed Hassan AL-Maksousy halmakso@kent.edu

2
2 Graph used for Data Structure Figure 6 in [Potter, Baker, et. al.] a bc d e f 8 9 6 3 3 4 7 2

3
3 Data Structure for MST Algorithm

4
4 Graph used for Data Structure Figure 6 in [Potter, Baker, et. al.] a bc d e f 8 9 6 3 3 4 7 2

5
5 Data Structure for MST Algorithm

6
6 Graph used for Data Structure Figure 6 in [Potter, Baker, et. al.] a bc d e f 8 9 6 3 3 4 7 2

7
7 Graph used for Data Structure Figure 6 in [Potter, Baker, et. al.] a bc d e f 8 9 6 3 3 4 7 2

8
8 Data Structure for MST Algorithm

9
9 Graph used for Data Structure Figure 6 in [Potter, Baker, et. al.] a bc d e f 8 9 6 3 3 4 7 2

10
10 Graph used for Data Structure Figure 6 in [Potter, Baker, et. al.] a bc d e f 8 9 6 3 3 4 7 2

11
11 Data Structure for MST Algorithm

12
12 Graph used for Data Structure Figure 6 in [Potter, Baker, et. al.] a bc d e f 8 9 6 3 3 4 7 2

13
13 Data Structure for MST Algorithm

14
14 Graph used for Data Structure Figure 6 in [Potter, Baker, et. al.] a bc d e f 8 9 6 3 3 4 7 2

15
15 Graph used for Data Structure Figure 6 in [Potter, Baker, et. al.] a bc d e f 8 9 6 3 3 4 7 2

16
16 Data Structure for MST Algorithm c9

17
17 Graph used for Data Structure Figure 6 in [Potter, Baker, et. al.] a bc d e f 8 9 6 3 3 4 7 2

18
18 Short Version of Algorithm: ASC-MST-PRIM(root) 1.Initialize candidates to “waiting” 2.If there are any finite values in root’s field, 3. set candidate$ to “yes” 4. set parent$ to root 5. set current_best$ to the values in root’s field 6. set root’s candidate field to “no” 7.Loop while some candidate$ contain “yes” 8. for them 9. restrict mask$ to mindex(current_best$) 10. set next_node to a node identified in the preceding step 11. set its candidate to “no” 12. if the value in their next_node’s field are less than current_best$, then 13. set current_best$ to value in next_node’s field 14. set parent$ to next_node 15. if candidate$ is “waiting” and the value in its next_node’s field is finite 16. set candidate$ to “yes” 17. set parent$ to next_node 18. set current_best to the values in next_node’s field

19
19 Algorithm: ASC-MST-PRIM Initially assign any node to root. All processors set –candidate$ to “wait” –current-best$ to –the candidate field for the root node to “no” All processors whose distance d from their node to root node is finite do –Set their candidate$ field to “yes –Set their parent$ field to root. –Set current_best$ = d.

20
20 Algorithm: ASC-MST-PRIM (cont. 2/3) While the candidate field of some processor is “yes”, –Restrict the active processors to those whose candidate field is “yes” and (for these processors) do Compute the minimum value x of current_best$. Restrict the active processors to those with current_best$ = x and do –pick an active processor, say node y. »Set the candidate$ value of node y to “no” –Set the scalar variable next-node to y.

21
21 Algorithm: ASC-MST-PRIM (cont. 3/3) –If the value z in the next_node column of a processor is less than its current_best$ value, then »Set current_best$ to z. »Set parent$ to next_node –For all processors, if candidate$ is “waiting” and the distance of its node from next_node y is finite, then Set candidate$ to “yes” Set current_best$ to the distance of its node from y. Set parent$ to y

22
22 MST in Cn By Hassan AL-Maksousy //---------------------------------------------------------- // mst.cn // by Hassan AL-Maksousy // 2012-02-02 //---------------------------------------------------------- #include #include "asc.h" struct nodes { char nodeId; char candidate; int nodeArray[6]; int current_best; int parent; }; //---------------------------------------------------------- void initialize(poly struct nodes* node) { poly int i; //Initialize candidates to 'waiting' (*node).candidate = 'w'; (*node).parent = -1; //All active processor set current_best to infinit (*node).current_best = 32; for(i=0;i<6;i++) { (*node).nodeArray[i]=32; } if (get_penum() == 0) { (*node).nodeId = 'a'; (*node).nodeArray[1] = 2; (*node).nodeArray[2] = 8; } if (get_penum() == 1) { (*node).nodeId = 'b'; (*node).nodeArray[0] = 2; (*node).nodeArray[2] = 7; (*node).nodeArray[3] = 4; (*node).nodeArray[4] = 3; } if (get_penum() == 2) { (*node).nodeId = 'c';

23
23 (*node).nodeArray[0] = 8; (*node).nodeArray[1] = 7; (*node).nodeArray[4] = 6; (*node).nodeArray[5] = 9; } if (get_penum() == 3) { (*node).nodeId = 'd'; (*node).nodeArray[1] = 4; (*node).nodeArray[4] = 3; } if (get_penum() == 4) { (*node).nodeId = 'e'; (*node).nodeArray[1] = 3; (*node).nodeArray[2] = 6; (*node).nodeArray[3] = 3; } if (get_penum() == 5) { (*node).nodeId = 'f'; (*node).nodeArray[2] = 9; } } //initilize //---------------------------------------------------------- void showNodes(poly struct nodes node) { poly char letter[7]={' ','a','b','c','d','e','f'}; //Print nodeID, candidate, parent, and current best //distance. printfp("Node %c: Candidate %c, Parent: %c, Current Best: %d\n", node.nodeId, node.candidate, letter[node.parent+1], ((node.current_best < 32) ? node.current_best : 0) ); printf("\n"); } //End of showNodes(poly struct nodes) //---------------------------------------------------------- int main() { poly int mask = 0; //Initially assign any node to root. poly int root = 0; // we choose the root here // a poly int minimum = 0; MST in Cn By Hassan AL-Maksousy

24
24 poly struct nodes node; poly int nextNode; int control=0; int i; poly int minCpu=100; poly char letter[6]={'a','b','c','d','e','f'}; if ( get_penum() < 6 ) { //All processors set //candidate$ to 'wait' //current-best$ to infinit initialize(&node); showNodes(node); //the candidate field for the root node to 'no' if (get_penum() == root) { node.candidate = 'n'; control+=1; printfp("Root = %c\n", letter[root]); } // All processors whose distance d from their node to //root node is finite do if ((node.nodeArray[root] >= 0)&& (node.nodeArray[root] != 32)) { //Set their candidate$ field to 'yes' node.candidate = 'y'; //Set their parent$ field to root. node.parent = root; //Set current_best$ = d node.current_best=node.nodeArray[root]; } //While the candidate field of some processor is 'yes' while (control < 6 ) { //Restrict the active processors to those whose //candidate field //is 'yes' and (for these processors) do if (node.candidate == 'y') { mask = 1; //Compute the minimum value x of current_best$. minimum = min_int(node.current_best); } MST in Cn By Hassan AL-Maksousy

25
25 nextNode = -1; showNodes(node); //Restrict the active processors to those with //current_best$ = x and do if ((mask == 1) && (minimum == node.current_best)) { minCpu=get_penum(); minCpu=min_int(minCpu); } //pick an active processor, say node y if ( minCpu == get_penum()) { //Set the candidate$ value of node y to 'no' node.candidate = 'n'; control+=1; nextNode = get_penum(); printfp("Next Node = %c\n", letter[nextNode]); } // save nextNode value to all processor nextNode = max_int(nextNode); if(node.candidate != 'n') { //If the value z in the next_node column of a //processor is less than //its current_best$ value, then if (node.nodeArray[nextNode] < node.current_best) { //Set current_best$ to z. node.current_best = node.nodeArray[nextNode]; //Set parent$ to next_node node.parent = nextNode; } //For all processors, if candidate$ is "waiting" and //the distance of its //node from next_node y is finite, then if ((node.nodeArray[nextNode] < 32) && (node.candidate == 'w')) { //Set candidate$ to "yes" node.candidate = 'y'; MST in Cn By Hassan AL-Maksousy

26
26 //Set current_best$ to the distance of its node from y. node.current_best = node.nodeArray[nextNode]; //Set parent$ to y. node.parent = nextNode; } } // endif 'n' mask = 0; minCpu = 100 ; } //end while showNodes(node); printf ("End of program \n"); }//endif get_penum() } //main // Compiling and running the program -bash-3.00$ csreset -bash-3.00$ cscn asc.cn mst.cn -bash-3.00$ csrun a.csx Node a: Candidate w, Parent:, Current Best: 0 Node b: Candidate w, Parent:, Current Best: 0 Node c: Candidate w, Parent:, Current Best: 0 Node d: Candidate w, Parent:, Current Best: 0 Node e: Candidate w, Parent:, Current Best: 0 Node f: Candidate w, Parent:, Current Best: 0 Root = a Node a: Candidate n, Parent:, Current Best: 0 Node b: Candidate y, Parent: a, Current Best: 2 Node c: Candidate y, Parent: a, Current Best: 8 Node d: Candidate w, Parent:, Current Best: 0 Node e: Candidate w, Parent:, Current Best: 0 Node f: Candidate w, Parent:, Current Best: 0 Next Node = b Node a: Candidate n, Parent:, Current Best: 0 Node b: Candidate n, Parent: a, Current Best: 2 Node c: Candidate y, Parent: b, Current Best: 7 Node d: Candidate y, Parent: b, Current Best: 4 Node e: Candidate y, Parent: b, Current Best: 3 Node f: Candidate w, Parent:, Current Best: 0 MST in Cn By Hassan AL-Maksousy

27
27 Next Node = e Node a: Candidate n, Parent:, Current Best: 0 Node b: Candidate n, Parent: a, Current Best: 2 Node c: Candidate y, Parent: e, Current Best: 6 Node d: Candidate y, Parent: e, Current Best: 3 Node e: Candidate n, Parent: b, Current Best: 3 Node f: Candidate w, Parent:, Current Best: 0 Next Node = d Node a: Candidate n, Parent:, Current Best: 0 Node b: Candidate n, Parent: a, Current Best: 2 Node c: Candidate y, Parent: e, Current Best: 6 Node d: Candidate n, Parent: e, Current Best: 3 Node e: Candidate n, Parent: b, Current Best: 3 Node f: Candidate w, Parent:, Current Best: 0 Next Node = c Node a: Candidate n, Parent:, Current Best: 0 Node b: Candidate n, Parent: a, Current Best: 2 Node c: Candidate n, Parent: e, Current Best: 6 Node d: Candidate n, Parent: e, Current Best: 3 Node e: Candidate n, Parent: b, Current Best: 3 Node f: Candidate y, Parent: c, Current Best: 9 Next Node = f Node a: Candidate n, Parent:, Current Best: 0 Node b: Candidate n, Parent: a, Current Best: 2 Node c: Candidate n, Parent: e, Current Best: 6 Node d: Candidate n, Parent: e, Current Best: 3 Node e: Candidate n, Parent: b, Current Best: 3 Node f: Candidate n, Parent: c, Current Best: 9 End of program MST in Cn By Hassan AL-Maksousy

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google