مرجع:
http://people.scs.carleton.ca/~maheshwa/courses/4009COMP/outline.html
http://people.scs.carleton.ca/~maheshwa/courses/409/409.html
P1[10 Marks] Suppose a linear array consisting of n processors (labeled P_0 to P_{n-1}) contains
n natural numbers. You need to design an algorithm so that processor
P_0 outputs YES if all the input numbers are distinct, otherwise
it answers NO. Justify why your algorithm is correct, its complexity and is it optimal?
هر پردازنده عدد خود را به پردازندهی با اندیس یکی کمتر از خودش بفرستد و اگر تساوی رخ داد YES را به بعدی بفرستد. بدیهی است که در هر زمان بیش از یک عدد از یک لینک عبور نمیکند چون هر پردازنده فقط یک عدد دارد. بعد از n گام عدد پردازندهی آخر به پردازندهی اول رسیده است پس در این زمان اگر در پردازندهی اول YES داشتیم یعنی جواب yes است و در غیر این صورت no است.
Question 2 (15 Marks)
Design an algorithm for sorting N numbers on an O(log N)-processor linear array that is 100% efficient. (Assume that N/log N numbers are with each processor. Recall that efficiency is ratio of the running time of the best sequential algorithm to the work of parallel algorithm. Work of a parallel algorithm is the product of its running time and number of processors.)
جواب:
Efficiency = 1 ==> speed up = p = O(log n)
sort = O(n log n)
==> T_parallel = O(n)
اگر بخواهیم الگوریتم معمولی را با تعداد پردازندهی کمتری اجرا کنیم (طبق راهنمایی سوال) داریم:
T_sort_1_processor (serial) = O( n / log n log (n/logn) ) = O(n)
سپس روی آن الگوریتم مرتب سازی زوج و فرد را اجرا میکنیم با فرض اینکه بیش از یک عدد در هر پردازنده هست. یعنی در هر عمل ابتدا لیست دو پردازنده را ادغام میکنیم و نیمهی کمتر را به پردازنده سمت چپ و نیمهی بیشتر را به پردازندهی سمت راست میدهیم. مشابه مرتب سازی زوج و فرد این کار به تعداد پردازندهها گام نیاز دارد که O(log n) است پس کل الگوریتم O(n) میشود و بهینه است.
Question 3 ( 15 Marks) Show that sorting the rows and then the columns of a mesh leaves the rows in sorted order.