brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · b531af6 Raw
66 lines · c
1// RUN: %libomp-compile-and-run2#include <stdio.h>3#include <math.h>4#include "omp_testsuite.h"5#include "omp_my_sleep.h"6 7int test_omp_task_final()8{9  int tids[NUM_TASKS];10  int includedtids[NUM_TASKS];11  int i;12  int error = 0;13  #pragma omp parallel14  {15    #pragma omp single16    {17      for (i = 0; i < NUM_TASKS; i++) {18        /* First we have to store the value of the loop index in a new variable19         * which will be private for each task because otherwise it will be overwritten20         * if the execution of the task takes longer than the time which is needed to21         * enter the next step of the loop!22         */23        int myi;24        myi = i;25 26        #pragma omp task final(i>=10)27        {28          tids[myi] = omp_get_thread_num();29          /* we generate included tasks for final tasks */30          if(myi >= 10) {31            int included = myi;32            #pragma omp task33            {34              my_sleep (SLEEPTIME);35              includedtids[included] = omp_get_thread_num();36            } /* end of omp included task of the final task */37            my_sleep (SLEEPTIME);38          } /* end of if it is a final task*/39        } /* end of omp task */40      } /* end of for */41    } /* end of single */42  } /*end of parallel */43 44  /* Now we ckeck if more than one thread executed the final task and its included task. */45  for (i = 10; i < NUM_TASKS; i++) {46    if (tids[i] != includedtids[i]) {47      error++;48    }49  }50  return (error==0);51} /* end of check_paralel_for_private */52 53int main()54{55  int i;56  int num_failed=0;57 58  for(i = 0; i < REPETITIONS; i++) {59    if(!test_omp_task_final()) {60      num_failed++;61    }62  }63  return num_failed;64}65 66