⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 64.html

📁 国外MPI教材
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />	<style type="text/css">	body { font-family: Verdana, Arial, Helvetica, sans-serif;}	a.at-term {	font-style: italic; }	</style>	<title>Cartesian Mapping Functions</title>	<meta name="Generator" content="ATutor">	<meta name="Keywords" content=""></head><body> <h3>Computing ranks of neighboring processes</h3>

<p>The Cartisian mapping function does not actually shift the data: it returns the correct ranks for a shift which can be used in subsequent communication calls.</p>

<h3>Arguments:</h3>

<table class="info" >
<tr>
<td>direction</td>

<td>dimension in which the shift should be made</td>
</tr>

<tr>
<td>disp</td>

<td>length of the shift in processor coordinates (+ or -)</td>
</tr>

<tr>
<td>rank_source</td>

<td>where calling process should receive a message from during the shift</td>
</tr>

<tr>
<td>rank_dest</td>

<td>where calling process should send a message to during the shift</td>
</tr>
</table>

<p>If the shift goes off of the topology, MPI_PROC_NULL is returned.</p>

<p class="codelang">C:</p>

<pre><code>int MPI_Cart_shift(MPI_Comm comm, int direction, int disp, int rank_source, int *rank_dest)</code></pre>

<p class="codelang">
Fortran:</p>

<pre><code>INTEGER    COMM, DIRECTION, DISP, RANK_SOURCE, RANK_DEST, IERROR
CALL MPI_CART_RANK(COMM, DIRECTION, DISP, RANK_SOURCE, RANK_DEST, IERROR)</code></pre>

<h3>Sample Program - C</h3>

<pre><code>#include &lt;mpi.h&gt;
#include &lt;stdio.h&gt;
#define TRUE 1
#define FALSE 0
/* run with 12 processors */
int main(int argc, char *argv[]) {
  int rank;
  MPI_Comm vu;
  int dim[2],period[2],reorder;
  int up,down,right,left;
  MPI_Init(&amp;argc, &amp;argv);
  MPI_Comm_rank(MPI_COMM_WORLD,&amp;rank);
  dim[0]=4; dim[1]=3;
  period[0]=TRUE; period[1]=FALSE;
  reorder=TRUE;

  MPI_Cart_create(MPI_COMM_WORLD,2,dim,period,reorder,&amp;vu);

  if(rank==9){
      MPI_Cart_shift(vu,0,1,&amp;left,&amp;right);
      MPI_Cart_shift(vu,1,1,&amp;up,&amp;down);
      printf("P:%d My neighbors are r: %d d:%d 1:%d u:%d\n",rank,right,down,left,up);
  }

  MPI_Finalize();
}
</code></pre>

<h4>Program Output:</h4>

<pre><code>P:9 my neighbors are r:0 d:10 1:6 u:-1</code></pre>

<h3>Sample Program - Fortran</h3>
<pre><code>      PROGRAM neighbors
C
C Run with 12 processes
C
      INCLUDE 'mpif.h'
      INTEGER err, rank, size
      integer vu
      integer dim(2)
      logical period(2),reorder
      integer up,down,right,left

      CALL MPI_INIT(err)
      CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,err)
      CALL MPI_COMM_SIZE(MPI_COMM_WORLD,size,err)
      dim(1)=4
      dim(2)=3
      period(1)=.true.
      period(2)=.false.
      reorder=.true.
      call MPI_CART_CREATE(MPI_COMM_WORLD,2,dim,period,reorder,vu,err)

      if(rank.eq.9) then
          call MPI_CART_SHIFT(vu,0,1,left,right,err)
          call MPI_CART_SHIFT(vu,1,1,up,down,err)
          print*,'P:',rank,' neighbors (rdlu)are',right,down,left,up
      end if

      CALL MPI_FINALIZE(err)
      END</code></pre>

<h4>Program Output:</h4>

<pre><code>P:9 neighbors (rdlu) are 0, 10, 6, -1</code></pre></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -