{"id":270933,"date":"2015-12-23T09:25:02","date_gmt":"2015-12-23T06:25:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=270933"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=270933","title":{"rendered":"\u0420\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432 \u043d\u0430 CPU \u0438 GPU"},"content":{"rendered":"<br \/>\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432 \u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044f\u0445 CPU \u0438 GPU. \u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0441\u0430\u043c\u0438\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u044e \u0432\u0430\u0441 \u0441 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439.<\/p>\n<p>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0435\u0439. \u0421 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0414\u0430\u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0441\u0435\u0442\u043a\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/e16\/f26\/f11\/e16f26f1167a46d5bdc545b8487be441.jpg\"\/><\/p>\n<p>  \u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0435\u0442\u043a\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0435\u0439:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/9e9\/e76\/426\/9e9e76426e62479e9d1e06f334fb2122.jpg\"\/><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0420\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 CPU<\/h4>\n<p>  \u0414\u043b\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u043d\u0430 CPU \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044e Parallel, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430 OpenMP. Parallel \u2013 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044f\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0432 \u044f\u0437\u044b\u043a\u0435 C#, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0446\u0438\u043a\u043b\u043e\u0432 \u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439.<\/p>\n<p>  \u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0430 Parallel:<\/p>\n<pre><code class=\"cs\">\/* n*m \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0441\u0435\u0442\u043a\u0438 T \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0441\u0435\u0442\u043a\u0438 eps \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u0430\u044f \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c *\/ \/* \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f   \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043d\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0443\u0437\u043b\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b, \u0442\u0430\u043a   \u043a\u0430\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a. \u042d\u0442\u043e \u0442\u0440\u0430\u0442\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u0435  \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a.*\/ private void Parallelization(int n, int m, float[,] T, float eps) { \tint time; \/\/\u0421\u0435\u043a\u0443\u043d\u0434\u043e\u043c\u0435\u0440 \tbool flag = false; \/\/\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \tint interetion = 0; \/\/\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \tfloat epsilint; \/\/ \u041d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0441\u0435\u0442\u043a\u0435 \tfloat[,] count_eps = new float[n,m]; \/\/ \u041f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c \u0443\u0437\u043b\u0430 \tfloat[,] T_new = new float[n, m]; \/\/ \u041d\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u044d\u043b-\u0442\u043e\u0432 \u0441\u0435\u0442\u043a\u0438 \ttime = Environment.TickCount; \/\/ \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \tdo \t{ \t\tepsilint = eps; \t\tParallel.For(1, n-1, i =&gt; \t\t\t{ \t\t\tParallel.For(1, m - 1, j =&gt; \t\t\t\t{ \t\t\t\t\t\/\/\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \t\t\t\t\tT_new[i, j] = (T[i - 1, j] + T[i + 1, j] + T[i, j - 1] + T[i, j + 1]) \/ 4; \t\t\t\t\t\/\/\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u0430\u0440\u044b\u043c \u0438 \u043d\u043e\u0432\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \t\t\t\t\tcount_eps[i, j] = Math.Abs(T_new[i, j] - T[i, j]); \t\t\t\t\t \/\/\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \t\t\t\t\tif (count_eps[i,j] &gt; epsilint) \t\t\t\t\t{ \t\t\t\t\t\tepsilint = count_eps[i,j]; \t\t\t\t\t} \t\t\t\t\tT[i, j] = T_new[i, j]; \t\t\t\t}); \t\t\t}); \t\tinteretion++; \t}while(epsilint &gt; eps || epsilint != eps); \/\/\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c \u043f\u043e\u043a\u0430 \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \ttime = Environment.TickCount - time; \/\/\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \tOutput(n, m, time, interetion, &quot;OpenMP Parallezetion&quot;); \/\/\u0412\u044b\u0432\u043e\u0434 } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0420\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 GPU<\/h4>\n<p>  \u0414\u043b\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u043d\u0430 GPU \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f CUDA. CUDA \u2013 \u044d\u0442\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u043e\u0442 NVIDIA, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e GPU.<\/p>\n<p>  \u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0430 CUDA:<\/p>\n<pre><code class=\"cpp\">\/*\u0423\u043f\u0440\u043e\u0449\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 CUDA, \u0432\u044b\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434*\/ #define CUDA_DEBUG #ifdef CUDA_DEBUG #define CUDA_CHECK_ERROR(err)           \\ if (err != cudaSuccess) {          \\ printf(&quot;Cuda error: %s\\n&quot;, cudaGetErrorString(err));    \\ printf(&quot;Error in file: %s, line: %i\\n&quot;, __FILE__, __LINE__);  \\ }                 \\ #else #define CUDA_CHECK_ERROR(err) #endif  \/*\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0430 GPU*\/ __global__ void VectorAdd(float* inputMatrix, float* outputMatrix, int n, int m) { \tint i = threadIdx.x + blockIdx.x * blockDim.x; \/\/\u0418\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u044f \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c \tint j = threadIdx.y  + blockIdx.y * blockDim.y; \/\/\u0418\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u044f \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c \tif(i &lt; n -1 && i &gt; 0) \t{ \t\tif(  j &lt; m - 1 &&  j &gt; 0) \t\t\t\/\/\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \t\t\toutputMatrix[i * n + j] = (inputMatrix[(i - 1) * n + j ] + inputMatrix[(i + 1) * n + j] + inputMatrix[i * n + (j - 1)] + inputMatrix[i * n + (j + 1)])\/4; \t} } \/* n*m \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0441\u0435\u0442\u043a\u0438 T \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0441\u0435\u0442\u043a\u0438 eps \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u0430\u044f \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c *\/ \/* \u0412 GPU \u0432\u0441\u0435 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 T \u0431\u044b\u043b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d \u0432 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0439*\/ void OpenCL_Parallezetion(int n, int m, float *T, float eps) { \tint matrixsize = n * m; \/\/ \u0420\u0430\u0437\u043c\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f CPU \tint byteSize = matrixsize * sizeof(float); \/\/ \u0420\u0430\u0437\u043c\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0434 GPU \ttime_t start, end; \/\/ \u0412\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438 \u043a\u043e\u043d\u0446\u0430 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \tfloat time; \/\/ \u0412\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0441\u0447\u0435\u0442\u043e\u0432 \tfloat* T_new = new float[matrixsize]; \/\/ \u041d\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u044d\u043b-\u0442\u043e\u0432 \u0441\u0435\u0442\u043a\u0438 \tfloat *cuda_T_in; \/\/ \u0421\u0442\u0430\u0440\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u044d\u043b-\u0442\u043e\u0432 \u0441\u0435\u0442\u043a\u0438 \u043d\u0430 GPU \tfloat *cuda_T_out; \/\/ \u041d\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u044d\u043b-\u0442\u043e\u0432 \u0441\u0435\u0442\u043a\u0438 \u043d\u0430 GPU \tCUDA_CHECK_ERROR(cudaMalloc((void**)&cuda_T_in, byteSize)); \/\/ \u0412\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043d\u0430 GPU \tCUDA_CHECK_ERROR(cudaMalloc((void**)&cuda_T_out, byteSize)); \tfloat epsilint; \/\/ \u041d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0441\u0435\u0442\u043a\u0435 \tfloat count_eps; \/\/ \u041f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c \u0443\u0437\u043b\u0430 \tint interetaion = 0; \/\/\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \tstart = clock(); \/\/ \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \tdim3 gridsize = dim3(n,m,1); \/\/ \u0414\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 (x,y,z) \u0434\u043b\u044f GPU \tdo{ \t\tepsilint = eps; \t\tCUDA_CHECK_ERROR(cudaMemcpy(cuda_T_in, T, byteSize, cudaMemcpyHostToDevice)); \/\/ \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c GPU \t\tVectorAdd&lt;&lt;&lt; gridsize, m &gt;&gt;&gt;(cuda_T_in, cuda_T_out, n, m); \t\tCUDA_CHECK_ERROR(cudaMemcpy(T_new, cuda_T_out, byteSize, cudaMemcpyDeviceToHost)); \/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438 GPU  \t\tfor(int i = 1; i &lt; n -1; i++) \t\t{ \t\t\tfor(int j = 1; j &lt; m -1; j++) \t\t\t{ \t\t\t\t\/\/\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u0430\u0440\u044b\u043c \u0438 \u043d\u043e\u0432\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \t\t\t\tcount_eps = T_new[i* n + j ] - T[i* n + j]; \t\t\t\t\/\/\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \t\t\t\tif(count_eps &gt; epsilint) \t\t\t\t{ \t\t\t\t\tepsilint = count_eps; \t\t\t\t} \t\t\t\tT[i * n + j] = T_new[i * n + j]; \t\t\t} \t\t} \t\tinteretaion++; \t}while(epsilint &gt; eps || epsilint != eps);\/\/\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c \u043f\u043e\u043a\u0430 \u043f\u043e\u0433\u0440\u0435\u0448\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \tend = clock(); \/\/\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \ttime = (end - start); \/\/\u0412\u044b\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u044f \t\/*\u041e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438 \tCPU \u0438 GPU*\/ \tfree(T); \tfree(T_new); \tcudaFree(cuda_T_in); \tcudaFree(cuda_T_out); \tOutput(n, m, time, interetaion); \/\/\u0412\u044b\u0432\u043e\u0434 } <\/code><\/pre>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/273771\/\"> http:\/\/habrahabr.ru\/post\/273771\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<br \/>\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u0447\u0435\u0442\u043e\u0432 \u043d\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044f\u0445 CPU \u0438 GPU. \u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0441\u0430\u043c\u0438\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u043b\u044e \u0432\u0430\u0441 \u0441 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439.<\/p>\n<p>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0435\u0439. \u0421 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0414\u0430\u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0441\u0435\u0442\u043a\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/e16\/f26\/f11\/e16f26f1167a46d5bdc545b8487be441.jpg\"\/><\/p>\n<p>  \u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0435\u0442\u043a\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u0435\u0439:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/9e9\/e76\/426\/9e9e76426e62479e9d1e06f334fb2122.jpg\"\/>  <\/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-270933","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/270933","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=270933"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/270933\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=270933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=270933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=270933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}