-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2d_for.cpp
More file actions
38 lines (30 loc) · 1011 Bytes
/
Copy path2d_for.cpp
File metadata and controls
38 lines (30 loc) · 1011 Bytes
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
//
// Created by blackgeorge on 7/6/19.
//
#include <mutex>
#include <iostream>
#include <thread>
#include <tbb/parallel_for.h>
#include <tbb/task_scheduler_init.h>
#include <tbb/blocked_range2d.h>
#include <atomic> // !!!
std::mutex cout_mutex;
int main()
{
auto N = 3;
auto M = 4;
tbb::task_scheduler_init init(4);
tbb::parallel_for(tbb::blocked_range2d<int>(0, N, 0, M),
[&](const tbb::blocked_range2d<int>& r)
{
for(int j=r.rows().begin(), j_end=r.rows().end(); j<j_end; j++){
for(int k=r.cols().begin(), k_end=r.cols().end(); k<k_end; k++){
std::this_thread::sleep_for(std::chrono::seconds(1));
cout_mutex.lock();
std::cout << std::this_thread::get_id() << ", " << j << ", " << k << std::endl;
cout_mutex.unlock();
}
}
}
);
}