brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 49fd633 Raw
43 lines · c
1// RUN: %libomp-compile-and-run2#include "omp_testsuite.h"3#include <stdio.h>4 5// This should be slightly less than KMP_I_LOCK_CHUNK, which is 10246#define LOCKS_PER_ITER 10007#define ITERATIONS (REPETITIONS + 1)8 9// This tests concurrently using locks on one thread while initializing new10// ones on another thread.  This exercises the global lock pool.11int test_omp_init_lock() {12  int i;13  omp_lock_t lcks[ITERATIONS * LOCKS_PER_ITER];14#pragma omp parallel for schedule(static) num_threads(NUM_TASKS)15  for (i = 0; i < ITERATIONS; i++) {16    int j;17    omp_lock_t *my_lcks = &lcks[i * LOCKS_PER_ITER];18    for (j = 0; j < LOCKS_PER_ITER; j++) {19      omp_init_lock(&my_lcks[j]);20    }21    for (j = 0; j < LOCKS_PER_ITER * 100; j++) {22      omp_set_lock(&my_lcks[j % LOCKS_PER_ITER]);23      omp_unset_lock(&my_lcks[j % LOCKS_PER_ITER]);24    }25  }26  // Wait until all repetitions are done.  The test is exercising growth of27  // the global lock pool, which does not shrink when no locks are allocated.28  {29    int j;30    for (j = 0; j < ITERATIONS * LOCKS_PER_ITER; j++) {31      omp_destroy_lock(&lcks[j]);32    }33  }34 35  return 0;36}37 38int main() {39  // No use repeating this test, since it's exercising a private global pool40  // which is not reset between test iterations.41  return test_omp_init_lock();42}43