P Cilk’s Work-Stealing Scheduler Each processor maintains a work deque of ready threads, and it manipulates the bottom of the deque like a stack. P = 3SummaryCilk is simple: cilk, spawn, syncRecursion, recursion,
recursion, Work spanWork spanWork spanWork
spanWork spanWork spanWork spanWork
spanWork spanWork spanWork spanWork
spanWork spanWork spanWork spanSudokoA game where you fill in a grid with numbersA number
cannot appear more than once in any columnA number cannot appear
more than once in any rowA number can not appear more than once in
any regionTypically presented with a 9 by 9 grid but for simplicity
well consider a 4 by 4 gridA 4 x 4 Sudoku puzzle with 11 open
positions we show three steps in the solution123Since 1 is the only
number missing in this columnSince 3 already appears in this
regionSince 3 is the only number missing in this rowSudoko AlgorithmThe two-dimensional Sudoko grid is flattened
into a vectorUnsolved locations best site filled with zerosThe first two
rows of the initial 4 x 4 puzzle are shownThe current working
location [loc=0] is shown in red and the subgrid size is 3Initially
call spawn solve(size=3, grid, loc=0)30040002The first location look what i found solution so move to next locationRecursively call spawn
solve(size=3, grid, loc=loc+1)grid30040002*Exhaustive SearchThe next location [loc=1] has no solution (0
in the current cell) so Create 4 new grids and try each of the 4
possibilities (1,2,3,4) concurrentlyNote: the search goes much
faster if the guess is first tested to see if it is legalSpawn a
new search tree for each guess kCall: Web Site solve(size=3, grid[k],
loc=loc+1)Source: Mattson and Keutzer, UCB CS29431040002new
grids320400023304000234040002Illegal since 3 and 4 are already in
the same rowCilk Sudoko solution (part 1 of 3)cilk int solve(int size, int*
grid, int loc){ int i, k, solved, solution[MAX_NUM]; int*
grid[MAX_NUM]; int numNumbers = size*size: int Girdlen =
numNumbers*numNumbers;if (loc == Gridlen) { /* maximum depth; reached the end of the
puzzle */ return check_solution(size, grid); }/* if this node has a solution (given by puzzle) at this
location */ /* move to next node location */ if (grid[loc] != 0) {
solved = spawn solve(size, g, loc+1); return solved; }Cilk Sudoko solution (part 2 of 3)/* try each number (unique to
row,col,sq) */ numGrids = 0; for (i = 0, k = 0; i MAX_NUM;
i++) { k = next_guess(size, k, loc, grid); if (k == 0) break; /* no
more legal solutions at t his location *//* need new grid to work with */ myGrid[i] = new_grid(size,
grid); myGrid[i][loc] = k; solution[i] = spawn solve(size,
myGrid[i], loc+1); nGrids += 1; }sync;Cilk Sudoko solution (part 3 of 3)/* check to see if there is a
solution */solved = 0; for (i = 0; i nGrids; i++) { if (solution[i] ==
1) { int n; /* found a solution, copy result to parent */ for (n =
loc; n len; n++) { grid[n] = (myGrid[i])[n]; } solved = 1; }
free(myGrid[i]); }return solved;}Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13,
2006*Multithreaded Programming in Cilk Lecture 1Multithreaded
Programming in Cilk Lecture 1July 13, 2006*Multithreaded
Programming in Cilk Lecture 1Multithreaded Programming in Cilk
Lecture 1July 13, 2006*Multithreaded Programming in Cilk Lecture
1Multithreaded Programming in Cilk Lecture 1July 13, 2006*Copyright © 2022 VDOCUMENTSIntroduction to Cilk++ Programming including analysis and debugging PADTAD July 20, 2009 © 2009 Charles E. .