1

I am using OpenMP to perform a time consuming operation. I am unable to update a ProgressBar from GTK+ from within the time consuming loop at the same time the operations are carried out. The code I have updtates the ProgressBar, but it does so after everything is done. Not as the code progresses.

This is my dummy code that doesn't update the ProgressBar until everything is done:

void largeTimeConsumingFunction (GtkProgressBar** progressBar) {

    int extensiveOperationSize = 1000000;

    #pragma omp parallel for ordered schedule(dynamic)
    for (int i = 0; i < extensiveOperationSize; i++) {
        // Do something that will take a lot of of time with data

        #pragma omp ordered
        {        
            // Update the progress bar
            gtk_progress_bar_set_fraction(*progressBar, i/(double)extensiveOperationSize);
        }

    }
}

When I do the same, but without using OpenMP, the same happens. It doesn't get updated until the end.

How could I get that GTK+ Widget to update at the same time the loop is working?

Edit: This is just a dummy code to keep it short and readable. It has the same structure as my actual code, but in my actual code I don't know before hand the size of the items I will be processing. It could be 10 or more than 1 million items and I will have to perform some action for each of them.

g_l
  • 621
  • 5
  • 15
  • Regardless of the GTK+ issues, you should uses `#pragma omp ordered` instead of `#pragma omp critical` inside the loop if you want the progress bar to increase monotonically! Although I wouldn't recommend ordered, as it can be decremental to performance. – Zulan May 19 '17 at 08:15
  • Thanks for the tip. I will change it as so. Critical indeed is not in an ordered fashion, but I wonder... If I already have ordered above, would that mean the critical is being executed in an ordered manner? Or is it still one thread randomly entering that critical region? In simpler words I don't know if the declared ordered region that I made covers that critical region too and as such, the threads accessing critical are in order. – g_l May 19 '17 at 17:49
  • A `parallel for ordered` is meaningless without a `ordered` construct. – Zulan May 19 '17 at 17:56
  • I understand. Thanks. – g_l May 19 '17 at 19:55

1 Answers1

1

There are two potential issues here:

First, if you are performing long running computations that might block main thread, you have to call

while (gtk_events_pending ())
  gtk_main_iteration ();

every now and then to keep UI responsive (which includes redrawing itself).

Second, you should call GTK+ functions only from main thread.

Community
  • 1
  • 1