# MPI_Alltoall ![](https://i.imgur.com/v5lrj1Z.png) [MPI_Alltoall](https://www.mpich.org/static/docs/v3.4.1/www3/MPI_Ialltoall.html) MPI_Alltoall(void* sendBuf, int sendCount,MpIDatatype sendType,void* recvBufm, int recvCount,MPI_Datatype recvType,MPI_Commcomm) ### Comm: ##### Communicator over which data is to be exchanged (handle). ##### EX: MPI_COMM_WROLD ``` MPI_Comm_size(comm, &n); for (i = 0, i < n; i++) MPI_Send(sendbuf + i * sendcount * extent(sendtype), sendcount, sendtype, i, ..., comm); for (i = 0, i < n; i++) MPI_Recv(recvbuf + i * recvcount * extent(recvtype), recvcount, recvtype, i, ..., comm); ``` ``` % mpicc hello.c % cat nodefile node1 node2 % mpirun -np 1 -hostfile nodefile a.out(由1節點來執行) Hello World from node1 % mpirun -np 2 -hostfile nodefile a.out(由2節點來執行) Hello World from node1 Hello World from node2 ```