Kolorwanie:
Status:
12345678910111213141516171819202122232425262728293031323334353637
#include <iostream>
#include <mpi.h>

using namespace std;


int main()
{
	MPI_Init(NULL, NULL);

	int rank, size;
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Comm_size(MPI_COMM_WORLD, &size);

	int msg;

	if(rank == 0) 
	{		
		msg = 0;
		MPI_Send(&msg, 1, MPI_INT, 1, 88, MPI_COMM_WORLD);
	}
	else if(rank > 0 && rank < size - 1)
	{	
		MPI_Recv(&msg, 1, MPI_INT, rank-1, 88, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
		msg += rank;
		MPI_Send(&msg, 1, MPI_INT, rank+1, 88, MPI_COMM_WORLD);
	}
	else
	{
		MPI_Recv(&msg, 1, MPI_INT, rank-1, 88, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
		msg += rank;
		cout << "rank = " << rank << " msg = " << msg << endl;
	}

	MPI_Finalize();
}


Copyrights 2014-2020 © Wklejaj.pl Wszelkie prawa zastrzeżone.