Im trying to create a programm that displays value from different thread every second, as an attempt at progress tracking functionality, but unfortunatly i cant seam to correctly parallelise this case at all.
Here is my attempt:
#include <stdio.h>
#include <omp.h>
int i;
void print_every_second() {
while(i<10000000) {
#pragma omp flush
printf("%d!n",i);
sleep(1);
}
}
void increment_to_10_million() {
#pragma omp parallel for
for( i = 1; i <= 10000000; ++i) {
}
}
int main() {
#pragma omp parallel sections
{
#pragma omp section
increment_to_10_million();
#pragma omp section
print_every_second();
}
printf("Both threads have finished.n");
return 0;
}
Functions end up not beign parallelised and only print_every_second ends up executing, at all. It is tested in VirtualBox with AMD Ryzen™ 7 2700 × 4 and gcc (Debian 12.2.0-14) 12.2.0