Simple MPI Send and Receive Programs Write a simple MPI send and receive programs.
The P.30 is almost the same as Du Zhihui Teacher.
One point, you want to see the effect, to ensure that the x is greater than 1 mpirun.exe -np x $ (targetpath). Ha ha.
#include #include #include #include #include int _tmain (int argc, _tchar * argv [ID , numprocs; int namelen; char processor_name [MPI_MAX_PROCESSOR_NAME]; char buff [100]; MPI_Init (& argc, & argv); MPI_Comm_rank (MPI_COMM_WORLD, & myid); MPI_Comm_size (MPI_COMM_WORLD, & numprocs); MPI_Get_processor_name (processor_name, & namelen); fprintf (stderr, "/ NHELLO World! Process% D OF% D ON% S / N", MyID, NumProcs, Processor_Name); MEMSET (BUFF, 0, 100); if (MyID == 0) {STRCPY (BUFF, "0 TO 1") MPI_SEND (BUFF, STRLEN (BUFF), MPI_CHAR, 1, 99, MPI_COMM_WORLD); FPRINTF (stderr, "/ nsend:% s", buff);} else {mpi_status sta; if (myid == 1) {MPI_RECV ( BUFF, 20, MPI_CHAR, 0, 99, MPI_COMM_WORLD, & STA); FPRINTF (stderr, "/ nRecv:% s", buff);}} MPI_Finalize (); if (myid == 0) {printf ("/ npress a Key and exit./N "); getCh ();} return 0;