我有两个用 C++ 编写的独立程序,现在必须在运行时通过某种接口进行耦合。我试图用伪代码在下面画出它:
program1.cpp:
program1(){
initializeProgram1();
for (i = 0; i < nIterations; i ++){
A = veryComplexParallelCalculation();
postProcessAndOutput(A);
}
finishProgram1();
}
program2.cpp:
program2(){
prepareProgram2();
for (i = 0; i < nIterations; i ++){
B = evenMoreComplexParallelCalculation();
OutputAndPostProcess(B);
}
finishProgram2();
}
我们需要在循环中添加另一个函数,该函数在运行时使用相同迭代值的program1.cpp
结果。例如,两个程序的修改循环如下所示:program2.cpp
i
for (i = 0; i < nIterations; i ++){
A = veryComplexParallelCalculation();
postProcessAndOutput(A);
//iB is the iteration number from program2
getBfromProgram2(B, iB);
if (iB == i )
C = foo(A ,B);
}
program2.cpp
里面会是这样的
for (i = 0; i < nIterations; i ++){
B = evenMoreComplexParallelCalculation();
OutputAndPostProcess(B);
//send data and iteration number to program1
sendBtoProgram1(B, i);
doSomeOtherStuff();
}
所以我想知道是否可以B
在程序2的运行时捕获变量并将其发送到程序1。请注意,两个程序是两个不能合并的巨大项目!
或者也许可以使用某种接口或包装器(某种程序间 MPI_Send/Recv :)?我也在考虑 i/o to/from 文件。我会 appritiate 任何关于它的想法。