Research Article

Parallel Implementations of Candidate Solution Evaluation Algorithm for N-Queens Problem

Algorithm 6

Calculation of conflicts with the Fork_Join framework.
Input:
Output:
(1)start 0
(2)end N-2
(3)if end–start < threshold;//calculate small task directly
(4)then
(5)  Fori = start; i ¡ = end; ++ido
(6)   Forj = i + 1; j ¡ N; ++jdo
(7)    if = = j–i then
(8)     conflicts++
(9)   end
(10)  end
(11)end
(12)else
(13) middle (start + end)/2; //large task need to be splited
(14) leftTask new CountTask(start, middle); //generate sub_task_1
(15) rightTask new CountTask(middle+1,end); //generate sub_task_2
(16) leftTask.fork(); //submit sub_task_1
(17) rightTask.fork(); //submit sub_task_2
(18) leftResult leftTask.join(); //wait for sub_task_1
(19) rightResult rightTask.join(); //wait for sub_task_2
(20) conflicts leftResult + rightResult; //merge subtask results
(21)end