C# NET如何使进程以任意顺序发送数据?
我正在使用C# NET如何使进程以任意顺序发送数据?,c#,mpi,C#,Mpi,我正在使用mpi.net。我希望每个处理器(proc 0除外)以任意顺序向进程0发送数据。下面是一段简化的代码: if (rank == 0) { int all = nTasks-1; //wich is the number of processes -1 while (all > 0) { Comm
mpi.net
。我希望每个处理器(proc 0除外)以任意顺序向进程0发送数据。下面是一段简化的代码:
if (rank == 0)
{
int all = nTasks-1; //wich is the number of processes -1
while (all > 0)
{
Communicator.world.Receive<Pixelator>(Communicator.anySource, 1, out pixelus);
if (pixelus.x == -1)
{
all--;
}
}
}
else
{
for (int i = 0; i < 5; i++)
{
Communicator.world.Send<Pixelator>(some_data, 0, 1);
}
Communicator.world.Send<Pixelator>(-1, 0, 1);
}
if(秩==0)
{
int all=nTasks-1;//其中是进程数-1
而(全部>0)
{
Communicator.world.Receive(Communicator.anySource,1,out pixelus);
if(pixelus.x==-1)
{
全部--;
}
}
}
其他的
{
对于(int i=0;i<5;i++)
{
Communicator.world.Send(一些_数据,0,1);
}
Communicator.world.Send(-1,0,1);
}
问题是进程0一次从另一个进程接收所有信息,然后在从另一个进程接收数据时向前移动。例如,进程0获取
1 1 1 2 2 2 5 5 5 5 4 4 4 4 3 3 3 3(这些是发送数据的进程的级别)。我希望它是1 5 2 3 1 4 3…或任意顺序。。。有什么建议吗?看看。有一种方法可以阻止进程在到达某个计算点时执行进一步的操作,直到所有其他进程都到达同一点。
希望能对你有所帮助。您的代码可能如下所示:
if (rank == 0)
{
int all = nTasks-1; //wich is the number of processes -1
while (all > 0)
{
Communicator.world.Receive<Pixelator>(Communicator.anySource, 1, out pixelus);
if (pixelus.x == -1)
{
all--;
}
}
}
else
{
for (int i = 0; i < 5; i++)
{
Communicator.world.Send<Pixelator>(some_data, 0, 1);
//Here's the barrier
Communicator.Barrier();
}
Communicator.world.Send<Pixelator>(-1, 0, 1);
}
if(秩==0)
{
int all=nTasks-1;//其中是进程数-1
而(全部>0)
{
Communicator.world.Receive(Communicator.anySource,1,out pixelus);
if(pixelus.x==-1)
{
全部--;
}
}
}
其他的
{
对于(int i=0;i<5;i++)
{
Communicator.world.Send(一些_数据,0,1);
//这是障碍
沟通障碍();
}
Communicator.world.Send(-1,0,1);
}
它肯定会提供类似于您的输出的东西。但是,如果障碍不适合,我只能猜测将更多的工作交给流程,这样它们就没有更多的时间相互交流。我不太熟悉mpi.net,但是您发布的代码应该允许任何顺序。您是否在同一台机器上运行所有进程?如果是这样,那么调度器就可以一次性完成每个节点的作业。试着在worker节点的
中为
循环做一个短暂的(~1秒)睡眠。当我试着睡觉时,这个想法突然出现在我的脑海中。但是我的程序做了一些图像变形,速度必须很快。如果我找不到更好的解决方案,我会这样做,因为我必须在明天的考试中展示这个项目……睡眠只用于证明消息可以以任何顺序接收,不需要在最终代码中。这个解决方案是为了更好的视觉效果,所以我放了睡眠(1)。谢谢你的介入