I have two indepentend programs written in C++ that now have to be coupled during the runtiime via some kind of an interface. I tried to sketch it below with a pseudo-code:
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();
}
We need to add another function into the loop in program1.cpp
that uses the result of the program2.cpp
during the runtime at the same value of an iteration i
. For example, the modified loops of two programs would look like this:
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);
}
And in program2.cpp
it will be something like
for (i = 0; i < nIterations; i ++){
B = evenMoreComplexParallelCalculation();
OutputAndPostProcess(B);
//send data and iteration number to program1
sendBtoProgram1(B, i);
doSomeOtherStuff();
}
So I am wondering if it is possible to catch the variable B
during the runtime of the program2 and send it to program1. Note, that two programs are two huge projects that cannot be merged!
Or maybe some kind of an interface or a wrapper could be used (some kind of inter-program MPI_Send/Recv:)? I was also thinking about i/o to/from file. I would appritiate any ideas about it.