{"id":1012951,"date":"2024-12-27T11:43:52","date_gmt":"2024-12-27T03:43:52","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1012951.html"},"modified":"2024-12-27T11:43:55","modified_gmt":"2024-12-27T03:43:55","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e8%b0%83%e7%94%a8mpi","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1012951.html","title":{"rendered":"Python\u4e2d\u5982\u4f55\u8c03\u7528MPI"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25090536\/462e655d-262c-47ad-a6e1-f0d14166f4e5.webp\" alt=\"Python\u4e2d\u5982\u4f55\u8c03\u7528MPI\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u8c03\u7528MPI\uff08Message Passing Interface\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528mpi4py\u5e93\u3001\u901a\u8fc7\u5c01\u88c5C\u8bed\u8a00\u7684MPI\u51fd\u6570\u6765\u5b9e\u73b0\u3001\u5e76\u884c\u8ba1\u7b97\u4e0e\u8de8\u8282\u70b9\u901a\u4fe1\u3002mpi4py\u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2aPython\u63a5\u53e3\uff0c\u4f7f\u5f97Python\u7a0b\u5e8f\u5458\u80fd\u591f\u4f7f\u7528MPI\u8fdb\u884c\u5e76\u884c\u8ba1\u7b97\uff0c\u800c\u65e0\u9700\u6df1\u5165\u4e86\u89e3\u5e95\u5c42\u7684C\u8bed\u8a00\u5b9e\u73b0\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u5728Python\u4e2d\u8c03\u7528MPI\uff0c\u6211\u4eec\u9700\u8981\u4ece\u5b89\u88c5\u3001\u57fa\u672c\u4f7f\u7528\u3001\u5e38\u89c1\u64cd\u4f5c\u4ee5\u53ca\u5b9e\u7528\u6280\u5de7\u7b49\u51e0\u4e2a\u65b9\u9762\u8fdb\u884c\u6df1\u5165\u63a2\u8ba8\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001MPI4PY\u5e93\u5b89\u88c5\u4e0e\u914d\u7f6e<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u8c03\u7528MPI\u6700\u5e38\u7528\u7684\u65b9\u5f0f\u662f\u4f7f\u7528mpi4py\u5e93\u3002mpi4py\u662f\u4e00\u4e2a\u4e3aPython\u63d0\u4f9bMPI\u5e76\u884c\u8ba1\u7b97\u529f\u80fd\u7684\u5e93\uff0c\u5b83\u662f\u57fa\u4e8eMPI\u6807\u51c6\u7684Python\u7ed1\u5b9a\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5mpi4py<\/strong><\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684\u7cfb\u7edf\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86MPI\u5e93\uff0c\u4f8b\u5982OpenMPI\u6216MPICH\u3002\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528pip\u5b89\u88c5mpi4py\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install mpi4py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684MPI\u5e93\u5b89\u88c5\u5728\u4e00\u4e2a\u975e\u6807\u51c6\u8def\u5f84\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u5728\u5b89\u88c5\u65f6\u6307\u5b9a\u8def\u5f84\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u914d\u7f6eMPI\u73af\u5883<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u8fd0\u884cMPI\u7a0b\u5e8f\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u786e\u4fddMPI\u73af\u5883\u914d\u7f6e\u6b63\u786e\u3002\u8fd9\u5305\u62ec\u5c06MPI\u5e93\u7684\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u786e\u8ba4MPI\u7684\u5b89\u88c5\u60c5\u51b5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">mpicc -v<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001MPI4PY\u7684\u57fa\u672c\u4f7f\u7528<\/p>\n<\/p>\n<ol>\n<li><strong>\u521d\u59cb\u5316\u4e0e\u7ed3\u675f<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u4f7f\u7528mpi4py\u8fdb\u884c\u5e76\u884c\u8ba1\u7b97\u65f6\uff0c\u5fc5\u987b\u9996\u5148\u521d\u59cb\u5316MPI\u73af\u5883\uff0c\u5e76\u5728\u7a0b\u5e8f\u7ed3\u675f\u65f6\u9002\u5f53\u5173\u95edMPI\u73af\u5883\u3002\u8fd9\u901a\u5e38\u5728\u7a0b\u5e8f\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u5904\u8fdb\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from mpi4py import MPI<\/p>\n<p>comm = MPI.COMM_WORLD<\/p>\n<p>rank = comm.Get_rank()<\/p>\n<p>size = comm.Get_size()<\/p>\n<p>print(f&quot;Process {rank} of {size} is running&quot;)<\/p>\n<h2><strong>\u7ed3\u675f\u65f6\uff0c\u901a\u5e38\u4e0d\u9700\u8981\u663e\u5f0f\u8c03\u7528finalize\uff0c\u56e0\u4e3aPython\u4f1a\u81ea\u52a8\u5904\u7406<\/strong><\/h2>\n<h2><strong>MPI.Finalize()<\/strong><\/h2>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u57fa\u672c\u901a\u4fe1\u64cd\u4f5c<\/strong><\/li>\n<\/ol>\n<p><p>MPI\u63d0\u4f9b\u4e86\u591a\u79cd\u901a\u4fe1\u65b9\u5f0f\uff0c\u4f8b\u5982\u70b9\u5bf9\u70b9\u901a\u4fe1\u548c\u96c6\u4f53\u901a\u4fe1\u3002\u5728mpi4py\u4e2d\uff0c\u8fd9\u4e9b\u529f\u80fd\u90fd\u88ab\u5f88\u597d\u5730\u5c01\u88c5\u4e86\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u70b9\u5bf9\u70b9\u901a\u4fe1<\/strong><\/li>\n<\/ul>\n<p><p>\u70b9\u5bf9\u70b9\u901a\u4fe1\u662f\u6307\u4e24\u4e2a\u8fdb\u7a0b\u4e4b\u95f4\u76f4\u63a5\u7684\u6570\u636e\u4ea4\u6362\u3002\u5e38\u7528\u7684\u64cd\u4f5c\u5305\u62ec\u53d1\u9001\u548c\u63a5\u6536\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if rank == 0:<\/p>\n<p>    data = {&#39;key1&#39;: 1, &#39;key2&#39;: 2}<\/p>\n<p>    comm.send(data, dest=1, tag=11)<\/p>\n<p>elif rank == 1:<\/p>\n<p>    data = comm.recv(source=0, tag=11)<\/p>\n<p>    print(f&quot;Process 1 received data: {data}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>\u96c6\u4f53\u901a\u4fe1<\/strong><\/li>\n<\/ul>\n<p><p>\u96c6\u4f53\u901a\u4fe1\u6d89\u53ca\u591a\u4e2a\u8fdb\u7a0b\u7684\u53c2\u4e0e\uff0c\u4f8b\u5982\u5e7f\u64ad\u3001\u805a\u96c6\u3001\u6563\u64ad\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = None<\/p>\n<p>if rank == 0:<\/p>\n<p>    data = {&#39;key1&#39;: 1, &#39;key2&#39;: 2}<\/p>\n<p>data = comm.bcast(data, root=0)<\/p>\n<p>print(f&quot;Process {rank} received data: {data}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u5e38\u89c1\u7684MPI\u64cd\u4f5c<\/p>\n<\/p>\n<ol>\n<li><strong>\u5e7f\u64ad\uff08Broadcast\uff09<\/strong><\/li>\n<\/ol>\n<p><p>\u5e7f\u64ad\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u96c6\u4f53\u901a\u4fe1\u64cd\u4f5c\uff0c\u7528\u4e8e\u5c06\u6570\u636e\u4ece\u4e00\u4e2a\u8fdb\u7a0b\u53d1\u9001\u5230\u6240\u6709\u5176\u4ed6\u8fdb\u7a0b\u3002mpi4py\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u63a5\u53e3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = None<\/p>\n<p>if rank == 0:<\/p>\n<p>    data = &quot;Hello, World&quot;<\/p>\n<p>data = comm.bcast(data, root=0)<\/p>\n<p>print(f&quot;Process {rank} received data: {data}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6563\u64ad\uff08Scatter\uff09\u4e0e\u805a\u96c6\uff08Gather\uff09<\/strong><\/li>\n<\/ol>\n<p><p>Scatter\u548cGather\u662f\u96c6\u4f53\u901a\u4fe1\u64cd\u4f5c\uff0c\u5206\u522b\u7528\u4e8e\u5c06\u6570\u636e\u5206\u53d1\u7ed9\u591a\u4e2a\u8fdb\u7a0b\u548c\u4ece\u591a\u4e2a\u8fdb\u7a0b\u6536\u96c6\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if rank == 0:<\/p>\n<p>    data = [i for i in range(size)]<\/p>\n<p>else:<\/p>\n<p>    data = None<\/p>\n<p>recv_data = comm.scatter(data, root=0)<\/p>\n<p>print(f&quot;Process {rank} received data: {recv_data}&quot;)<\/p>\n<p>gathered_data = comm.gather(recv_data, root=0)<\/p>\n<p>if rank == 0:<\/p>\n<p>    print(f&quot;Gathered data: {gathered_data}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u89c4\u7ea6\u64cd\u4f5c\uff08Reduce\uff09<\/strong><\/li>\n<\/ol>\n<p><p>\u89c4\u7ea6\u64cd\u4f5c\u7528\u4e8e\u5bf9\u6765\u81ea\u591a\u4e2a\u8fdb\u7a0b\u7684\u6570\u636e\u8fdb\u884c\u5f52\u5e76\u64cd\u4f5c\uff0c\u4f8b\u5982\u6c42\u548c\u3001\u6c42\u6700\u5927\u503c\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">send_data = rank<\/p>\n<p>reduced_data = comm.reduce(send_data, op=MPI.SUM, root=0)<\/p>\n<p>if rank == 0:<\/p>\n<p>    print(f&quot;Sum of ranks: {reduced_data}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u5e76\u884c\u8ba1\u7b97\u4e2d\u7684\u5b9e\u7528\u6280\u5de7<\/p>\n<\/p>\n<ol>\n<li><strong>\u907f\u514d\u6b7b\u9501<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u5e76\u884c\u7f16\u7a0b\u4e2d\uff0c\u6b7b\u9501\u662f\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u3002\u4e3a\u4e86\u907f\u514d\u6b7b\u9501\uff0c\u5efa\u8bae\u9075\u5faa\u4ee5\u4e0b\u539f\u5219\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u6240\u6709\u7684\u53d1\u9001\u548c\u63a5\u6536\u64cd\u4f5c\u6210\u5bf9\u51fa\u73b0\u3002<\/li>\n<li>\u4f7f\u7528\u975e\u963b\u585e\u901a\u4fe1\uff0c\u4f8b\u5982<code>Isend<\/code>\u548c<code>Irecv<\/code>\uff0c\u6765\u907f\u514d\u8fdb\u7a0b\u963b\u585e\u3002<\/li>\n<\/ul>\n<ol start=\"2\">\n<li><strong>\u8c03\u8bd5\u4e0e\u6d4b\u8bd5<\/strong><\/li>\n<\/ol>\n<p><p>\u8c03\u8bd5\u5e76\u884c\u7a0b\u5e8f\u53ef\u80fd\u5f88\u56f0\u96be\uff0c\u56e0\u4e3a\u591a\u4e2a\u8fdb\u7a0b\u540c\u65f6\u8fd0\u884c\u3002\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u8c03\u8bd5\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728\u5173\u952e\u6b65\u9aa4\u6253\u5370\u8c03\u8bd5\u4fe1\u606f\u3002<\/li>\n<li>\u4f7f\u7528MPI\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u4f8b\u5982TotalView\u6216gdb\u3002<\/li>\n<\/ul>\n<ol start=\"3\">\n<li><strong>\u6027\u80fd\u4f18\u5316<\/strong><\/li>\n<\/ol>\n<p><p>\u4f18\u5316\u5e76\u884c\u7a0b\u5e8f\u7684\u6027\u80fd\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5c3d\u91cf\u51cf\u5c11\u8fdb\u7a0b\u95f4\u901a\u4fe1\u3002<\/li>\n<li>\u4f7f\u7528\u9002\u5f53\u7684\u6570\u636e\u5206\u5e03\u7b56\u7565\uff0c\u4ee5\u5747\u8861\u8d1f\u8f7d\u3002<\/li>\n<li>\u5229\u7528MPI\u63d0\u4f9b\u7684\u9ad8\u7ea7\u901a\u4fe1\u529f\u80fd\uff0c\u4f8b\u5982One-sided Communication\u3002<\/li>\n<\/ul>\n<p><p>\u4e94\u3001\u6269\u5c55\u4e0e\u9ad8\u7ea7\u5e94\u7528<\/p>\n<\/p>\n<ol>\n<li><strong>One-sided Communication<\/strong><\/li>\n<\/ol>\n<p><p>MPI\u7684\u4e00\u5927\u7279\u8272\u662f\u652f\u6301\u4e00\u5bf9\u591a\u7684\u901a\u4fe1\u6a21\u5f0f\uff0c\u79f0\u4e3a\u4e00\u8fb9\u901a\u4fe1\u3002\u8fd9\u79cd\u901a\u4fe1\u65b9\u5f0f\u53ef\u4ee5\u51cf\u5c11\u901a\u4fe1\u7684\u590d\u6742\u6027\u548c\u5f00\u9500\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">win = MPI.Win.Create(data, comm=comm)<\/p>\n<p>win.Fence()<\/p>\n<p>if rank == 0:<\/p>\n<p>    win.Put(data, target_rank, target_disp)<\/p>\n<p>win.Fence()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6df7\u5408\u7f16\u7a0b\u6a21\u578b<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u9ad8\u6027\u80fd\u8ba1\u7b97\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u7ed3\u5408\u591a\u79cd\u7f16\u7a0b\u6a21\u578b\uff0c\u4f8b\u5982MPI\u4e0eOpenMP\u7684\u7ed3\u5408\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5728\u8282\u70b9\u5185\u90e8\u4f7f\u7528\u591a\u7ebf\u7a0b\uff0c\u5728\u8282\u70b9\u4e4b\u95f4\u4f7f\u7528MPI\u901a\u4fe1\uff0c\u4ee5\u5145\u5206\u5229\u7528\u73b0\u4ee3\u591a\u6838\u5904\u7406\u5668\u7684\u8ba1\u7b97\u80fd\u529b\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u4f7f\u7528MPI\u4e0eGPU\u52a0\u901f<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u9700\u8981\u5927\u91cf\u8ba1\u7b97\u7684\u5e94\u7528\u4e2d\uff0c\u7ed3\u5408MPI\u4e0eGPU\u52a0\u901f\u6280\u672f\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6027\u80fd\u3002\u901a\u8fc7CUDA\u6216OpenCL\u4e0eMPI\u7684\u7ed3\u5408\uff0c\u53ef\u4ee5\u5728GPU\u4e0a\u8fdb\u884c\u5e76\u884c\u8ba1\u7b97\uff0c\u800c\u5728CPU\u4e4b\u95f4\u4f7f\u7528MPI\u8fdb\u884c\u901a\u4fe1\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u8c03\u7528MPI\uff0c\u53ef\u4ee5\u901a\u8fc7mpi4py\u5e93\u5b9e\u73b0\u3002\u5b83\u63d0\u4f9b\u4e86\u7b80\u5355\u6613\u7528\u7684\u63a5\u53e3\uff0c\u4f7f\u5f97Python\u7a0b\u5e8f\u5458\u80fd\u591f\u65b9\u4fbf\u5730\u8fdb\u884c\u5e76\u884c\u8ba1\u7b97\u3002\u5728\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u6ce8\u610fMPI\u73af\u5883\u7684\u914d\u7f6e\u3001\u5e38\u89c1\u7684\u901a\u4fe1\u64cd\u4f5c\u4ee5\u53ca\u5e76\u884c\u7f16\u7a0b\u4e2d\u7684\u4e00\u4e9b\u6280\u5de7\u548c\u4f18\u5316\u65b9\u6cd5\u3002\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u77e5\u8bc6\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u5229\u7528MPI\u5728Python\u4e2d\u5b9e\u73b0\u9ad8\u6548\u7684\u5e76\u884c\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b89\u88c5MPI\u5e93\u4ee5\u4fbf\u8c03\u7528\uff1f<\/strong><br \/>\u5728Python\u4e2d\u8c03\u7528MPI\u9700\u8981\u5b89\u88c5\u76f8\u5e94\u7684MPI\u5e93\uff0c\u5982<code>mpi4py<\/code>\u3002\u53ef\u4ee5\u901a\u8fc7Python\u7684\u5305\u7ba1\u7406\u5de5\u5177<code>pip<\/code>\u8fdb\u884c\u5b89\u88c5\u3002\u8fd0\u884c\u547d\u4ee4<code>pip install mpi4py<\/code>\u5373\u53ef\u3002\u786e\u4fdd\u5728\u5b89\u88c5\u4e4b\u524d\uff0c\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86MPI\u7684\u5b9e\u73b0\uff0c\u5982OpenMPI\u6216MPICH\u3002\u5982\u679c\u672a\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u5b89\u88c5\u5bf9\u5e94\u7684MPI\u5e93\u3002<\/p>\n<p><strong>\u4f7f\u7528MPI\u65f6\u5982\u4f55\u8fdb\u884c\u8fdb\u7a0b\u95f4\u901a\u4fe1\uff1f<\/strong><br \/>\u5728Python\u4e2d\u4f7f\u7528<code>mpi4py<\/code>\u8fdb\u884c\u8fdb\u7a0b\u95f4\u901a\u4fe1\uff0c\u53ef\u4ee5\u5229\u7528\u53d1\u9001\u548c\u63a5\u6536\u51fd\u6570\u3002\u4f7f\u7528<code>comm.send()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5c06\u6570\u636e\u4ece\u4e00\u4e2a\u8fdb\u7a0b\u53d1\u9001\u5230\u53e6\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u800c<code>comm.recv()<\/code>\u5219\u7528\u4e8e\u63a5\u6536\u6570\u636e\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u53d1\u9001\u548c\u63a5\u6536\u65f6\uff0c\u6307\u5b9a\u6b63\u786e\u7684\u8fdb\u7a0b\u7f16\u53f7\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u80fd\u591f\u6b63\u786e\u4f20\u9012\u3002<\/p>\n<p><strong>MPI\u7a0b\u5e8f\u7684\u5e76\u884c\u6267\u884c\u5982\u4f55\u7ba1\u7406\uff1f<\/strong><br \/>\u5728MPI\u4e2d\uff0c\u7ba1\u7406\u5e76\u884c\u6267\u884c\u901a\u5e38\u4f9d\u8d56\u4e8e\u5212\u5206\u4efb\u52a1\u7ed9\u4e0d\u540c\u7684\u8fdb\u7a0b\u3002\u53ef\u4ee5\u4f7f\u7528<code>comm.rank<\/code>\u83b7\u53d6\u5f53\u524d\u8fdb\u7a0b\u7684\u7f16\u53f7\uff0c\u901a\u8fc7<code>comm.size<\/code>\u83b7\u53d6\u8fdb\u7a0b\u603b\u6570\u3002\u6839\u636e\u8fd9\u4e9b\u4fe1\u606f\uff0c\u53ef\u4ee5\u5c06\u6570\u636e\u6216\u8ba1\u7b97\u4efb\u52a1\u5408\u7406\u5206\u914d\u5230\u5404\u4e2a\u8fdb\u7a0b\u4e2d\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u5206\u5e03\u5f0f\u6570\u636e\u5904\u7406\u7684\u65b9\u6cd5\uff0c\u5c06\u5927\u6570\u636e\u96c6\u5206\u5272\u6210\u5c0f\u5757\uff0c\u7531\u4e0d\u540c\u7684\u8fdb\u7a0b\u72ec\u7acb\u5904\u7406\uff0c\u6700\u540e\u518d\u6c47\u603b\u7ed3\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8c03\u7528MPI\uff08Message Passing Interface\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528mpi4py\u5e93\u3001\u901a\u8fc7 [&hellip;]","protected":false},"author":3,"featured_media":1012958,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1012951"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1012951"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1012951\/revisions"}],"predecessor-version":[{"id":1012961,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1012951\/revisions\/1012961"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1012958"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1012951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1012951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1012951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}