brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 584eceb Raw
79 lines · c
1// RUN: %libomp-compile-and-run2 3// This test is known to be fragile on NetBSD kernel at the moment,4// https://bugs.llvm.org/show_bug.cgi?id=42020.5// UNSUPPORTED: netbsd6#include <stdio.h>7#include <math.h>8#include "omp_testsuite.h"9#include "omp_my_sleep.h"10 11int test_omp_taskwait()12{13  int result1 = 0;   /* Stores number of not finished tasks after the taskwait */14  int result2 = 0;   /* Stores number of wrong array elements at the end */15  int array[NUM_TASKS];16  int i;17 18  /* fill array */19  for (i = 0; i < NUM_TASKS; i++)20    array[i] = 0;21 22  #pragma omp parallel23  {24    #pragma omp single25    {26      for (i = 0; i < NUM_TASKS; i++) {27        /* First we have to store the value of the loop index in a new variable28         * which will be private for each task because otherwise it will be overwritten29         * if the execution of the task takes longer than the time which is needed to30         * enter the next step of the loop!31         */32        int myi;33        myi = i;34        #pragma omp task35        {36          my_sleep (SLEEPTIME);37          array[myi] = 1;38        } /* end of omp task */39      } /* end of for */40      #pragma omp taskwait41      /* check if all tasks were finished */42      for (i = 0; i < NUM_TASKS; i++)43        if (array[i] != 1)44          result1++;45 46      /* generate some more tasks which now shall overwrite47       * the values in the tids array */48      for (i = 0; i < NUM_TASKS; i++) {49        int myi;50        myi = i;51        #pragma omp task52        {53          array[myi] = 2;54        } /* end of omp task */55      } /* end of for */56    } /* end of single */57  } /*end of parallel */58 59  /* final check, if all array elements contain the right values: */60  for (i = 0; i < NUM_TASKS; i++) {61    if (array[i] != 2)62      result2++;63  }64  return ((result1 == 0) && (result2 == 0));65}66 67int main()68{69  int i;70  int num_failed=0;71 72  for(i = 0; i < REPETITIONS; i++) {73    if(!test_omp_taskwait()) {74      num_failed++;75    }76  }77  return num_failed;78}79