Skip to content

Instantly share code, notes, and snippets.

@malleor
Created January 15, 2013 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malleor/4542884 to your computer and use it in GitHub Desktop.
Save malleor/4542884 to your computer and use it in GitHub Desktop.
//
// in ExecuteManager::Execute:
//
IAlgorithm& v_alg = ...
ParamsIn v_in = ...
Context v_ctx = ...
// static data init
v_alg.Startup(v_ctx, v_in);
// execute across multiple threads
Workers v_workers(N, v_alg); // creates N threads and calls v_alg.Execute in each thread
// <- set up a callback for the worker pool (v_workers)
//
// in the worker pool finish callback:
//
ParamsOut v_out;
bool v_success = p_alg.Teardown(v_out); // collect output
#include <frames.h>
class AlgorithmA :
public IAlgorithm
{
public:
AlgorithmA(); // ctor should be minimal
IAlgorithm::Manifest GetManifest() const; // author, version, mt (name not needed - it's 'moduleX.A')
bool Startup( // one-time call to Startup
IAlgorithm::Context& p_ctx, // executor, project, visualizer and log
const IAlgorithm::ParamsIn& p_in
);
void Execute( // Execute called once per worker thread
const IAlgorithm::ThreadInfo& p_thread // thread index, thread count (useful for thread-data mapping)
);
bool Teardown( // one-time call to Teardown
IAlgorithm::ParamsOut& p_out
);
}
extern "C"
__declspec(dllexport)
IAlgorithm* A() // algorithm 'moduleX.A'
{
return new AlgorithmA();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment