[Openmp-commits] [openmp] r274151 - Fix omp_sections_nowait.c test to address Bugzilla Bug 28336

Hal Finkel via Openmp-commits openmp-commits at lists.llvm.org
Thu Jun 30 17:26:31 PDT 2016


Hi Jonathan,

Can you please apply a similar rewrite to this other nowait test?

  runtime/test/worksharing/for/omp_for_nowait.c

I now see that this one also nondeterministically fails, and it looks like it is the same problem (the reliance on a sleep).

Thanks again,
Hal

----- Original Message -----
> From: "Jonathan Peyton via Openmp-commits" <openmp-commits at lists.llvm.org>
> To: openmp-commits at lists.llvm.org
> Sent: Wednesday, June 29, 2016 2:46:53 PM
> Subject: [Openmp-commits] [openmp] r274151 - Fix omp_sections_nowait.c test to address Bugzilla Bug 28336
> 
> Author: jlpeyton
> Date: Wed Jun 29 14:46:52 2016
> New Revision: 274151
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=274151&view=rev
> Log:
> Fix omp_sections_nowait.c test to address Bugzilla Bug 28336
> 
> This rewrite of the omp_sections_nowait.c test file causes it to hang
> if the
> nowait is not respected. If the nowait isn't respected, the lone
> thread which
> can escape the first sections construct will just sleep at a barrier
> which
> shouldn't exist. All reliance on timers is taken out. For good
> measure, the test
> makes sure that all eight sections are executed as well. The test
> should take no
> longer than a few seconds on any modern machine.
> 
> Differential Revision: http://reviews.llvm.org/D21842
> 
> Modified:
>     openmp/trunk/runtime/test/worksharing/sections/omp_sections_nowait.c
> 
> Modified:
> openmp/trunk/runtime/test/worksharing/sections/omp_sections_nowait.c
> URL:
> http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/test/worksharing/sections/omp_sections_nowait.c?rev=274151&r1=274150&r2=274151&view=diff
> ==============================================================================
> ---
> openmp/trunk/runtime/test/worksharing/sections/omp_sections_nowait.c
> (original)
> +++
> openmp/trunk/runtime/test/worksharing/sections/omp_sections_nowait.c
> Wed Jun 29 14:46:52 2016
> @@ -1,18 +1,45 @@
>  // RUN: %libomp-compile-and-run
>  #include <stdio.h>
>  #include "omp_testsuite.h"
> -#include "omp_my_sleep.h"
>  
> -int test_omp_sections_nowait()
> +/*
> + * This test will hang if the nowait is not working properly
> + *
> + * It relies on a thread skipping to the second sections construct
> to
> + * release the threads in the first sections construct
> + *
> + * Also, since scheduling of sections is implementation defined, it
> is
> + * necessary to have all four sections in the second sections
> construct
> + * release the threads since we can't guarantee which section a
> single thread
> + * will execute.
> + */
> +volatile int release;
> +volatile int count;
> +
> +void wait_for_release_then_increment(int rank)
> +{
> +  fprintf(stderr, "Thread nr %d enters first section"
> +    " and waits.\n", rank);
> +  while (release == 0);
> +  #pragma omp atomic
> +  count++;
> +}
> +
> +void release_and_increment(int rank)
>  {
> -  int result;
> -  int count;
> -  int j;
> +  fprintf(stderr, "Thread nr %d sets release to 1\n", rank);
> +  release = 1;
> +  #pragma omp flush(release)
> +  #pragma omp atomic
> +  count++;
> +}
>  
> -  result = 0;
> +int test_omp_sections_nowait()
> +{
> +  release = 0;
>    count = 0;
>  
> -  #pragma omp parallel
> +  #pragma omp parallel num_threads(4)
>    {
>      int rank;
>      rank = omp_get_thread_num ();
> @@ -20,18 +47,22 @@ int test_omp_sections_nowait()
>      {
>        #pragma omp section
>        {
> -        fprintf(stderr, "Thread nr %d enters first section"
> -          " and gets sleeping.\n", rank);
> -        my_sleep(SLEEPTIME);
> -        count = 1;
> -        fprintf(stderr, "Thread nr %d woke up an set"
> -          " count to 1.\n", rank);
> -        #pragma omp flush(count)
> +        wait_for_release_then_increment(rank);
> +      }
> +      #pragma omp section
> +      {
> +        wait_for_release_then_increment(rank);
>        }
>        #pragma omp section
>        {
> -        fprintf(stderr, "Thread nr %d executed work in the"
> -          " first section.\n", rank);
> +        wait_for_release_then_increment(rank);
> +      }
> +      #pragma omp section
> +      {
> +        fprintf(stderr, "Thread nr %d enters first sections and goes
> "
> +          "immediately to next sections construct to release.\n",
> rank);
> +        #pragma omp atomic
> +        count++;
>        }
>      }
>      /* Begin of second sections environment */
> @@ -39,20 +70,24 @@ int test_omp_sections_nowait()
>      {
>        #pragma omp section
>        {
> -        fprintf(stderr, "Thread nr %d executed work in the"
> -          " second section.\n", rank);
> +        release_and_increment(rank);
> +      }
> +      #pragma omp section
> +      {
> +        release_and_increment(rank);
> +      }
> +      #pragma omp section
> +      {
> +        release_and_increment(rank);
>        }
>        #pragma omp section
>        {
> -        fprintf(stderr, "Thread nr %d executed work in the"
> -          " second section and controls the value of count\n",
> rank);
> -        if (count == 0)
> -          result = 1;
> -        fprintf(stderr, "count was %d\n", count);
> +        release_and_increment(rank);
>        }
>      }
>    }
> -  return result;
> +  // Check to make sure all eight sections were executed
> +  return (count==8);
>  }
>  
>  int main()
> 
> 
> _______________________________________________
> Openmp-commits mailing list
> Openmp-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-commits
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory


More information about the Openmp-commits mailing list