#include "iostream"
#include <mpi.h>


int main(int argc, char ** argv)
{
	int myRank = 0, size = 0;
	int variable = 0;
    int message = 15;
	int message2 = 16;
	MPI_Win window;
	int destinationRank = 0;

	MPI_Init(&argc, &argv);

	MPI_Comm_size(MPI_COMM_WORLD, &size);
	MPI_Comm_rank(MPI_COMM_WORLD, &myRank);

	if (myRank == 0) 
	{
		MPI_Win_create(&variable, sizeof(MPI_INT), sizeof(MPI_INT), MPI_INFO_NULL, MPI_COMM_WORLD, &window);	//	collective operation
		std::cout << "Process " << myRank << " has value = " << variable << std::endl;
		MPI_Win_fence(0, window);
		MPI_Win_fence(0, window);
		std::cout << "Process " << myRank << " has value = " << variable << " after PUT" << std::endl;
	}
	else
	{
		MPI_Win_create(&variable, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &window);
		MPI_Win_fence(0, window);
		MPI_Put(&message, 1, MPI_INT, destinationRank, 0, 1, MPI_INT, window);
		MPI_Win_fence(0, window);
	}

	MPI_Win_free(&window);
	MPI_Finalize();
	return 0;
}

