我正在尝试使用MPI_Sendrecv
在进程之间交换数据,但陷入了发送和接收逻辑中。
假设我们有四个进程,每个进程都有2个大小为4的一维数组:Params
和Params_
。 Params
的条目将被初始化为rank * 4 + i
(例如,在进程等级0,Params = {0,1,2,3}
中),而Params_
用于存储由Params
发送的params
其他过程。每个进程都将params
发送给其他进程,并从其他进程接收#include<mpi.h>
#include<stdio.h>
int main(int argc, char **argv){
int my_rank, ncpus;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &ncpus);
double *params;
double *params_;
int Nparams = 4;
params = new double[Nparams];
params_ = new double[Nparams];
// Initialize params and print it
printf("ID %d: ", my_rank);
for (int i = 0; i < Nparams; i++) {
params[i] = my_rank * ncpus + i;
printf("%g ", params[i]);
}
printf("\n");
// Receive params from the other processes, store it in params_, and print it
for (int i = 0; i < ncpus; i++) {
MPI_Sendrecv(params, Nparams, MPI_DOUBLE, i, 0, params_, Nparams, MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &status);
printf("Receive params from %d: ", i);
for (int i = 0; i < Nparams; i++)
printf("%g ", params_[i]);
printf("\n");
}
delete[] params;
delete[] params_;
MPI_Finalize();
return 0;
}
。代码如下。
Params
代码的输出未显示任何内容(甚至无法打印出WARNING: There was an error initializing an OpenFabrics device
),并且有很多警告,例如 if (userManager.isLoggedIn()) {
notificationsRefreshSubscription = Observable
.interval(0, 10, TimeUnit.SECONDS)
.subscribeOn(ioScheduler)
.flatMap {
return@flatMap service.checkForNewNotifications(
token = userManager.getUser().takeToken(),
locale = userManager.getUserLanguageCode())
}
.observeOn(uiScheduler)
.subscribe({
listener?.onNewNotificationsReceived(it.count)
}, {
// Empty
})
}
。您能帮我弄清楚为什么它不起作用以及我应该怎么做。非常感谢!