Changes

Jump to: navigation, search

OpenMP Debugging in Visual Studio / Team Debug

257 bytes added, 14:44, 6 December 2017
Case B - Using the Parallel Stacks Window
}
==Case B - Using the Parallel Stacks and the Parallel Watch Window==
We will use the following program, which uses cilk API for parallelization, to experiment with the Parallel Stacks and the Parallel Watch Window:
// cilk threadscilkthreads.cpp
#include <iostream>
#include <thread> // std::this_thread::sleep_for
#include <chrono> // std::chrono::seconds
void int foo(int i); void int boo(int i); void int coo(int i); void int doo(int i); void int zoo(int i); void int bla(int i); void int blo(int i); void int blu(int i); void int vroom(int i); void int beep(int i); void int screech(int i); void int woof(int i); void int meow(int i); void int oink(int i); void int zzz(int i); void int cough(int i);
int main() {
int i = 12;
int nwt = __cilkrts_get_nworkers();
std::cout << "Number of workers is " << nwt << std::endl;
int a i = 1;
cilk_spawn foo(i); cilk_spawn coo(i); cilk_spawn boo(i); cilk_spawn doo(i); cilk_spawn zoo(i);
foo(i);
cilk_sync;
#pragma cilk grainsize = 3 cilk_for(int i = 0; i < 10; i++) { bla(); } return 0;
}
void int foo(int i) { ++i;
int tid = __cilkrts_get_worker_number();
std::this_thread::sleep_for(std::chrono::seconds(1));
printf("Foo! from worker %d\n", tid);
returni;
}
void int boo(int i) { i += 5;
int tid = __cilkrts_get_worker_number();
std::this_thread::sleep_for(std::chrono::seconds(1));
printf("Boo! from worker %d\n", tid);
i = zzz(i); returni ;
}
void int coo(int i) { i *= 10;
int tid = __cilkrts_get_worker_number();
std::this_thread::sleep_for(std::chrono::seconds(1));
printf("Coo! from worker %d\n", tid);
i = bla(i); returni;
}
void int doo(int i) { i *= 100;
int tid = __cilkrts_get_worker_number();
std::this_thread::sleep_for(std::chrono::seconds(1));
printf("Doo! from worker %d\n", tid);
i = vroom(i); returni;
}
void int zoo(int i) { --i;
int tid = __cilkrts_get_worker_number();
std::this_thread::sleep_for(std::chrono::seconds(1));
printf("Zoo! from worker %d\n", tid);
i = woof(i); i = meow(i); i = oink(i); returni;
}
void int bla(int i) { i *= 3;
int tid = __cilkrts_get_worker_number();
printf("Bla bla! from worker %d\n", tid);
i = blo(i); returni;
}
void int blo(int i) { i += 4;
int tid = __cilkrts_get_worker_number();
printf("Blo Blo! from worker %d\n", tid);
i = blu(i); returni;
}
void int blu(int i) { i *= 7;
int tid = __cilkrts_get_worker_number();
printf("Blu Blu! from worker %d\n", tid);
returni;
}
void int vroom(int i) { i += 5;
int tid = __cilkrts_get_worker_number();
printf("Vroom! from worker %d\n", tid);
i = beep(i); returni;
}
void int beep(int i) { i -= 2;
int tid = __cilkrts_get_worker_number();
printf("Beep beep! from worker %d\n", tid);
i = screech(i); returni;
}
void int screech(int i) { i -= 5; int tid = __cilkrts_get_worker_number();
printf("Screeeeeeeeechhhhhh! from worker %d\n", tid);
returni;
}
void int woof(int i) { i += 12;
int tid = __cilkrts_get_worker_number();
printf("Woof! from worker %d\n", tid); returni;
}
void int meow(int i) { i *= 6;
int tid = __cilkrts_get_worker_number();
printf("Meow! from worker %d\n", tid);
returni;
}
void int oink(int i) { i++;
int tid = __cilkrts_get_worker_number();
printf("Oink! from worker %d\n", tid);
returni;
}
void int zzz(int i) { i -= 10;
int tid = __cilkrts_get_worker_number();
for (int i = 0; i < 10; i++) {
cough(i);
}
printf("Zzzzzzzzz...... from worker %d\n", tid);
returni;
}
void int cough(int i) { i += 8;
int tid = __cilkrts_get_worker_number();
printf("cough! from worker %d\n", tid); returni;
}
 
In the above code, the main program calls functions that may themselves call other functions. At each cilk_spawn keyword, we can expect a new child thread to call the function. However, if the function have very short operations each, then the different spawns may not even be distributed to different child threads, since each function call may take very fast. That was originally the case, where all of the function calls were done by one thread. Therefore, the functions were adjusted to sleep for 1 second within the function itself. This way, the functions took long enough so that the program did spawn into multiple child threads.
92
edits

Navigation menu