| |
ðÒÉÍÅÒ 1Á:
main(int argc, char **argv) { int me, size; ... MPI_Init (&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &me); MPI_Comm_size (MPI_COMM_WORLD, &size); (void)printf ("Process %d size %d\n", me, size); ... MPI_Finalize(); }
ðÒÉÍÅÒ 1a Ñ×ÌÑÅÔÓÑ ÐÒÏÇÒÁÍÍÏÊ, ËÏÔÏÒÁÑ ÉÎÉÃÉÁÌÉÚÉÒÕÅÔÓÑ, ÏÂÒÁÝÁÅÔÓÑ Ë ``ÏÂÝÅÍÕ'' ËÏÍÍÕÎÉËÁÔÏÒÕ É ÐÅÞÁÔÁÅÔ ÓÏÏÂÝÅÎÉÅ.
ðÒÉÍÅÒ 1b (ÐÒÅÄÐÏÌÁÇÁÅÔÓÑ, ÞÔÏ ÁÒÇÕÍÅÎÔ size ÞÅÔÎÙÊ):
main(int argc, char **argv) { int me, size; int SOME_TAG = 0; ... MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &me); /* ÌÏËÁÌØÎÏ */ MPI_Comm_size(MPI_COMM_WORLD, &size); /* ÌÏËÁÌØÎÏ */ if((me % 2) == 0) { /* ÐÏÓÙÌÁÔØ ×ÐÌÏÔØ ÄÏ ÐÒÏÃÅÓÓÁ Ó ÓÁÍÙÍ ÓÔÁÒÛÉÍ ÎÏÍÅÒÏÍ */ if((me + 1) < size) MPI_Send(..., me + 1, SOME_TAG, MPI_COMM_WORLD); } else MPI_Recv(..., me - 1, SOME_TAG, MPI_COMM_WORLD); ... MPI_Finalize(); }
ðÒÉÍÅÒ 1b ÓÈÅÍÁÔÉÞÎÏ ÉÌÌÀÓÔÒÉÒÕÅÔ ÏÂÍÅÎÙ ÓÏÏÂÝÅÎÉÑÍÉ ÍÅÖÄÕ ``ÞÅÔÎÙÍÉ'' É ``ÎÅÞÅÔÎÙÍÉ'' ÐÒÏÃÅÓÓÁÍÉ × ``ÏÂÝÅÍ'' ËÏÍÍÕÎÉËÁÔÏÒÅ.
úÁËÌÁÄËÉ ÎÁ ÓÁÊÔÅ ðÒÏÓÌÅÄÉÔØ ÚÁ ÓÔÒÁÎÉÃÅÊ |
Created 1996-2024 by Maxim Chirkov äÏÂÁ×ÉÔØ, ðÏÄÄÅÒÖÁÔØ, ÷ÅÂÍÁÓÔÅÒÕ |