Skip to main content
4 of 7
edited tags
priyanka
  • 215
  • 1
  • 5

OpenMP parallel for critical section and use of flush

The following is my code. I am not sure about the place where flush should be used(if it is used at all here)

int Window_Shift :: get_window_shift()
{
    int window_shift = INFINITE;    

    #pragma omp parallel for
    for(unsigned int node_id = 0;node_id< no_of_valid_nodes ;node_id++) 
    {
        //for all the nodes that can be extended
        //finds the minimum possible window shift
        if(can_node_determine_window_shift(node_id) == true)
        {
            int node_window_shift = get_window_shift_for_node(node_id);
            #pragma omp flush(window_shift)
            #pragma omp critical(get_window_shift_for_node)
            {
            window_shift = min(window_shift,node_window_shift);
            #pragma omp flush(window_shift)
            }
        }
    }

Please review the code, specially the flush commands.Should atomic be used instead of critical section.

priyanka
  • 215
  • 1
  • 5