C++ MPI_Send MPI_Recv 一个数

void t10(int argumentcount, char* argumentvector[]) {
	MPI_Init(&argumentcount, &argumentvector);

	int rank, num_process;
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Comm_size(MPI_COMM_WORLD, &num_process);
	// Read the local value of the process
	// local_value will hold a specific int for process 0, and another for process 1
	
	int a = 1;
	int b;
	if (rank == 0) {
		std::cout << "num_process=" << num_process << "\n";
		std::cout << "rank=" << rank << "\n";
	}
	MPI_Barrier(MPI_COMM_WORLD);
	if (rank == 0) {
		// Here, enter the code for the first process :
		// 1- Send the value to process 1 
		for (int i = 1; i < num_process;++i)
			MPI_Send(&a, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
		//MPI_Send(&a, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
		
	}
	else if (rank > 0) {
		// Here enter the code for the second process :
		// 1- Receive the value from process 0 (in other_value)
		MPI_Recv(&b, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
		
		std::cout <<"rank=" << rank << ", b=" <<  b <<  "\n";
	}


	MPI_Finalize();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值