-
Notifications
You must be signed in to change notification settings - Fork 130
Closed
Description
Probably I misunderstand how parallelizing signals should be done. My issue is that the code below doesn't seem to parallelize. It is the example code from the README. As for the doCostlyOperation
, it just sleeps for 1 second.
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#if defined(WIN32)
#include <windows.h>
#elif !defined(WIN32)
#include <unistd.h>
void Sleep(int ms) {
usleep(1000*ms);
}
#endif
#include <react/Domain.h>
#include <react/Signal.h>
#include <react/Observer.h>
using namespace std;
using namespace react;
REACTIVE_DOMAIN(D, parallel)
USING_REACTIVE_DOMAIN(D)
int doCostlyOperation(int in) {
std::cout << "do " << in << std::endl;
Sleep(1000);
std::cout << "end " << in << std::endl;
return in;
}
VarSignalT<int> in = MakeVar<D>(0);
SignalT<int> op1 = MakeSignal(in,
[] (int in) {
return doCostlyOperation(in);
});
SignalT<int> op2 = MakeSignal(in,
[] (int in) {
return doCostlyOperation(in);
});
// op1 and op2 can be re-calculated in parallel
SignalT<int> out = op1 + op2;
int main()
{
in <<= 2;
}
The output I get is this:
do 0
end 0
do 0
end 0
do 2
end 2
do 2
end 2
Sleeps happen here:
do 0 # after this line
end 0
do 0 # after this line
end 0
do 2 # after this line
end 2
do 2 # after this line
end 2
I would expect the code above to do some of the tasks in parallel, but currently it acts as if it were sequential.
Metadata
Metadata
Assignees
Labels
No labels