class gpr::linalg::TilePool

Overview

Runs fn(0) .. More…

#include <gpr/linalg/TileParallel.h>
 
class TilePool {
public:
    // construction
 
    TilePool(const TilePool&);
    ~TilePool();
 
    // methods
 
    static TilePool& instance();
 
    template <class F>
    void run(long count, F&& fn);
 
    template <class F>
    void runWith(int threads, long count, F&& fn);
 
    template <class F>
    void start(long count, F&& fn);
 
    void finish();
    TilePool& operator=(const TilePool&);
};

Detailed Documentation

Runs fn(0) .. fn(count - 1) on the calling thread and a small pool of workers. Items are claimed from a shared counter, so the item-to-thread assignment varies between runs; the callers pass items that write disjoint output and run each item’s arithmetic on one thread, which makes the result independent of the thread count. Called from a worker, or with one thread configured, the items run in order on the calling thread.

Methods

template <class F>
void runWith(int threads, long count, F&& fn)

run() with an explicit thread count in place of the configured one.

template <class F>
void start(long count, F&& fn)

Starts fn(0) .. fn(count - 1) on the workers and returns at once; the calling thread joins with finish(), which runs the items no worker has claimed and waits for the rest. Between the two calls, loops started by the calling thread run serially on it, which leaves it free for communication and for work the items do not touch. fn must stay valid until finish() returns. With one thread configured, or from inside a worker, every item runs in finish().

void finish()

Joins the items of start(); see there.