This repository has been archived on 2024-12-25. You can view files and clone it, but cannot push or open issues or pull requests.
2024-03-10 20:32:51 +03:00

35 lines
1.2 KiB
ObjectPascal
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//Демонстрация использования параллельных секций на примере задачи о ханойских башнях
// Вывод решения закомментирован, так как он занимает большую часть времени
//параллельная процедура
procedure MovePiramidParallel(n: integer; f, t, w: integer);
begin
if n = 0 then
exit;
{$omp parallel sections}
begin
MovePiramidParallel(n - 1, f, w, t);
//writelnFormat('Переложить диск с {0} на {1}', f, t);
MovePiramidParallel(n - 1, w, t, f);
end;
end;
//последовательная процедура
procedure MovePiramid(n: integer; f, t, w: integer);
begin
if n = 0 then
exit;
MovePiramid(n - 1, f, w, t);
//writelnFormat('Переложить диск с {0} на {1}', f, t);
MovePiramid(n - 1, w, t, f);
end;
begin
var m0 := Milliseconds;
MovePiramid(27, 1, 2, 3);
writeln('Последовательное выполнение: ', Milliseconds - m0, 'ms');
var m1 := Milliseconds;
MovePiramidParallel(27, 1, 2, 3);
writeln('Параллельное выполнение: ', Milliseconds - m1, 'ms');
end.