Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tasks/guseva_a_matrix_sums/common/include/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <cstdint>
#include <string>
#include <tuple>
#include <vector>

#include "task/include/task.hpp"

namespace guseva_a_matrix_sums {

constexpr double kEpsilon = 10e-12;
using InType = std::tuple<uint32_t, uint32_t, std::vector<double>>;
using OutType = std::vector<double>;
using TestType = std::string;
using BaseTask = ppc::task::Task<InType, OutType>;

} // namespace guseva_a_matrix_sums
3 changes: 3 additions & 0 deletions tasks/guseva_a_matrix_sums/data/cases/test1.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tasks/guseva_a_matrix_sums/data/cases/test10.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tasks/guseva_a_matrix_sums/data/cases/test2.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tasks/guseva_a_matrix_sums/data/cases/test3.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tasks/guseva_a_matrix_sums/data/cases/test4.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tasks/guseva_a_matrix_sums/data/cases/test5.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tasks/guseva_a_matrix_sums/data/cases/test6.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tasks/guseva_a_matrix_sums/data/cases/test7.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tasks/guseva_a_matrix_sums/data/cases/test8.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tasks/guseva_a_matrix_sums/data/cases/test9.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tasks/guseva_a_matrix_sums/data/expected/test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
101
1194 1118 272 81 595 -741 -466 706 704 -324 432 343 -388 193 -578 -175 885 188 -63 155 -1625 479 170 -258 264 -293 68 -462 -187 60 -1399 412 -1017 -293 612 315 21 172 -229 1154 886 54 132 120 425 79 -291 1123 316 -237 -1287 -743 -997 -600 695 578 -306 -1059 1291 -428 -368 412 -376 625 28 57 827 -397 -273 682 -123 -434 246 -133 -125 122 161 -313 177 472 361 1594 261 -158 -646 31 -351 -88 -1839 381 -105 -99 277 -360 -421 -160 655 432 -217 -492 1310
2 changes: 2 additions & 0 deletions tasks/guseva_a_matrix_sums/data/expected/test10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
103
336 135 -34 -1395 390 1252 -289 -458 -1185 643 -327 -363 -801 -744 -299 413 1133 -334 412 350 -321 -98 -1631 819 -421 662 966 -917 787 -1398 -432 -123 -531 -1076 -836 -172 138 -203 606 451 -51 52 246 754 -534 817 -230 347 -1130 -284 764 522 757 437 39 296 1114 -204 -1099 -776 -1278 756 136 374 -1248 -781 12 799 -152 373 -838 -1661 -23 417 -870 -586 396 690 -59 292 -109 -319 -323 1277 -93 -72 -156 1032 993 1214 -322 -212 633 1328 123 -141 554 -327 -64 1065 -513 -1211 774
2 changes: 2 additions & 0 deletions tasks/guseva_a_matrix_sums/data/expected/test2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
138
170 -466 486 316 44 230 666 -598 400 354 154 -120 273 218 597 398 454 -486 203 -173 1223 545 580 -124 -519 -85 -132 577 57 -301 -417 -169 -591 684 232 646 -314 186 -225 -354 -173 596 797 -193 200 -2 -759 -78 747 673 845 -990 -3 908 929 -317 164 27 -381 264 -238 -272 -32 -588 -236 268 317 -325 -586 611 -415 1192 -17 -592 -429 -45 -432 -713 421 -947 -422 55 377 -252 -959 -179 -628 590 -609 -363 173 796 -215 20 1107 -619 -159 -494 -313 -343 -1400 1005 -322 317 605 229 1201 764 602 -268 -801 -281 -26 342 731 -670 1317 201 -350 -193 -1097 -390 466 -321 76 372 1062 25 -1123 295 -1554 -395 -1083 -910 1301 -459 -277 177
2 changes: 2 additions & 0 deletions tasks/guseva_a_matrix_sums/data/expected/test3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
154
600 -57 -689 -96 -585 1 -221 -131 1980 2011 -844 -28 -373 95 241 787 -714 202 332 888 -863 -1093 530 -1347 -87 513 -487 -491 -314 1027 30 267 379 305 368 -1064 -92 276 746 742 -1210 -107 273 -35 -249 691 -418 440 -205 10 -45 318 123 -1489 232 589 -445 -45 -131 -11 -505 446 718 -239 -387 726 1319 -614 -92 282 148 -1478 -285 -588 66 3 -738 -604 -34 560 -639 50 462 -32 -258 -173 347 128 605 97 -1045 249 239 97 -154 -221 -422 -2096 -281 277 541 426 -228 -369 -1745 -857 -542 -734 447 -121 174 -402 -45 -641 -52 -347 -271 824 -2 -330 141 -563 1356 -40 -1042 -1472 328 -186 234 702 -184 251 939 -254 219 -47 -96 499 -287 -1171 139 532 -134 441 -2597 -479 -791 191 485 248 -967 1099 -1100 -51
2 changes: 2 additions & 0 deletions tasks/guseva_a_matrix_sums/data/expected/test4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
197
650 -674 -68 787 -507 861 136 1592 -165 -446 214 -1137 995 -1184 -653 17 18 387 383 495 964 831 450 -311 -452 -197 -937 -186 -646 -509 -348 1172 686 735 -951 817 -332 305 -739 -773 -632 530 -528 -26 864 614 679 -267 -670 -588 407 244 746 1529 -169 -16 -230 -392 116 -790 -359 -1265 192 -1447 1164 1459 -373 596 -821 507 -1283 -244 -353 7 786 -320 -752 -537 1095 -67 -1017 573 473 662 428 25 -530 -738 1016 -170 706 -186 -69 1387 -73 184 465 -436 888 163 -560 -969 9 1369 258 1139 814 -105 -1043 704 -758 1075 -1029 -941 298 1080 722 747 -937 -127 -873 -678 614 516 -933 864 -187 -511 -289 -64 251 -53 -170 534 -1139 -211 476 -506 356 37 54 1417 -507 -542 812 -271 502 -762 -1613 403 1138 381 -58 716 246 -1571 -325 -225 105 -896 -700 356 617 826 326 -314 -425 265 -263 1332 -912 -276 651 16 1464 -996 711 -1093 1604 -235 673 1602 -813 -692 164 -31 313 580 -299 873 -541 341 -337 -1005 2035 -68 60
2 changes: 2 additions & 0 deletions tasks/guseva_a_matrix_sums/data/expected/test5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
148
76 211 71 220 483 396 -1549 -299 -1276 678 -560 -849 488 -505 -383 -42 -211 619 421 -173 -244 392 -180 456 773 246 -231 968 39 41 -174 -299 293 -860 -418 -290 -35 220 319 1043 -116 -58 327 -669 15 303 -644 -226 -98 -142 633 257 339 326 -1263 17 423 540 270 -614 -706 -464 -314 -71 617 -20 31 -362 59 270 -452 25 -232 -151 208 652 1166 661 566 -67 741 -230 -43 -261 -1030 -204 285 -311 25 -372 -721 -155 479 -1087 -910 318 -1103 -79 -302 -256 202 258 -260 534 -400 65 -505 -675 -484 -712 417 -729 669 -634 657 -606 103 243 946 79 307 46 -258 -527 155 -1008 -42 262 -215 -120 -93 -306 -239 -281 389 -42 189 261 246 -152 273 -568 55 124 400 639 764 50
2 changes: 2 additions & 0 deletions tasks/guseva_a_matrix_sums/data/expected/test6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
171
1531 -741 368 114 -1094 -252 1054 1163 1344 -1648 -410 727 1179 -524 1005 613 -1095 403 -104 178 -634 312 294 -14 116 -279 -395 122 -705 -123 -451 -804 -101 -1242 229 -383 -192 591 -735 287 545 534 250 -435 -690 161 93 -355 891 -1040 -252 -893 372 772 -639 -390 -1580 -155 -347 -353 298 -191 608 234 -966 -462 573 443 -889 405 1321 316 -744 233 -2234 -34 1088 1525 -312 137 380 -599 -231 891 -863 612 -234 363 1110 -197 253 1156 517 113 -255 67 402 -579 -104 -1073 835 -449 -34 -309 -955 -665 -996 -408 229 285 -235 412 112 -181 -38 -33 -1077 1597 1157 569 562 964 78 -159 -640 539 261 -774 -742 502 261 -27 -604 22 837 271 -205 -237 -302 211 -834 942 -33 -223 106 21 -488 -541 -221 -181 410 780 -317 -201 1060 -782 45 875 894 -182 -1186 -301 -514 551 -244 -135 -1311 718 -731 244 22
2 changes: 2 additions & 0 deletions tasks/guseva_a_matrix_sums/data/expected/test7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
190
-219 -108 -989 -412 -804 858 -235 -734 571 635 -1046 -532 522 -290 687 197 -348 536 -352 -191 -119 871 -140 119 237 103 97 -234 837 964 594 309 -451 -447 -609 336 58 -146 -240 -25 -93 -206 -197 263 -132 -1494 725 -1652 -817 -781 -1536 147 -220 17 280 -735 138 -584 172 -383 267 67 507 1064 691 1033 364 -391 241 310 -1838 581 -139 -125 192 -226 732 355 -357 908 -794 1016 56 424 -46 -243 485 -177 -594 7 776 819 -897 889 -576 740 -85 -1280 1025 9 -1202 139 -683 1231 -1298 -466 -369 -136 529 245 -82 -290 122 265 -233 -44 1473 -1053 -4 288 -194 873 -96 -914 431 -9 878 491 -140 922 551 168 50 -137 207 856 -246 -202 146 -91 -160 562 744 208 276 1159 -745 380 -570 -517 606 -412 337 -643 -153 -282 327 -336 -297 -211 576 1199 -53 -471 -111 -862 421 -1104 -309 535 765 -1055 727 -346 1427 1492 700 -299 673 -794 566 -824 -231 -34 1207 486 566 -1022 375 -720
2 changes: 2 additions & 0 deletions tasks/guseva_a_matrix_sums/data/expected/test8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
173
-640 584 -28 -469 647 -259 1005 -96 -1072 -749 86 979 -1469 -759 -1538 549 660 1141 29 268 793 -844 359 655 -308 51 281 -1075 -445 -771 -17 -523 -244 -72 -10 -14 594 -1313 -168 91 665 270 -757 360 -104 205 784 -692 21 -647 -14 543 -582 -990 341 -181 -74 1345 -1599 -1077 826 -652 -114 -56 1250 908 224 1323 -1609 70 21 -122 -471 34 917 800 -1327 -1103 957 334 -59 937 -279 464 -723 1243 -710 -821 -1400 -747 -911 841 414 63 1259 -407 -520 758 854 -962 -246 -168 -480 287 -227 -729 34 1601 682 326 -16 771 993 -1090 -235 -211 1510 -512 898 267 380 946 389 569 886 -291 -475 395 733 -561 -796 821 -516 -691 1065 723 494 797 589 -50 939 560 -493 -818 -122 -347 -100 2352 385 1558 -90 -124 -1442 924 -349 -117 592 553 -30 422 -262 -891 98 -272 792 -3 -265 988 168 -803 1293 560 330
2 changes: 2 additions & 0 deletions tasks/guseva_a_matrix_sums/data/expected/test9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
196
-255 191 964 -15 -323 773 410 -441 -340 119 -10 -298 266 -90 363 869 302 -749 -13 446 -527 -511 51 -812 168 -534 -1388 -332 -932 1687 -1497 -24 -725 59 135 -449 -1733 -295 36 -38 704 915 -404 162 98 644 -840 -598 263 45 492 -184 290 -831 1016 -590 -150 288 400 565 -233 -339 1078 1219 416 -125 -858 103 -515 433 -315 192 917 685 263 -1091 676 113 -98 -1571 542 316 -499 172 583 -556 -399 799 1267 1033 -102 200 -198 741 -655 300 184 605 706 14 304 109 -723 -286 -596 588 15 253 -361 -998 -694 24 -1172 788 -216 1552 -1325 520 -233 304 306 475 -405 1372 1239 -38 -278 350 -272 -244 158 205 -217 -184 -1234 -414 1443 174 -676 350 -1221 -227 197 247 515 -189 -683 1207 -868 -410 -1339 401 901 -691 -1394 389 527 -414 785 -37 -304 1003 942 -601 -85 -31 -212 401 629 -504 95 1446 -821 -907 584 -57 949 780 -567 694 -763 -323 -802 791 155 85 -1046 1130 -237 81 623 -510 -367 -212 -196 -583
2 changes: 2 additions & 0 deletions tasks/guseva_a_matrix_sums/data/perf/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1000
8390 4942 5060 11684 4524 -2254 1969 2290 5398 -3332 777 3502 -2936 3619 -11562 -6713 -7093 -10547 -1589 2679 -1752 -3424 -3250 5620 -1454 -8252 -8884 1065 4957 -3802 5285 -7530 -8856 -5063 -7197 6272 2854 1798 1556 502 655 5335 998 4609 4452 2437 -13285 -2344 -12377 -596 -2634 -14636 1193 978 712 8428 3256 -10409 5487 -126 -1457 -3336 6710 -13027 2673 -616 -7683 509 -4245 -2536 344 4554 5620 97 -2399 2691 -9154 6788 1670 -6976 -4264 5225 -6703 5841 8013 -3627 -405 -3596 -1114 -933 1292 2000 564 -11649 222 -13195 2451 -85 8832 -6392 2422 3249 5300 6348 15422 9138 4650 -1524 12138 -2589 8790 1200 -3851 -3788 -5272 2144 -1790 9732 -5364 -1187 -1859 4430 5809 -2583 -3120 7364 463 -16773 -7846 -3422 -3310 -10932 -572 -4295 2784 1510 -2739 4429 11980 327 7824 -1736 13134 -461 -653 5783 -2616 368 -11782 -3070 -4700 4918 -4916 9183 -5411 -2936 5279 -5540 9311 -5813 -8784 -12648 -3015 4934 -13161 242 -19875 2276 -7959 4351 2323 5058 7832 -1942 3768 8655 -12373 -1404 -3569 -3777 8249 4068 4914 1652 1842 1717 523 -1814 9925 -3268 -5313 4948 -3021 7543 -3113 2604 2290 -2888 -10782 182 1733 -12684 554 10104 -5835 6012 -3513 4886 -7515 -303 3280 1712 10575 -12059 12066 -12120 -7900 -6217 12273 -3070 2862 -2721 -448 2105 2589 2500 5329 -7249 2518 -3820 10278 9173 6349 926 -1657 4075 -4067 7600 -4510 8586 -3650 3279 2823 5530 2960 -5289 8854 2324 586 3745 -4956 4566 3150 -5209 -5356 -287 6233 2697 -1408 -5096 -3605 -8462 1391 3309 1795 2434 543 3341 -901 10131 9486 6541 -8923 -7232 -3728 1088 -1526 -10864 4079 -10738 -10954 2605 -926 -9824 5281 6262 -787 -6550 -9132 1113 -5356 4654 959 4133 4994 -4388 5784 82 8358 10402 4620 -866 -3646 -8457 3106 5419 6795 310 -3578 -2798 -4599 -2465 -5526 286 -2826 -5833 -2207 -15060 -7207 -1156 321 5381 1649 -2186 2317 341 6225 -5056 7306 -1693 4690 4452 4260 1495 -6395 9799 -6860 8364 -1136 4172 369 11607 -3550 -2082 1398 -5937 -3808 -2100 -3942 2464 4085 350 5013 -806 6819 4194 882 -3601 4416 3699 -1299 2161 -476 5833 -803 -1128 918 7543 10713 -7168 606 5489 -6979 -3413 -5233 962 -446 8745 7786 3826 -11947 5481 758 6680 6939 -5207 10075 -8516 -1267 9063 -1762 2976 -915 5477 -1484 4207 -405 2229 8283 -7165 -6987 -6628 -12724 -444 6179 -502 -3201 -4618 -4494 7125 -1420 -9814 -39 1174 -4627 6555 6122 1109 9911 164 283 9507 -6557 -1896 4266 -2712 -7130 1500 -1992 5580 310 12892 -2102 -5092 8693 339 -244 2493 4855 -4200 -1989 -4468 229 3649 -3255 -5475 -4224 4602 -10373 4648 -3343 6757 4368 -7542 15048 -2673 -221 15367 8238 8637 5701 -2912 7337 2982 6856 -5811 9029 -7769 -3248 4780 491 2947 -3284 1656 9697 -4341 -5232 -337 -12050 3306 6269 4773 9426 -5989 -6712 6155 -4053 9785 -7472 1860 -4554 -3134 -8475 5010 -5622 -2655 2385 -10945 3927 -5725 -1429 -5602 5180 -1060 4983 5898 -1521 -7270 5015 140 -7136 1405 14011 -8853 -6157 3468 -564 -2655 -2071 2060 4410 10740 -4845 234 4305 1692 1014 -5101 -1601 -3997 8429 11558 5306 -2954 -3512 -7975 -478 1205 5246 10441 8232 -1298 270 -5497 7623 -4150 -507 -2040 -287 10114 2090 7730 -15723 -5132 -9032 859 10339 4795 -2787 -2766 -5320 -1122 -7041 656 -2616 9292 3554 -6602 -214 -1046 2906 -1823 -1379 -4719 -3400 205 1317 -313 -8482 -1855 5339 1282 1667 -10287 7591 -4909 -902 -6415 5377 -1008 -963 2683 -6860 -2325 -1605 8694 -5521 651 2771 6004 -6210 -1607 5225 1014 443 -6424 -2871 -2375 -6213 9422 3866 5565 -1014 5796 2315 230 -3442 1921 4598 -1424 -611 6062 3153 -252 -7994 -2088 -6083 -5346 -9888 -2401 1383 -3184 479 8317 -4979 6666 -4153 -1175 1860 -3840 4715 -9693 -1895 -3934 -919 6453 5332 4152 3617 -3182 -6624 4240 -8411 2639 6589 4594 -322 4269 -5909 -12064 3467 568 -7904 -6957 4703 -965 4492 -6362 5807 8562 3684 2189 -2654 -4953 -1915 4417 565 6160 579 3240 -4521 925 -1703 4345 -3288 2921 7232 -8820 8518 -5992 1681 9153 7634 -3517 2381 1893 -6502 -2099 1843 -6734 209 -3095 4070 4206 -1369 -2846 -2729 8624 1909 -7360 -12978 -924 1081 -7233 2411 947 12082 749 5590 2406 -1752 935 7995 -5877 -13997 -833 4364 -2104 1645 -11938 1827 -902 5139 4564 -2683 8537 13529 -3902 -776 -2853 7203 -5714 -2756 3218 -11296 4196 11226 -9414 -5368 5920 9527 -777 4822 1714 -6258 -12184 -8981 2347 13238 8238 5963 -1758 138 5567 -901 -3454 3447 -14837 10687 -3952 4031 62 -6859 -2118 -8000 -7961 -6456 9062 -6882 5891 -1757 2568 2264 1374 3946 -822 7509 -1843 8145 -8331 -3059 918 5777 2072 2606 6066 6683 -4802 -634 -6315 -5345 -2297 -488 4679 5080 1158 3918 -4377 -10697 1384 -8142 -7805 13709 5134 -8751 12105 -2801 -7379 -8162 -393 5130 1240 3646 6978 4876 8099 3670 -15369 -920 4817 -3538 6890 2014 607 3158 4281 2452 10209 -2088 1503 -5277 -1792 -3748 8225 1154 -1132 3754 -1388 -3685 473 5190 10699 -4501 -11440 -1352 3464 9911 -535 546 658 1874 -2732 -745 -1693 -1951 9439 5674 8619 725 11395 -7667 -3483 -5671 3876 7319 1009 -5070 -8007 -10123 1258 3762 -11952 706 2988 6154 -5053 317 -5021 -10508 -1593 3171 -5843 -723 2147 7121 2776 3923 9763 3898 -3037 5295 -1058 -5740 -2487 9172 -6684 7355 2565 3864 685 18031 6155 -5211 8297 1622 -36 1280 2991 -7724 -5843 12747 645 5019 -5800 814 -2068 4426 -4462 -2166 -748 2319 -1706 4677 -6047 875 8612 -11217 -1410 -604 3383 -5671 6420 -799 1372 -3275 5070 -1656 16982 -1010 -2347 4960 -573 819 4270 7070 -2874 -961 44 -8696 9104 3493 -12878 -3119 -8590 -2187 -6814 -20230 -8937 -371 -1318 4142 1647 6324 5765 5398 6776 3825 -9979 -571 7237 -1370 -9118 -2114 6539 -1486 -8221 7195 2597 -11131 7814 4663 5082 5925 1455 4274 -3015 3789 6443 4824 -7107
3 changes: 3 additions & 0 deletions tasks/guseva_a_matrix_sums/data/perf/input.txt

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tasks/guseva_a_matrix_sums/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"student": {
"first_name": "Алёна",
"last_name": "Гусева",
"middle_name": "Сергеевна",
"group_number": "3823Б1ФИ2",
"task_number": "1"
}
}
22 changes: 22 additions & 0 deletions tasks/guseva_a_matrix_sums/mpi/include/ops_mpi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "guseva_a_matrix_sums/common/include/common.hpp"
#include "task/include/task.hpp"

