Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <list>
- #include "tbb/task_scheduler_init.h"
- #include "tbb/tick_count.h"
- #include "tbb/task.h"
- #include <mutex>
- using namespace tbb;
- using namespace std;
- #define WORKLOAD 100000000
- mutex term_m;
- void do_work() {
- for (int i = 0; i<WORKLOAD; i++) {
- ;
- }
- }
- class Dummy : public tbb::task {
- public:
- char naziv_cvora;
- tbb::task* successor;
- Dummy(char _naziv_cvora) : naziv_cvora(_naziv_cvora) {};
- tbb::task* execute() {
- if (successor != NULL) {
- if (successor->decrement_ref_count() == 0)
- spawn(*successor);
- }
- cout << "Ja sam cvor " << naziv_cvora << "!\n";
- do_work();
- return NULL;
- }
- };
- void serial() {
- //ToDo: Replace with actual tasks
- Dummy *t0 = new(tbb::task::allocate_root()) Dummy('F');
- t0->execute();
- t0->destroy(*t0);
- Dummy *t1 = new(tbb::task::allocate_root()) Dummy('C');
- t1->execute();
- t1->destroy(*t1);
- Dummy *t2 = new(tbb::task::allocate_root()) Dummy('D');
- t2->execute();
- t2->destroy(*t2);
- Dummy *t3 = new(tbb::task::allocate_root()) Dummy('A');
- t3->execute();
- t3->destroy(*t3);
- Dummy *t4 = new(tbb::task::allocate_root()) Dummy('B');
- t4->execute();
- t4->destroy(*t4);
- return;
- }
- tbb::empty_task* StartSideShow() {
- tbb::empty_task* parent = new(tbb::task::allocate_root()) tbb::empty_task;
- parent->set_ref_count(3);
- Dummy* a = new(parent->allocate_root()) Dummy('A');
- a->successor = parent;
- Dummy* b = new(parent->allocate_root()) Dummy('B');
- b->successor = parent;
- Dummy* c = new(tbb::task::allocate_root()) Dummy('C');
- c->successor = parent;
- a->set_ref_count(1);
- b->set_ref_count(1);
- Dummy* d = new(tbb::task::allocate_root()) Dummy('D');
- Dummy* f = new(tbb::task::allocate_root()) Dummy('F');
- d->successor = b;
- f->successor = c;
- parent->spawn(*d);
- parent->spawn(*f);
- return parent;
- }
- void BuildAndEvaluateDAG() {
- //ToDo: Add code here
- tbb::empty_task* em_tsk = StartSideShow();
- em_tsk->wait_for_all();
- em_tsk->destroy(*em_tsk);
- return;
- }
- void parallel() {
- BuildAndEvaluateDAG();
- return;
- }
- int main(int argc, char* argv[]) {
- tick_count startTime = tick_count::now();
- serial();
- tick_count stopTime = tick_count::now();
- cout << "serial finished. Took: " <<
- (stopTime - startTime).seconds() * 1000 << "ms." << endl;
- startTime = tick_count::now();
- parallel();
- stopTime = tick_count::now();
- cout << "parallel finished. Took: " <<
- (stopTime - startTime).seconds() * 1000 << "ms." << endl;
- cout << "Nina je najveci car na svetuuuu hhehe :D"<<endl;
- cin.get();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement