main.cpp 994 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <thallium.hpp>

namespace tl = thallium;

void hello() {
    tl::xstream es = tl::xstream::self();
    std::cout << "Hello World from ES " 
        << es.get_rank() << ", ULT " 
        << tl::thread::self_id() << std::endl;
}

int main(int argc, char** argv) {

    tl::engine myEngine("tcp", THALLIUM_CLIENT_MODE);

    std::vector<tl::managed<tl::xstream>> ess;

    tl::managed<tl::pool> myPool = tl::pool::create(tl::pool::access::spmc);

    for(int i=0; i < 4; i++) {
        tl::managed<tl::xstream> es 
            = tl::xstream::create(tl::scheduler::predef::deflt, *myPool);
        ess.push_back(std::move(es));
    }

    std::vector<tl::managed<tl::thread>> ths;
    for(int i=0; i < 16; i++) {
        tl::managed<tl::thread> th = ess[i % ess.size()]->make_thread(hello);
        ths.push_back(std::move(th));
    }

    for(auto& mth : ths) {
        mth->join();
    }

    for(int i=0; i < 4; i++) {
        ess[i]->join();
    }

    return 0;
}