namespace guseva_a_matrix_sums {

class GusevaAMatrixSumsMPI : public BaseTask {
public:
static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() {
return ppc::task::TypeOfTask::kMPI;
}
explicit GusevaAMatrixSumsMPI(const InType &in);

private:
bool ValidationImpl() override;
bool PreProcessingImpl() override;
bool RunImpl() override;
bool PostProcessingImpl() override;
};

} // namespace guseva_a_matrix_sums
92 changes: 92 additions & 0 deletions tasks/guseva_a_matrix_sums/mpi/src/ops_mpi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "guseva_a_matrix_sums/mpi/include/ops_mpi.hpp"

#include <mpi.h>

#include <cstdint>
#include <vector>

#include "guseva_a_matrix_sums/common/include/common.hpp"

namespace guseva_a_matrix_sums {

GusevaAMatrixSumsMPI::GusevaAMatrixSumsMPI(const InType &in) {
SetTypeOfTask(GetStaticTypeOfTask());
GetInput() = in;
GetOutput() = {};
}

bool GusevaAMatrixSumsMPI::ValidationImpl() {
return (static_cast<uint64_t>(std::get<0>(GetInput())) * std::get<1>(GetInput()) == std::get<2>(GetInput()).size()) &&
(GetOutput().empty());
}

bool GusevaAMatrixSumsMPI::PreProcessingImpl() {
GetOutput().clear();
return true;
}

bool GusevaAMatrixSumsMPI::RunImpl() {
int rank = 0;
int wsize = 0;

MPI_Comm_size(MPI_COMM_WORLD, &wsize);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

int rows = static_cast<int>(std::get<0>(GetInput()));
int columns = static_cast<int>(std::get<1>(GetInput()));

MPI_Bcast(&rows, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(&columns, 1, MPI_INT, 0, MPI_COMM_WORLD);
int size = rows * columns;

int elems_per_proc = size / wsize;
int remainder = size % wsize;

std::vector<int> counts(wsize, 0);
std::vector<int> displs(wsize, 0);

int displ = 0;
int shift = 0;
int total = 0;

for (int proc = 0; proc < wsize; proc++) {
counts[proc] = elems_per_proc + (proc < remainder ? 1 : 0);
displs[proc] = displ;
displ += counts[proc];
if (rank == proc) {
shift = total % columns;
}
total += counts[proc];
}

std::vector<double> matrix(size, 0);

if (rank == 0) {
matrix = std::get<2>(GetInput());
}

std::vector<double> local_buff(counts[rank], 0);

MPI_Scatterv(matrix.data(), counts.data(), displs.data(), MPI_DOUBLE, local_buff.data(), counts[rank], MPI_DOUBLE, 0,
MPI_COMM_WORLD);

std::vector<double> local_sums(columns, 0.0);

for (int i = 0; i < counts[rank]; i++) {
local_sums[(i + shift) % columns] += local_buff[i];
}

if (rank == 0) {
GetOutput().resize(columns, 0.0);
}

MPI_Reduce(local_sums.data(), GetOutput().data(), columns, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);

return true;
}

bool GusevaAMatrixSumsMPI::PostProcessingImpl() {
return true;
}

} // namespace guseva_a_matrix_sums
Loading
Loading