27
1 An Associative Program for the MST Problem using ClearSpeed Hassan AL-Maksousy [email protected]

An Associative Program for the MST Problem using ClearSpeed

  • Upload
    kalli

  • View
    21

  • Download
    0

Embed Size (px)

DESCRIPTION

An Associative Program for the MST Problem using ClearSpeed. Hassan AL- Maksousy [email protected]. a. 2. 8. 7. b. c. 4. 3. 9. 6. e. d. 3. f. Graph used for Data Structure. Figure 6 in [Potter, Baker, et. al.]. current_best$. candidate$. node$. parent$. mask$. PEs. d$. - PowerPoint PPT Presentation

Citation preview

Page 1: An Associative Program for the MST Problem using  ClearSpeed

1

An Associative Program for the MST Problem using ClearSpeed

Hassan [email protected]

Page 2: An Associative Program for the MST Problem using  ClearSpeed

2

Graph used for Data Structure

Figure 6 in [Potter, Baker, et. al.]

a

b c

d ef

8

96

3

3

4

7

2

Page 3: An Associative Program for the MST Problem using  ClearSpeed

3

Data Structure for MST Algorithm

curr

ent_

best

$

cand

idat

e$

next-node

a

IS

∞∞∞9∞∞f

∞∞363∞e

∞3∞∞4∞d

96∞∞78 c

∞347∞2b

∞∞∞82∞aP

Es

mas

k$

node

$

a$ b$ pare

nt$

rootc$ d$ e$ f$

Page 4: An Associative Program for the MST Problem using  ClearSpeed

4

Graph used for Data Structure

Figure 6 in [Potter, Baker, et. al.]

a

b c

d ef

8

96

3

3

4

7

2

Page 5: An Associative Program for the MST Problem using  ClearSpeed

5

Data Structure for MST Algorithm

curr

ent_

best

$

cand

idat

e$

next-node b

a

IS

wait∞∞∞9∞∞f

wait∞∞363∞e

wait∞3∞∞4∞d

8ayes96∞∞78 c

2ayes∞347∞2b

no∞∞∞82∞aP

Es

mas

k$

node

$

a$ b$ pare

nt$

rootc$ d$ e$ f$

Page 6: An Associative Program for the MST Problem using  ClearSpeed

6

Graph used for Data Structure

Figure 6 in [Potter, Baker, et. al.]

a

b c

d ef

8

96

3

3

4

7

2

Page 7: An Associative Program for the MST Problem using  ClearSpeed

7

Graph used for Data Structure

Figure 6 in [Potter, Baker, et. al.]

a

b c

d ef

8

96

3

3

4

7

2

Page 8: An Associative Program for the MST Problem using  ClearSpeed

8

Data Structure for MST Algorithm

curr

ent_

best

$

cand

idat

e$

next-node e

a

IS

wait∞∞∞9∞∞f

3byes∞∞363∞e

4byes∞3∞∞4∞d

7byes96∞∞78 c

2ano∞347∞2b

no∞∞∞82∞aP

Es

mas

k$

node

$

a$ b$ pare

nt$

rootc$ d$ e$ f$

Page 9: An Associative Program for the MST Problem using  ClearSpeed

9

Graph used for Data Structure

Figure 6 in [Potter, Baker, et. al.]

a

b c

d ef

8

96

3

3

4

7

2

Page 10: An Associative Program for the MST Problem using  ClearSpeed

10

Graph used for Data Structure

Figure 6 in [Potter, Baker, et. al.]

a

b c

d ef

8

96

3

3

4

7

2

Page 11: An Associative Program for the MST Problem using  ClearSpeed

11

Data Structure for MST Algorithm

curr

ent_

best

$

cand

idat

e$

next-node d

a

IS

wait∞∞∞9∞∞f

3bno∞∞363∞e

3eyes∞3∞∞4∞d

6eyes96∞∞78 c

2ano∞347∞2b

no∞∞∞82∞aP

Es

mas

k$

node

$

a$ b$ pare

nt$

rootc$ d$ e$ f$

Page 12: An Associative Program for the MST Problem using  ClearSpeed

12

Graph used for Data Structure

Figure 6 in [Potter, Baker, et. al.]

a

b c

d ef

8

96

3

3

4

7

2

Page 13: An Associative Program for the MST Problem using  ClearSpeed

13

Data Structure for MST Algorithm

curr

ent_

best

$

cand

idat

e$

next-node c

a

IS

wait∞∞∞9∞∞f

3bno∞∞363∞e

3eno∞3∞∞4∞d

6eyes96∞∞78 c

2ano∞347∞2b

no∞∞∞82∞aP

Es

mas

k$

node

$

a$ b$ pare

nt$

rootc$ d$ e$ f$

Page 14: An Associative Program for the MST Problem using  ClearSpeed

14

Graph used for Data Structure

Figure 6 in [Potter, Baker, et. al.]

a

b c

d ef

8

96

3

3

4

7

2

Page 15: An Associative Program for the MST Problem using  ClearSpeed

15

Graph used for Data Structure

Figure 6 in [Potter, Baker, et. al.]

a

b c

d ef

8

96

3

3

4

7

2

Page 16: An Associative Program for the MST Problem using  ClearSpeed

16

Data Structure for MST Algorithm

curr

ent_

best

$

cand

idat

e$

next-node f

a

IS

yes∞∞∞9∞∞f

3bno∞∞363∞e

3eno∞3∞∞4∞d

6eno96∞∞78 c

2ano∞347∞2b

no∞∞∞82∞aP

Es

mas

k$

node

$

a$ b$ pare

nt$

rootc$ d$ e$ f$

c 9

Page 17: An Associative Program for the MST Problem using  ClearSpeed

17

Graph used for Data Structure

Figure 6 in [Potter, Baker, et. al.]

a

b c

d ef

8

96

3

3

4

7

2

Page 18: An Associative Program for the MST Problem using  ClearSpeed

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

Page 19: An Associative Program for the MST Problem using  ClearSpeed

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.

Page 20: An Associative Program for the MST Problem using  ClearSpeed

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.

Page 21: An Associative Program for the MST Problem using  ClearSpeed

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

Page 22: An Associative Program for the MST Problem using  ClearSpeed

22

MST in Cn By Hassan AL-Maksousy•//----------------------------------------------------------•// mst.cn•// by Hassan AL-Maksousy•// 2012-02-02•//----------------------------------------------------------• •#include <lib_ext.h>•#include <stdiop.h>•#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';

Page 23: An Associative Program for the MST Problem using  ClearSpeed

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

Page 24: An Associative Program for the MST Problem using  ClearSpeed

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

Page 25: An Associative Program for the MST Problem using  ClearSpeed

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

Page 26: An Associative Program for the MST Problem using  ClearSpeed

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

Page 27: An Associative Program for the MST Problem using  ClearSpeed

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