Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added solution for second and third openMP task #3

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

LevchenkoDmitry
Copy link

Сделал несколько решений:

  1. calc: каждому треду выдается своя результирующая переменная, где идет суммирование, таким образом исключается race condition. В конце происходит сложение. Решение не проходит 4 тест

[TEST 00]
  ./build/task ./tests/00/input.txt ./build/00.txt
[TEST 00] OK (3 ms)

[TEST 01]
  ./build/task ./tests/01/input.txt ./build/01.txt
[TEST 01] OK (2 ms)

[TEST 02]
  ./build/task ./tests/02/input.txt ./build/02.txtvimdiff ./build/04.txt ./tests/04/output.txt
[TEST 02] OK (6 ms)

[TEST 03]
  ./build/task ./tests/03/input.txt ./build/03.txt
[TEST 03] OK (422 ms)

[TEST 04]
  ./build/task ./tests/04/input.txt ./build/04.txt
[TEST 04] DIFF FAIL: vimdiff ./build/04.txt ./tests/04/output.txt
===========
SUCCESSFUL: 00 01 02 03
FAIL: 04

calc2: решение основано на reduction, но не проходит также 4 тест. Время работы не сильно отличается от предыдущего решения, так как механизм работы +- такой же (каждому треду выдается по локальной переменной, где идет суммирование), ошибка та же самая в том же знаке после запятой.

[TEST 00] OK (2 ms)

[TEST 01]
  ./build/task ./tests/01/input.txt ./build/01.txt
[TEST 01] OK (2 ms)

[TEST 02]
  ./build/task ./tests/02/input.txt ./build/02.txt
[TEST 02] OK (6 ms)

[TEST 03]
  ./build/task ./tests/03/input.txt ./build/03.txt
[TEST 03] OK (416 ms)

[TEST 04]
  ./build/task ./tests/04/input.txt ./build/04.txt
[TEST 04] DIFF FAIL: vimdiff ./build/04.txt ./tests/04/output.txt
===========
SUCCESSFUL: 00 01 02 03
FAIL: 04

calc3: каждому элементу выдается по элементу массива, после суммируем элементы.
Решение проходит все тесты, но по 3 тесту видно, что почти в 2.5 раза медленнее предыдущих вариантов

[TEST 00]
  ./build/task ./tests/00/input.txt ./build/00.txt
[TEST 00] OK (2 ms)

[TEST 01]
  ./build/task ./tests/01/input.txt ./build/01.txt
[TEST 01] OK (2 ms)

[TEST 02]
  ./build/task ./tests/02/input.txt ./build/02.txt
[TEST 02] OK (6 ms)

[TEST 03]
  ./build/task ./tests/03/input.txt ./build/03.txt
[TEST 03] OK (1027 ms)

[TEST 04]
  ./build/task ./tests/04/input.txt ./build/04.txt
[TEST 04] OK (473 ms)
===========
SUCCESSFUL: 00 01 02 03 04
FAIL: 

@LevchenkoDmitry LevchenkoDmitry changed the title Added solution for second openMP task Added solution for second and third openMP task Oct 8, 2020
@LevchenkoDmitry
Copy link
Author

Также 2 решения к 3 задаче.
Немного оптимизировал формулу трапеций заменой sum (f(i+1)+f(i))/2 * dx на (f(0) + f(x1)) / 2 + (f(1) + ... f(x1 - 1)) * dx что исключает двойное суммирование по f(1), ..., f(x1 - 1).

calc_reduce:
[TEST 00]
./build/task ./tests/00/input.txt ./build/00.txt
[TEST 00] OK (2 ms)

[TEST 01]
./build/task ./tests/01/input.txt ./build/01.txt
[TEST 01] OK (2 ms)

[TEST 02]
./build/task ./tests/02/input.txt ./build/02.txt
[TEST 02] OK (512 ms)

[TEST 03]
./build/task ./tests/03/input.txt ./build/03.txt
[TEST 03] OK (513 ms)

[TEST 04]
./build/task ./tests/04/input.txt ./build/04.txt
[TEST 04] OK (675 ms)

[TEST 05]
./build/task ./tests/05/input.txt ./build/05.txt
[TEST 05] OK (675 ms)

[TEST 06]
./build/task ./tests/06/input.txt ./build/06.txt
[TEST 06] OK (6247 ms)

[TEST 07]
./build/task ./tests/07/input.txt ./build/07.txt
[TEST 07] OK (6230 ms)

SUCCESSFUL: 00 01 02 03 04 05 06 07
FAIL:

calc:
[TEST 00]
./build/task ./tests/00/input.txt ./build/00.txt
[TEST 00] OK (2 ms)

[TEST 01]
./build/task ./tests/01/input.txt ./build/01.txt
[TEST 01] OK (2 ms)

[TEST 02]
./build/task ./tests/02/input.txt ./build/02.txt
[TEST 02] OK (689 ms)

[TEST 03]
./build/task ./tests/03/input.txt ./build/03.txt
[TEST 03] OK (241 ms)

[TEST 04]
./build/task ./tests/04/input.txt ./build/04.txt
[TEST 04] OK (871 ms)

[TEST 05]
./build/task ./tests/05/input.txt ./build/05.txt
[TEST 05] OK (270 ms)

[TEST 06]
./build/task ./tests/06/input.txt ./build/06.txt
[TEST 06] OK (8011 ms)

[TEST 07]
./build/task ./tests/07/input.txt ./build/07.txt
[TEST 07] OK (2417 ms)

SUCCESSFUL: 00 01 02 03 04 05 06 07
FAIL:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant