mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-16 14:16:09 -06:00
34 lines
746 B
C++
34 lines
746 B
C++
#include <Core/Core.h>
|
|
|
|
using namespace Upp;
|
|
|
|
struct Model { // some computation model that is not stateless, abstract definition
|
|
virtual void Start(int i) = 0;
|
|
virtual int Compute() = 0;
|
|
};
|
|
|
|
struct Model1 : Model { // concrete model (there would be more)
|
|
int n;
|
|
|
|
virtual void Start(int i) { n = i; }
|
|
virtual int Compute() { return n++; }
|
|
};
|
|
|
|
CONSOLE_APP_MAIN
|
|
{
|
|
Vector<int> data;
|
|
data.SetCount(3000);
|
|
|
|
CoWorkerResources<One<Model>> res;
|
|
for(auto& r : res)
|
|
r.Create<Model1>();
|
|
|
|
CoPartition(0, data.GetCount(), [&data, &res](int l, int h) {
|
|
Model& m = *~res; // gets resource unique for worker
|
|
m.Start(l);
|
|
for(int i = l; i < h; i++)
|
|
data[i] = m.Compute();
|
|
});
|
|
|
|
DUMP(data);
|
|
}
|