{"id":290104,"date":"2018-09-29T23:55:03","date_gmt":"2018-09-29T19:55:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=290104"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=290104","title":{"rendered":"\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u044b\u00bb \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e GPU"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u041f\u0440\u0438\u0432\u0435\u0442 habr.<\/p>\n<p>  \u0422\u0435\u043c\u0430 \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432\u00bb \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430, \u0442.\u043a. \u0441 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043e\u043d\u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0435\u0449\u0435 \u0441 \u0434\u0440\u0435\u0432\u043d\u043e\u0441\u0442\u0438, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430\u00bb \u0434\u0430\u0436\u0435 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u0435\u0441\u044c\u043c\u0430 \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. \u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u00bb NxN, \u043d\u0443\u0436\u043d\u043e \u0432\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430 1..N*N \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u0443\u043c\u043c\u0430 \u0435\u0433\u043e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0435\u0439, \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u0435\u0439 \u0438 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0435\u0439 \u0431\u044b\u043b\u0430 \u0440\u0430\u0432\u043d\u0430 \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u0447\u0438\u0441\u043b\u0443. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0432\u0441\u0435\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0430\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0446\u0438\u0444\u0440 \u0434\u043b\u044f \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430 4\u04454, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c 16! = 20 922 789 888 000 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432.<\/p>\n<p>  \u041f\u043e\u0434\u0443\u043c\u0430\u0435\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/jc\/nd\/cc\/jcndccahc944f3iihffugn_bjsc.png\"><br \/>  <a name=\"habracut\"><\/a><br \/>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438. \u041d\u0443\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0435 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u043b\u0438\u0441\u044c, \u0438 \u0441\u0443\u043c\u043c\u0430 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0435\u0439, \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u0435\u0439 \u0438 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0435\u0439 \u0431\u044b\u043b\u0430 \u0440\u0430\u0432\u043d\u0430 \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u0447\u0438\u0441\u043b\u0443.<\/p>\n<p>  \u041b\u0435\u0433\u043a\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u0430 \u0441\u0443\u043c\u043c\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0430, \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e n:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/06\/wm\/50\/06wm50ycmeo5nszgdlm8iuu8pc4.png\"><\/p>\n<p>  \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u044b 4\u04454, \u0442\u0430\u043a \u0447\u0442\u043e \u0441\u0443\u043c\u043c\u0430 = 34.<br \/>  \u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0445 X, \u043d\u0430\u0448 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0432\u0438\u0434:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/pw\/zm\/8z\/pwzm8zao36smcgnpgv2bn8clwxk.png\"><\/p>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0435, \u0438 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435, \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e: \u0442.\u043a. \u0441\u0443\u043c\u043c\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430, \u043a\u0440\u0430\u0439\u043d\u0438\u0435 \u0441\u0442\u043e\u0431\u043b\u0446\u044b \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 3:<br \/>  <code>X14 = S - X11 - X12 - X13<br \/>  X24 = S - X21 - X22 - X23<br \/>  ...<br \/>  X41 = S - X11 - X21 - X31<\/code><\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u0432\u0430\u0434\u0440\u0430\u0442 4\u04454 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 3\u04453, \u0447\u0442\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u0447\u0438\u0441\u043b\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u0441 16! \u0434\u043e 9!, \u0442.\u0435. \u0432 57\u043c\u043b\u043d \u0440\u0430\u0437. \u0417\u043d\u0430\u044f \u044d\u0442\u043e, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u0435\u043d \u0442\u0430\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u0434\u043b\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043e\u0432.<\/p>\n<h3>\u0421++ \u2014 \u043e\u0434\u043d\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/h3>\n<p>  \u041f\u0440\u0438\u043d\u0446\u0438\u043f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432\u0435\u0441\u044c\u043c\u0430 \u043f\u0440\u043e\u0441\u0442. \u0411\u0435\u0440\u0435\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0447\u0438\u0441\u0435\u043b 1..16 \u0438 \u0446\u0438\u043a\u043b for \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443, \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u044511. \u0417\u0430\u0442\u0435\u043c \u0431\u0435\u0440\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0447\u0438\u0441\u043b\u0430 x11, \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u0439 \u0432\u0438\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cpp\">int squares = 0; int digits[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }; Set mset(digits, digits + N*N); for (int x11 = 1; x11 &lt;= MAX; x11++) {   Set set12(mset); set12.erase(x11);   for (SetIterator it12 = set12.begin(); it12 != set12.end(); it12++) {     int x12 = *it12;     Set set13(set12); set13.erase(x12);     for (SetIterator it13 = set13.begin(); it13 != set13.end(); it13++) {        int x13 = *it13;        int x14 = S - x11 - x12 - x13;        if (x14 &lt; 1 || x14 &gt; MAX) continue;        if (x14 == x11 || x14 == x12 || x14 == x13) continue;        ...        int sh1 = x11 + x12 + x13 + x14, sh2 = x21 + x22 + x23 + x24, sh3 = x31 + x32 + x33 + x34, sh4 = x41 + x42 + x43 + x44;        int sv1 = x11 + x21 + x31 + x41, sv2 = x12 + x22 + x32 + x42, sv3 = x13 + x23 + x33 + x43, sv4 = x14 + x24 + x34 + x44;        int sd1 = x11 + x22 + x33 + x44, sd2 = x14 + x23 + x32 + x41;        if (sh1 != S || sh2 != S || sh3 != S || sh4 != S || sv1 != S || sv2 != S || sv3 != S || sv4 != S || sd1 != S || sd2 != S)          continue;        \/\/ \u0415\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u0430 \u043f\u0440\u043e\u0448\u043b\u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f, \u0442\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u043d\u0430\u0439\u0434\u0435\u043d        printf(\"%d %d %d %d  %d %d %d %d  %d %d %d %d  %d %d %d %d\\n\", x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33, x34, x41, x42, x43, x44);        squares++;    } } printf(\"CNT: %d\\n\", squares); <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u043c.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;set&gt; #include &lt;stdio.h&gt; #include &lt;ctime&gt; #include \"stdafx.h\"  typedef std::set&lt;int&gt; Set; typedef Set::iterator SetIterator;  #define N 4 #define MAX (N*N) #define S 34  int main(int argc, char *argv[]) { \t\/\/ x11 x12 x13 x14  \t\/\/ x21 x22 x23 x24  \t\/\/ x31 x32 x33 x34  \t\/\/ x41 x42 x43 x44   \tconst clock_t begin_time = clock();  \tint squares = 0; \tint digits[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }; \tSet mset(digits, digits + N*N); \tfor (int x11 = 1; x11 &lt;= MAX; x11++) { \t\tSet set12(mset); set12.erase(x11); \t\tfor (SetIterator it12 = set12.begin(); it12 != set12.end(); it12++) { \t\t\tint x12 = *it12; \t\t\tSet set13(set12); set13.erase(x12); \t\t\tfor (SetIterator it13 = set13.begin(); it13 != set13.end(); it13++) { \t\t\t\tint x13 = *it13; \t\t\t\tint x14 = S - x11 - x12 - x13; \t\t\t\tif (x14 &lt; 1 || x14 &gt; MAX) continue; \t\t\t\tif (x14 == x11 || x14 == x12 || x14 == x13) continue;  \t\t\t\tSet set21(set13); set21.erase(x13); set21.erase(x14); \t\t\t\tfor (SetIterator it21 = set21.begin(); it21 != set21.end(); it21++) { \t\t\t\t\tint x21 = *it21; \t\t\t\t\tSet set22(set21); set22.erase(x21); \t\t\t\t\tfor (SetIterator it22 = set22.begin(); it22 != set22.end(); it22++) { \t\t\t\t\t\tint x22 = *it22; \t\t\t\t\t\tSet set23(set22); set23.erase(x22); \t\t\t\t\t\tfor (SetIterator it23 = set23.begin(); it23 != set23.end(); it23++) { \t\t\t\t\t\t\tint x23 = *it23, x24 = S - x21 - x22 - x23; \t\t\t\t\t\t\tif (x24 &lt; 1 || x24 &gt; MAX) continue; \t\t\t\t\t\t\tif (x24 == x11 || x24 == x12 || x24 == x13 || x24 == x14 || x24 == x21 || x24 == x22 || x24 == x23) continue;  \t\t\t\t\t\t\tSet set31(set23); \t\t\t\t\t\t\tset31.erase(x23); set31.erase(x24); \t\t\t\t\t\t\tfor (SetIterator it31 = set31.begin(); it31 != set31.end(); it31++) { \t\t\t\t\t\t\t\tint x31 = *it31; \t\t\t\t\t\t\t\tSet set32(set31); set32.erase(x31); \t\t\t\t\t\t\t\tfor (SetIterator it32 = set32.begin(); it32 != set32.end(); it32++) { \t\t\t\t\t\t\t\t\tint x32 = *it32; \t\t\t\t\t\t\t\t\tSet set33(set32); set33.erase(x32); \t\t\t\t\t\t\t\t\tfor (SetIterator it33 = set33.begin(); it33 != set33.end(); it33++) { \t\t\t\t\t\t\t\t\t\tint x33 = *it33, x34 = S - x31 - x32 - x33; \t\t\t\t\t\t\t\t\t\tif (x34 &lt; 1 || x34 &gt; MAX) continue; \t\t\t\t\t\t\t\t\t\tif (x34 == x11 || x34 == x12 || x34 == x13 || x34 == x14 || x34 == x21 || x34 == x22 || x34 == x23 || x34 == x24 || x34 == x31 || x34 == x32 || x34 == x33) continue;  \t\t\t\t\t\t\t\t\t\tint x41 = S - x11 - x21 - x31, x42 = S - x12 - x22 - x32, x43 = S - x13 - x23 - x33, x44 = S - x14 - x24 - x34; \t\t\t\t\t\t\t\t\t\tif (x41 &lt; 1 || x41 &gt; MAX || x42 &lt; 1 || x42 &gt; MAX || x43 &lt; 1 || x43 &gt; MAX || x44 &lt; 1 || x41 &gt; MAX) continue;  \t\t\t\t\t\t\t\t\t\tif (x41 == x11 || x41 == x12 || x41 == x13 || x41 == x14 || x41 == x21 || x41 == x22 || x41 == x23 || x41 == x24 || \t\t\t\t\t\t\t\t\t\t\tx41 == x31 || x41 == x32 || x41 == x33 || x41 == x34) \t\t\t\t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t\t\t\tif (x42 == x11 || x42 == x12 || x42 == x13 || x42 == x14 || x42 == x21 || x42 == x22 || x42 == x23 || x42 == x24 || \t\t\t\t\t\t\t\t\t\t\tx42 == x31 || x42 == x32 || x42 == x33 || x42 == x34 || x42 == x41) \t\t\t\t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t\t\t\tif (x43 == x11 || x43 == x12 || x43 == x13 || x43 == x14 || x43 == x21 || x43 == x22 || x43 == x23 || x43 == x24 || \t\t\t\t\t\t\t\t\t\t\tx43 == x31 || x43 == x32 || x43 == x33 || x43 == x34 || x43 == x41 || x43 == x42) \t\t\t\t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t\t\t\tif (x44 == x11 || x44 == x12 || x44 == x13 || x44 == x14 || x44 == x21 || x44 == x22 || x44 == x23 || x44 == x24 || \t\t\t\t\t\t\t\t\t\t\tx44 == x31 || x44 == x32 || x44 == x33 || x44 == x34 || x44 == x41 || x44 == x42 || x44 == x43) \t\t\t\t\t\t\t\t\t\t\tcontinue;  \t\t\t\t\t\t\t\t\t\tint sh1 = x11 + x12 + x13 + x14, sh2 = x21 + x22 + x23 + x24, sh3 = x31 + x32 + x33 + x34, sh4 = x41 + x42 + x43 + x44; \t\t\t\t\t\t\t\t\t\tint sv1 = x11 + x21 + x31 + x41, sv2 = x12 + x22 + x32 + x42, sv3 = x13 + x23 + x33 + x43, sv4 = x14 + x24 + x34 + x44; \t\t\t\t\t\t\t\t\t\tint sd1 = x11 + x22 + x33 + x44, sd2 = x14 + x23 + x32 + x41; \t\t\t\t\t\t\t\t\t\tif (sh1 != S || sh2 != S || sh3 != S || sh4 != S || sv1 != S || sv2 != S || sv3 != S || sv4 != S || sd1 != S || sd2 != S) \t\t\t\t\t\t\t\t\t\t\tcontinue;  \t\t\t\t\t\t\t\t\t\tprintf(\"%d %d %d %d  %d %d %d %d  %d %d %d %d  %d %d %d %d\\n\", x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33, x34, x41, x42, x43, x44); \t\t\t\t\t\t\t\t\t\tsquares++; \t\t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t} \t\t\t\t\t\t} \t\t\t\t\t} \t\t\t\t} \t\t\t} \t\t} \t} \t \tprintf(\"CNT: %d\\n\", squares);  \tfloat diff_t = float(clock() - begin_time)\/CLOCKS_PER_SEC; \tprintf(\"T = %.2fs\\n\", diff_t);  \treturn 0; }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \u0432\u0441\u0435\u0433\u043e \u0431\u044b\u043b\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043e <b>7040 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432<\/b> \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432\u00bb 4\u04454, \u0430 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u043e <b>102\u0441<\/b>.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/6c\/bc\/le\/6cbcle75t9b9owheenk5k-p7cms.png\"><\/p>\n<p>  \u041a\u0441\u0442\u0430\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d \u043d\u0430 \u0433\u0440\u0430\u0432\u044e\u0440\u0435 \u0414\u044e\u0440\u0435\u0440\u0430. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f \u0435\u0441\u0442\u044c, \u0442.\u043a. \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 <i>\u0432\u0441\u0435<\/i> \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 4\u04454:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/2h\/ew\/kx\/2hewkxuueb6na-r8vxvra-dnrdu.png\"><\/p>\n<p>  \u041d\u0435\u043b\u044c\u0437\u044f \u043d\u0435 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0414\u044e\u0440\u0435\u0440 \u0432\u0441\u0442\u0430\u0432\u0438\u043b \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0432 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a, \u0446\u0438\u0444\u0440\u044b <i>1514<\/i> \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u0433\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0433\u0440\u0430\u0432\u044e\u0440\u044b.<\/p>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 (\u043e\u0442\u043c\u0435\u0447\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u0430\u043a verified at 1514 by Albrecht D\u00fcrer;), \u043e\u0434\u043d\u0430\u043a\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0435 \u0442\u0430\u043a \u0438 \u043c\u0430\u043b\u043e \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u0441 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043e\u043c Core i7. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a, \u0438 \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u044f\u0434\u0440\u0430.<\/p>\n<h3>\u0421++ \u2014 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/h3>\n<p>  \u041f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e, \u0445\u043e\u0442\u044f \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0435\u0441\u0442\u044c \u043f\u043e\u0447\u0442\u0438 \u0437\u0430\u0431\u044b\u0442\u044b\u0439 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 <b>OpenMP<\/b> (Open Multi-Processing). \u042d\u0442\u0430 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0430\u0436 \u0441 1998\u0433, \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443, \u043a\u0430\u043a\u0438\u0435 \u0447\u0430\u0441\u0442\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e. \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 OpenMP \u0435\u0441\u0442\u044c \u0438 \u0432 Visual Studio, \u0442\u0430\u043a \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u0443\u044e, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u043e\u0434 \u043b\u0438\u0448\u044c \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443:  <\/p>\n<pre><code class=\"cpp\">int squares = 0; #pragma omp parallel for reduction(+: squares) for (int x11 = 1; x11 &lt;= MAX; x11++) {   ... } printf(\"CNT: %d\\n\", squares); <\/code><\/pre>\n<p>  \u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 <i>#pragma omp parallel<\/i> for \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0446\u0438\u043a\u043b for \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 squares \u0437\u0430\u0434\u0430\u0435\u0442 \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0449\u0435\u0439 \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 (\u0431\u0435\u0437 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e).<\/p>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430\u043b\u0438\u0446\u043e: \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u043e\u0441\u044c \u0441\u043e 102\u0441 \u0434\u043e <b>18\u0441<\/b>.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ji\/hl\/xt\/jihlxtqposct3ttitpeipapjmz0.png\"><\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#include &lt;set&gt; #include &lt;stdio.h&gt; #include &lt;ctime&gt; #include \"stdafx.h\"  typedef std::set&lt;int&gt; Set; typedef Set::iterator SetIterator;  #define N 4 #define MAX (N*N) #define S 34  int main(int argc, char *argv[]) { \t\/\/ x11 x12 x13 x14  \t\/\/ x21 x22 x23 x24  \t\/\/ x31 x32 x33 x34  \t\/\/ x41 x42 x43 x44   \tconst clock_t begin_time = clock();  \tint squares = 0; \t#pragma omp parallel for reduction(+: squares) \tfor (int x11 = 1; x11 &lt;= MAX; x11++) { \t\tint digits[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }; \t\tSet mset(digits, digits + N*N); \t\tSet set12(mset); set12.erase(x11); \t\tfor (SetIterator it12 = set12.begin(); it12 != set12.end(); it12++) { \t\t\tint x12 = *it12; \t\t\tSet set13(set12); set13.erase(x12); \t\t\tfor (SetIterator it13 = set13.begin(); it13 != set13.end(); it13++) { \t\t\t\tint x13 = *it13; \t\t\t\tint x14 = S - x11 - x12 - x13; \t\t\t\tif (x14 &lt; 1 || x14 &gt; MAX) continue; \t\t\t\tif (x14 == x11 || x14 == x12 || x14 == x13) continue;  \t\t\t\tSet set21(set13); set21.erase(x13); set21.erase(x14); \t\t\t\tfor (SetIterator it21 = set21.begin(); it21 != set21.end(); it21++) { \t\t\t\t\tint x21 = *it21; \t\t\t\t\tSet set22(set21); set22.erase(x21); \t\t\t\t\tfor (SetIterator it22 = set22.begin(); it22 != set22.end(); it22++) { \t\t\t\t\t\tint x22 = *it22; \t\t\t\t\t\tSet set23(set22); set23.erase(x22); \t\t\t\t\t\tfor (SetIterator it23 = set23.begin(); it23 != set23.end(); it23++) { \t\t\t\t\t\t\tint x23 = *it23, x24 = S - x21 - x22 - x23; \t\t\t\t\t\t\tif (x24 &lt; 1 || x24 &gt; MAX) continue; \t\t\t\t\t\t\tif (x24 == x11 || x24 == x12 || x24 == x13 || x24 == x14 || x24 == x21 || x24 == x22 || x24 == x23) continue;  \t\t\t\t\t\t\tSet set31(set23); \t\t\t\t\t\t\tset31.erase(x23); set31.erase(x24); \t\t\t\t\t\t\tfor (SetIterator it31 = set31.begin(); it31 != set31.end(); it31++) { \t\t\t\t\t\t\t\tint x31 = *it31; \t\t\t\t\t\t\t\tSet set32(set31); set32.erase(x31); \t\t\t\t\t\t\t\tfor (SetIterator it32 = set32.begin(); it32 != set32.end(); it32++) { \t\t\t\t\t\t\t\t\tint x32 = *it32; \t\t\t\t\t\t\t\t\tSet set33(set32); set33.erase(x32); \t\t\t\t\t\t\t\t\tfor (SetIterator it33 = set33.begin(); it33 != set33.end(); it33++) { \t\t\t\t\t\t\t\t\t\tint x33 = *it33, x34 = S - x31 - x32 - x33; \t\t\t\t\t\t\t\t\t\tif (x34 &lt; 1 || x34 &gt; MAX) continue; \t\t\t\t\t\t\t\t\t\tif (x34 == x11 || x34 == x12 || x34 == x13 || x34 == x14 || x34 == x21 || x34 == x22 || x34 == x23 || x34 == x24 || x34 == x31 || x34 == x32 || x34 == x33) continue;  \t\t\t\t\t\t\t\t\t\tint x41 = S - x11 - x21 - x31, x42 = S - x12 - x22 - x32, x43 = S - x13 - x23 - x33, x44 = S - x14 - x24 - x34; \t\t\t\t\t\t\t\t\t\tif (x41 &lt; 1 || x41 &gt; MAX || x42 &lt; 1 || x42 &gt; MAX || x43 &lt; 1 || x43 &gt; MAX || x44 &lt; 1 || x41 &gt; MAX) continue;  \t\t\t\t\t\t\t\t\t\tif (x41 == x11 || x41 == x12 || x41 == x13 || x41 == x14 || x41 == x21 || x41 == x22 || x41 == x23 || x41 == x24 || \t\t\t\t\t\t\t\t\t\t\tx41 == x31 || x41 == x32 || x41 == x33 || x41 == x34) \t\t\t\t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t\t\t\tif (x42 == x11 || x42 == x12 || x42 == x13 || x42 == x14 || x42 == x21 || x42 == x22 || x42 == x23 || x42 == x24 || \t\t\t\t\t\t\t\t\t\t\tx42 == x31 || x42 == x32 || x42 == x33 || x42 == x34 || x42 == x41) \t\t\t\t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t\t\t\tif (x43 == x11 || x43 == x12 || x43 == x13 || x43 == x14 || x43 == x21 || x43 == x22 || x43 == x23 || x43 == x24 || \t\t\t\t\t\t\t\t\t\t\tx43 == x31 || x43 == x32 || x43 == x33 || x43 == x34 || x43 == x41 || x43 == x42) \t\t\t\t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t\t\t\tif (x44 == x11 || x44 == x12 || x44 == x13 || x44 == x14 || x44 == x21 || x44 == x22 || x44 == x23 || x44 == x24 || \t\t\t\t\t\t\t\t\t\t\tx44 == x31 || x44 == x32 || x44 == x33 || x44 == x34 || x44 == x41 || x44 == x42 || x44 == x43) \t\t\t\t\t\t\t\t\t\t\tcontinue;  \t\t\t\t\t\t\t\t\t\tint sh1 = x11 + x12 + x13 + x14, sh2 = x21 + x22 + x23 + x24, sh3 = x31 + x32 + x33 + x34, sh4 = x41 + x42 + x43 + x44; \t\t\t\t\t\t\t\t\t\tint sv1 = x11 + x21 + x31 + x41, sv2 = x12 + x22 + x32 + x42, sv3 = x13 + x23 + x33 + x43, sv4 = x14 + x24 + x34 + x44; \t\t\t\t\t\t\t\t\t\tint sd1 = x11 + x22 + x33 + x44, sd2 = x14 + x23 + x32 + x41; \t\t\t\t\t\t\t\t\t\tif (sh1 != S || sh2 != S || sh3 != S || sh4 != S || sv1 != S || sv2 != S || sv3 != S || sv4 != S || sd1 != S || sd2 != S) \t\t\t\t\t\t\t\t\t\t\tcontinue;  \t\t\t\t\t\t\t\t\t\tprintf(\"%d %d %d %d  %d %d %d %d  %d %d %d %d  %d %d %d %d\\n\", x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33, x34, x41, x42, x43, x44); \t\t\t\t\t\t\t\t\t\tsquares++; \t\t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t\t} \t\t\t\t\t\t\t} \t\t\t\t\t\t} \t\t\t\t\t} \t\t\t\t} \t\t\t} \t\t} \t} \t \tprintf(\"CNT: %d\\n\", squares);  \tfloat diff_t = float(clock() - begin_time)\/CLOCKS_PER_SEC; \tprintf(\"T = %.2fs\\n\", diff_t);  \treturn 0; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u042d\u0442\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435 \u2014 \u0442.\u043a. \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f (\u0440\u0430\u0441\u0447\u0435\u0442\u044b \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0432\u0435\u0442\u0432\u0438 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430), \u0432\u0440\u0435\u043c\u044f \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 \u0447\u0438\u0441\u043b\u043e \u0440\u0430\u0437, \u0440\u0430\u0432\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u044f\u0434\u0435\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430. \u041d\u043e \u0443\u0432\u044b, \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e \u0431<i>\u043e<\/i>\u043b\u044c\u0448\u0435\u0433\u043e \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c, \u0445\u043e\u0442\u044f \u043a\u0430\u043a\u0438\u043c\u0438-\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0438\u0433\u0440\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u0432. \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0431\u043e\u043b\u0435\u0435 \u0442\u044f\u0436\u0435\u043b\u043e\u0439 \u0430\u0440\u0442\u0438\u043b\u043b\u0435\u0440\u0438\u0438, \u0440\u0430\u0441\u0447\u0435\u0442\u0430\u043c \u043d\u0430 GPU.<\/p>\n<h2>\u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e NVIDIA CUDA<\/h2>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0435 \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438, \u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u043d\u0430 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0430\u043f\u043f\u0430\u0440\u0430\u0442\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432 (blocks), \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 (threads). <br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/nf\/sp\/me\/nfspmek2x2tkbiix11zrb3ijkfi.png\"><\/p>\n<p>  \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f 2\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 CUDA:  <\/p>\n<pre><code class=\"cpp\">__global__ void add(int n, float *x, float *y) {   int index = threadIdx.x;   int stride = blockDim.x;   for (int i = index; i &lt; n; i += stride)       y[i] = x[i] + y[i]; }<\/code><\/pre>\n<p>  \u041c\u0430\u0441\u0441\u0438\u0432\u044b x \u0438 y \u2014 \u043e\u0431\u0449\u0438\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0431\u043b\u043e\u043a\u043e\u0432, \u0430 \u0441\u0430\u043c\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u0445. \u041a\u043b\u044e\u0447 \u0442\u0443\u0442 \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0435 \u2014 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u044b \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u044b \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u0447\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 CPU, \u0437\u0430\u0442\u043e \u0438\u0445 \u043c\u043d\u043e\u0433\u043e \u0438 \u043e\u043d\u0438 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u042d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e. \u041c\u044b \u0438\u043c\u0435\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0447\u0438\u0441\u0435\u043b X11, X12,..,X44. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u0437 16 \u0431\u043b\u043e\u043a\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c 16 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u041d\u043e\u043c\u0435\u0440\u0443 \u0431\u043b\u043e\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e X11, \u043d\u043e\u043c\u0435\u0440\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0447\u0438\u0441\u043b\u043e X12, \u0430 \u0441\u0430\u043c \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u044b \u0441 \u0434\u043b\u044f \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0445 X11 \u0438 X12. \u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u043d\u043e \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u044c \u2014 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c, \u043d\u043e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u044b \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 \u043d\u0443\u043b\u0435\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432.<\/p>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u0441\u044c\u043c\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u043c:  <\/p>\n<pre><code class=\"cpp\">#define N 4 #define SQ_MAX 8*1024 #define BLOCK_SIZE (SQ_MAX*N*N + 1)  int main(int argc,char *argv[]) {     const clock_t begin_time = clock();        int *results = (int*)malloc(BLOCK_SIZE*sizeof(int));     results[0] = 0;      int *gpu_out = NULL;     cudaMalloc(&amp;gpu_out, BLOCK_SIZE*sizeof(int));     cudaMemcpy(gpu_out, results, BLOCK_SIZE*sizeof(int), cudaMemcpyHostToDevice);     squares&lt;&lt;&lt;MAX, MAX&gt;&gt;&gt;(gpu_out);     cudaMemcpy(results, gpu_out, BLOCK_SIZE*sizeof(int), cudaMemcpyDeviceToHost);      \/\/ Print results     int squares = results[0];     for(int p=0; p&lt;SQ_MAX &amp;&amp; p&lt;squares; p++) {         int i = MAX*p + 1;         printf(\"[%d %d %d %d  %d %d %d %d  %d %d %d %d  %d %d %d %d]\\n\",                  results[i], results[i+1], results[i+2], results[i+3],                  results[i+4], results[i+5], results[i+6], results[i+7],                 results[i+8], results[i+9], results[i+10], results[i+11],                 results[i+12], results[i+13], results[i+14], results[i+15]);     }     printf (\"CNT: %d\\n\", squares);        float diff_t = float(clock() - begin_time)\/CLOCKS_PER_SEC;     printf(\"T = %.2fs\\n\", diff_t);        cudaFree(gpu_out);     free(results);        return 0; }<\/code><\/pre>\n<p>  \u041c\u044b \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u0431\u043b\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e cudaMalloc, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e squares, \u0443\u043a\u0430\u0437\u0430\u0432 \u0435\u0439 2 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 16,16 (\u0447\u0438\u0441\u043b\u043e \u0431\u043b\u043e\u043a\u043e\u0432 \u0438 \u0447\u0438\u0441\u043b\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432), \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c\u044b\u043c \u0447\u0438\u0441\u043b\u0430\u043c 1..16, \u0436\u0434\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 cudaDeviceSynchronize, \u0437\u0430\u0442\u0435\u043c \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0447\u0435\u0440\u0435\u0437 cudaMemcpy.<\/p>\n<p>  \u0421\u0430\u043c\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f squares \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u043a\u043e\u0434 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438, \u0441 \u0442\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u0435\u0439, \u0447\u0442\u043e \u043f\u0440\u0438\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e atomicAdd \u2014 \u044d\u0442\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f\u0445.   <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0446\u0435\u043b\u0438\u043a\u043e\u043c<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/\/ Compile: \/\/ nvcc -o magic4_gpu.exe magic4_gpu.cu  #include &lt;stdio.h&gt; #include &lt;ctime&gt;  #define N 4 #define MAX (N*N) #define SQ_MAX 8*1024 #define BLOCK_SIZE (SQ_MAX*N*N + 1) #define S 34  \/\/ Magic square: \/\/ x11 x12 x13 x14  \/\/ x21 x22 x23 x24  \/\/ x31 x32 x33 x34  \/\/ x41 x42 x43 x44    __global__ void squares(int *res_array) { \tint index1 = blockIdx.x, index2 = threadIdx.x; \tif (index1 + 1 &gt; MAX || index2 + 1 &gt; MAX) return;  \tconst int x11 = index1+1, x12 = index2+1; \tfor(int x13=1; x13&lt;=MAX; x13++) {  \t\tif (x13 == x11 || x13 == x12) \t\t\tcontinue; \t\tint x14 = S - x11 - x12 - x13; \t\tif (x14 &lt; 1 || x14 &gt; MAX) continue; \t\tif (x14 == x11 || x14 == x12 || x14 == x13) \t\t\tcontinue; \t\tfor(int x21=1; x21&lt;=MAX; x21++) {  \t\t\tif (x21 == x11 || x21 == x12 || x21 == x13 || x21 == x14) \t\t\t\tcontinue; \t\t\tfor(int x22=1; x22&lt;=MAX; x22++) { \t\t\t\tif (x22 == x11 || x22 == x12 || x22 == x13 || x22 == x14 || x22 == x21) \t\t\t\t\tcontinue; \t\t\t\tfor(int x23=1; x23&lt;=MAX; x23++) { \t\t\t\t\tint x24 = S - x21 - x22 - x23; \t\t\t\t\tif (x24 &lt; 1 || x24 &gt; MAX) continue; \t\t\t\t\tif (x23 == x11 || x23 == x12 || x23 == x13 || x23 == x14 || x23 == x21 || x23 == x22) \t\t\t\t\t\tcontinue; \t\t\t\t\tif (x24 == x11 || x24 == x12 || x24 == x13 || x24 == x14 || x24 == x21 || x24 == x22 || x24 == x23) \t\t\t\t\t\tcontinue; \t\t\t\t\tfor(int x31=1; x31&lt;=MAX; x31++) {  \t\t\t\t\t\tif (x31 == x11 || x31 == x12 || x31 == x13 || x31 == x14 ||  x31 == x21 || x31 == x22 || x31 == x23 || x31 == x24) \t\t\t\t\t\t\tcontinue; \t\t\t\t\t\tfor(int x32=1; x32&lt;=MAX; x32++) { \t\t\t\t\t\t\tif (x32 == x11 || x32 == x12 || x32 == x13 || x32 == x14 || x32 == x21 || x32 == x22 || x32 == x23 || x32 == x24 || x32 == x31) \t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\tfor(int x33=1; x33&lt;=MAX; x33++) { \t\t\t\t\t\t\t\tint x34 = S - x31 - x32 - x33; \t\t\t\t\t\t\t\tif (x34 &lt; 1 || x34 &gt; MAX) continue; \t\t\t\t\t\t\t\tif (x33 == x11 || x33 == x12 || x33 == x13 || x33 == x14 || x33 == x21 || x33 == x22 || x33 == x23 || x33 == x24 || x33 == x31 || x33 == x32) \t\t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t\tif (x34 == x11 || x34 == x12 || x34 == x13 || x34 == x14 || x34 == x21 || x34 == x22 || x34 == x23 || x34 == x24 || x34 == x31 || x34 == x32 || x34 == x33) \t\t\t\t\t\t\t\t\tcontinue;  \t\t\t\t\t\t\t\tconst int x41 = S - x11 - x21 - x31, x42 = S - x12 - x22 - x32, x43 = S - x13 - x23 - x33, x44 = S - x14 - x24 - x34; \t\t\t\t\t\t\t\tif (x41 &lt; 1 || x41 &gt; MAX || x42 &lt; 1 || x42 &gt; MAX || x43 &lt; 1 || x43 &gt; MAX || x44 &lt; 1 || x44 &gt; MAX)  \t\t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t\tif (x41 == x11 || x41 == x12 || x41 == x13 || x41 == x14 || x41 == x21 || x41 == x22 || x41 == x23 || x41 == x24 || \t\t\t\t\t\t\t\t\tx41 == x31 || x41 == x32 || x41 == x33 || x41 == x34) \t\t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t\tif (x42 == x11 || x42 == x12 || x42 == x13 || x42 == x14 || x42 == x21 || x42 == x22 || x42 == x23 || x42 == x24 || \t\t\t\t\t\t\t\t\tx42 == x31 || x42 == x32 || x42 == x33 || x42 == x34 || x42 == x41) \t\t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t\tif (x43 == x11 || x43 == x12 || x43 == x13 || x43 == x14 || x43 == x21 || x43 == x22 || x43 == x23 || x43 == x24 ||  \t\t\t\t\t\t\t\t\tx43 == x31 || x43 == x32 || x43 == x33 || x43 == x34 || x43 == x41 || x43 == x42) \t\t\t\t\t\t\t\t\tcontinue; \t\t\t\t\t\t\t\tif (x44 == x11 || x44 == x12 || x44 == x13 || x44 == x14 || x44 == x21 || x44 == x22 || x44 == x23 || x44 == x24 ||  \t\t\t\t\t\t\t\t\tx44 == x31 || x44 == x32 || x44 == x33 || x44 == x34 || x44 == x41 || x44 == x42 || x44 == x43) \t\t\t\t\t\t\t\t\tcontinue;    \t\t\t\t\t\t\t\tint sh1 = x11 + x12 + x13 + x14, sh2 = x21 + x22 + x23 + x24, sh3 = x31 + x32 + x33 + x34, sh4 = x41 + x42 + x43 + x44; \t\t\t\t\t\t\t\tint sv1 = x11 + x21 + x31 + x41, sv2 = x12 + x22 + x32 + x42, sv3 = x13 + x23 + x33 + x43, sv4 = x14 + x24 + x34 + x44; \t\t\t\t\t\t\t\tint sd1 = x11 + x22 + x33 + x44, sd2 = x14 + x23 + x32 + x41; \t\t\t\t\t\t\t\tif (sh1 != S || sh2 != S || sh3 != S || sh4 != S || sv1 != S || sv2 != S || sv3 != S || sv4 != S || sd1 != S || sd2 != S) \t\t\t\t\t\t\t\t\tcontinue;  \t\t\t\t\t\t\t\t\/\/ Square found: save in array (MAX numbers for each square) \t\t\t\t\t\t\t\tint p = atomicAdd(res_array, 1); \t\t\t\t\t\t\t\tif (p &gt;= SQ_MAX) continue;  \t\t\t\t\t\t\t\tint i = MAX*p + 1; \t\t\t\t\t\t\t\tres_array[i]   = x11; res_array[i+1] = x12; res_array[i+2]  = x13; res_array[i+3]  = x14;  \t\t\t\t\t\t\t\tres_array[i+4] = x21; res_array[i+5] = x22; res_array[i+6]  = x23; res_array[i+7]  = x24;  \t\t\t\t\t\t\t\tres_array[i+8] = x31; res_array[i+9] = x32; res_array[i+10] = x33; res_array[i+11] = x34;  \t\t\t\t\t\t\t\tres_array[i+12]= x41; res_array[i+13]= x42; res_array[i+14] = x43; res_array[i+15] = x44;   \t\t\t\t\t\t\t\t\/\/ Warning: printf from kernel makes calculation 2-3x slower \t\t\t\t\t\t\t\t\/\/ printf(\"%d %d %d %d  %d %d %d %d  %d %d %d %d  %d %d %d %d\\n\", x11, x12, x13, x14, x21, x22, x23, x24, x31, x32, x33, x34, x41, x42, x43, x44); \t\t\t\t\t\t\t} \t\t\t\t\t\t} \t\t\t\t\t} \t\t\t\t} \t\t\t} \t\t} \t} }  int main(int argc,char *argv[]) { \tint *gpu_out = NULL;     cudaMalloc(&amp;gpu_out, BLOCK_SIZE*sizeof(int));  \tconst clock_t begin_time = clock();  \tint *results = (int*)malloc(BLOCK_SIZE*sizeof(int)); \tresults[0] = 0; \tcudaMemcpy(gpu_out, results, BLOCK_SIZE*sizeof(int), cudaMemcpyHostToDevice);        squares&lt;&lt;&lt;MAX, MAX&gt;&gt;&gt;(gpu_out);      cudaMemcpy(results, gpu_out, BLOCK_SIZE*sizeof(int), cudaMemcpyDeviceToHost);  \t\/\/ Print results \tint squares = results[0]; \tfor(int p=0; p&lt;SQ_MAX &amp;&amp; p&lt;squares; p++) { \t\tint i = MAX*p + 1; \t\tprintf(\"[%d %d %d %d  %d %d %d %d  %d %d %d %d  %d %d %d %d]\\n\", results[i], results[i+1], results[i+2], results[i+3], \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t results[i+4], results[i+5], results[i+6], results[i+7], \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t results[i+8], results[i+9], results[i+10], results[i+11], \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t results[i+12], results[i+13], results[i+14], results[i+15]); \t} \tprintf (\"CNT: %d\\n\", squares);    \tfloat diff_t = float(clock() - begin_time)\/CLOCKS_PER_SEC; \tprintf(\"T = %.2fs\\n\", diff_t);    \tcudaFree(gpu_out); \tfree(results);    \treturn 0; } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u2014 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u043e 2.7\u0441, \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432 30 \u0440\u0430\u0437 \u043b\u0443\u0447\u0448\u0435 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0434\u043d\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/gw\/s7\/02\/gws702rzlxpvirxs5qtfiftk7fc.png\"><\/p>\n<p>  \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u044d\u0442\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0438\u0434\u0435\u0430\u043b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u043b\u043e\u043a\u043e\u0432 \u043d\u0430 GPU, \u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u044b\u043c \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0417\u0430\u0434\u0430\u0447\u0430 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432\u00bb \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0435\u0441\u044c\u043c\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439, \u0438 \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u043e\u0439. \u0414\u0430\u0436\u0435 \u0441 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u043d\u0430 GPU \u043f\u043e\u0438\u0441\u043a \u0432\u0441\u0435\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 5\u04455 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u044f\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u043e\u0432, \u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 7\u04457 \u0438 \u0432\u044b\u0448\u0435, \u0435\u0449\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u0438\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>  \u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432:<br \/>   \u2014 \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432\u00bb \u043e\u0442 N. \u0418\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0447\u0442\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430 2\u04452 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u043a\u0432\u0430\u0434\u0440\u0430\u0442 3\u04453 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0441\u0435\u0433\u043e 8, \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 4\u04454 \u043a\u0430\u043a \u043c\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u0438, 7040, \u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u043e\u0432 \u0438\u043b\u0438 \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u043e\u043a\u0430 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e. \u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u043e\u043a\u0430 \u043e\u0442\u043a\u0440\u044b\u0442.<br \/>   \u2014 \u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0430\u043c\u0438 \u0438\u043b\u0438 \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u0443\u0436\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0433\u043e.<br \/>   \u2014 \u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043f\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 \u0441\u0443\u043f\u0435\u0440\u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435 \u0438\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043d\u0430 NVIDIA Tesla \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u0442, \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c, \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e. \u0415\u0441\u043b\u0438 \u0443 \u043a\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0438\u0434\u0435\u0438 \u043f\u043e \u0441\u0430\u043c\u043e\u043c\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443, \u0438\u0445 \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c. \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u0430\u0436\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e \u043f\u043e\u0438\u0441\u043a\u0443 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432, \u0435\u0441\u043b\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0430\u0431\u0435\u0440\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0438\u0441\u043b\u043e \u0447\u0438\u0442\u0430\u0442\u0430\u043b\u0435\u0439 \ud83d\ude09<\/p>\n<p>  \u041e\u0431 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0441\u0430\u043c\u0438\u0445 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e, \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441.<\/p>\n<p>  PS: \u041a \u0432\u043e\u043f\u0440\u043e\u0441\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u00ab\u0430 \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0430\u0434\u043e\u00bb. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0445\u043e\u0434\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u044d\u043d\u0435\u0440\u0433\u0438\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 \u043d\u0438\u0447\u0435\u043c \u043d\u0435 \u043b\u0443\u0447\u0448\u0435 \u0438\u043b\u0438 \u0445\u0443\u0436\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0431\u0438\u0442\u043a\u043e\u0438\u043d\u043e\u0432, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u0438 \u043d\u0435\u0442? \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0440\u0430\u0437\u043c\u0438\u043d\u043a\u0430 \u0434\u043b\u044f \u0443\u043c\u0430 \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p><\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/424845\/\"> https:\/\/habr.com\/post\/424845\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\u041f\u0440\u0438\u0432\u0435\u0442 habr.<\/p>\n<p>  \u0422\u0435\u043c\u0430 \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432\u00bb \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430, \u0442.\u043a. \u0441 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043e\u043d\u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0435\u0449\u0435 \u0441 \u0434\u0440\u0435\u0432\u043d\u043e\u0441\u0442\u0438, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430\u00bb \u0434\u0430\u0436\u0435 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u0435\u0441\u044c\u043c\u0430 \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. \u041d\u0430\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u00bb NxN, \u043d\u0443\u0436\u043d\u043e \u0432\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430 1..N*N \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u0443\u043c\u043c\u0430 \u0435\u0433\u043e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0435\u0439, \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u0435\u0439 \u0438 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0435\u0439 \u0431\u044b\u043b\u0430 \u0440\u0430\u0432\u043d\u0430 \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u0447\u0438\u0441\u043b\u0443. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0432\u0441\u0435\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0430\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0446\u0438\u0444\u0440 \u0434\u043b\u044f \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430 4\u04454, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c 16! = 20 922 789 888 000 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432.<\/p>\n<p>  \u041f\u043e\u0434\u0443\u043c\u0430\u0435\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/jc\/nd\/cc\/jcndccahc944f3iihffugn_bjsc.png\">  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-290104","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/290104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=290104"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/290104\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=290104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=290104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=290104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}