├── www ├── Reference.pdf ├── content.css └── menu.css ├── runtime ├── doc │ ├── Reference.pdf │ └── doxygen │ │ └── header.tex ├── .clang-format ├── test │ ├── ompt │ │ ├── worksharing │ │ │ ├── for │ │ │ │ ├── guided.c │ │ │ │ ├── dynamic.c │ │ │ │ ├── runtime.c │ │ │ │ ├── dynamic_serialized.c │ │ │ │ ├── guided_serialized.c │ │ │ │ ├── runtime_serialized.c │ │ │ │ ├── static.c │ │ │ │ ├── auto.c │ │ │ │ ├── static_serialized.c │ │ │ │ ├── auto_serialized.c │ │ │ │ ├── dynamic_split.c │ │ │ │ ├── guided_split.c │ │ │ │ ├── runtime_split.c │ │ │ │ ├── static_split.c │ │ │ │ ├── auto_split.c │ │ │ │ └── base_serialized.h │ │ │ ├── single.c │ │ │ └── sections.c │ │ ├── misc │ │ │ ├── control_tool_no_ompt_support.c │ │ │ ├── idle.c │ │ │ ├── unset_callback.c │ │ │ ├── control_tool.c │ │ │ ├── threads.c │ │ │ └── threads_nested.c │ │ ├── ompt-signal.h │ │ ├── synchronization │ │ │ ├── flush.c │ │ │ ├── barrier │ │ │ │ ├── for_simd.c │ │ │ │ └── parallel_region.c │ │ │ ├── master.c │ │ │ ├── ordered.c │ │ │ ├── critical.c │ │ │ ├── taskwait.c │ │ │ ├── taskgroup.c │ │ │ ├── test_nest_lock.c │ │ │ └── lock.c │ │ ├── cancel │ │ │ ├── cancel_parallel.c │ │ │ └── cancel_worksharing.c │ │ └── parallel │ │ │ ├── dynamic_enough_threads.c │ │ │ └── dynamic_not_enough_threads.c │ ├── api │ │ ├── has_openmp.c │ │ ├── omp_get_wtick.c │ │ ├── omp_get_wtime.c │ │ ├── omp_in_parallel.c │ │ ├── omp_get_num_threads.c │ │ ├── kmp_set_defaults_lock_bug.c │ │ └── kmp_aligned_malloc.c │ ├── tasking │ │ ├── bug_serial_taskgroup.c │ │ ├── omp_task_priority.c │ │ ├── nested_task_creation.c │ │ ├── nested_parallel_tasking.c │ │ ├── omp_task_shared.c │ │ ├── omp_task_if.c │ │ ├── omp_task_imp_firstprivate.c │ │ ├── omp_task_firstprivate.c │ │ ├── omp_task_private.c │ │ ├── omp_task.c │ │ ├── omp_taskyield.c │ │ ├── omp_taskloop_num_tasks.c │ │ ├── omp_task_final.c │ │ └── omp_taskwait.c │ ├── env │ │ ├── kmp_aff_disable_hwloc.c │ │ ├── omp_wait_policy.c │ │ ├── kmp_set_dispatch_buf.c │ │ └── omp_thread_limit.c │ ├── critical │ │ └── omp_critical.c │ ├── master │ │ ├── omp_master.c │ │ └── omp_master_3.c │ ├── parallel │ │ ├── omp_parallel_if.c │ │ ├── omp_nested.c │ │ ├── omp_parallel_shared.c │ │ ├── omp_parallel_private.c │ │ ├── omp_parallel_default.c │ │ ├── omp_parallel_firstprivate.c │ │ ├── omp_parallel_copyin.c │ │ └── omp_parallel_num_threads.c │ ├── omp_my_sleep.h │ ├── worksharing │ │ ├── for │ │ │ ├── omp_parallel_for_firstprivate.c │ │ │ ├── bug_set_schedule_0.c │ │ │ ├── omp_parallel_for_lastprivate.c │ │ │ ├── omp_parallel_for_if.c │ │ │ ├── omp_parallel_for_private.c │ │ │ ├── omp_for_firstprivate.c │ │ │ ├── omp_for_collapse.c │ │ │ ├── omp_for_lastprivate.c │ │ │ ├── omp_for_ordered.c │ │ │ ├── omp_for_private.c │ │ │ ├── omp_parallel_for_ordered.c │ │ │ ├── kmp_doacross_check.c │ │ │ ├── omp_for_schedule_auto.c │ │ │ ├── omp_for_bigbounds.c │ │ │ ├── omp_for_nowait.c │ │ │ ├── omp_for_schedule_runtime.c │ │ │ └── kmp_set_dispatch_buf.c │ │ ├── single │ │ │ ├── omp_single.c │ │ │ ├── omp_single_private.c │ │ │ ├── omp_single_copyprivate.c │ │ │ └── omp_single_nowait.c │ │ └── sections │ │ │ ├── omp_parallel_sections_firstprivate.c │ │ │ ├── omp_section_firstprivate.c │ │ │ ├── omp_parallel_sections_private.c │ │ │ ├── omp_parallel_sections_lastprivate.c │ │ │ ├── omp_section_private.c │ │ │ └── omp_section_lastprivate.c │ ├── misc_bugs │ │ ├── many-microtask-args.c │ │ ├── teams-no-par.c │ │ ├── cancellation_for_sections.c │ │ ├── teams-reduction.c │ │ └── omp_foreign_thread_team_reuse.c │ ├── lit.site.cfg.in │ ├── flush │ │ └── omp_flush.c │ ├── barrier │ │ └── omp_barrier.c │ ├── lock │ │ ├── omp_nest_lock.c │ │ ├── omp_test_nest_lock.c │ │ ├── omp_lock.c │ │ ├── omp_test_lock.c │ │ └── omp_init_lock.c │ ├── threadprivate │ │ └── omp_threadprivate_for.c │ └── CMakeLists.txt ├── src │ ├── test-touch.c │ ├── kmp_wait_release.cpp │ ├── kmp_ftn_stdcall.cpp │ ├── kmp_ftn_extra.cpp │ ├── kmp_ftn_cdecl.cpp │ ├── kmp_import.cpp │ ├── kmp_io.h │ ├── thirdparty │ │ └── ittnotify │ │ │ ├── disable_warnings.h │ │ │ └── ittnotify_types.h │ ├── kmp_stub.h │ ├── kmp_safe_c_api.h │ ├── kmp_wrapper_getpid.h │ ├── kmp_debugger.h │ ├── kmp_error.h │ └── kmp_environment.h ├── cmake │ └── LibompDefinitions.cmake └── tools │ └── lib │ └── LibOMP.pm ├── .arcconfig ├── cmake ├── config-ix.cmake ├── HandleOpenMPOptions.cmake └── DetectTestCompiler │ └── CMakeLists.txt ├── libomptarget ├── plugins │ ├── exports │ ├── ppc64 │ │ └── CMakeLists.txt │ ├── x86_64 │ │ └── CMakeLists.txt │ ├── ppc64le │ │ └── CMakeLists.txt │ ├── aarch64 │ │ └── CMakeLists.txt │ ├── cuda │ │ └── CMakeLists.txt │ └── common │ │ └── elf_common.c ├── deviceRTLs │ ├── CMakeLists.txt │ └── nvptx │ │ └── src │ │ ├── cancel.cu │ │ ├── critical.cu │ │ ├── state-queue.h │ │ ├── counter_group.h │ │ └── option.h ├── test │ ├── offloading │ │ ├── offloading_success.c │ │ └── offloading_success.cpp │ ├── lit.site.cfg.in │ ├── CMakeLists.txt │ └── env │ │ └── omp_target_debug.c ├── src │ ├── exports │ ├── CMakeLists.txt │ └── private.h └── cmake │ └── Modules │ └── LibomptargetUtils.cmake ├── .gitignore └── CREDITS.txt /www/Reference.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NERSC/LLVM-openmp/master/www/Reference.pdf -------------------------------------------------------------------------------- /runtime/doc/Reference.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NERSC/LLVM-openmp/master/runtime/doc/Reference.pdf -------------------------------------------------------------------------------- /.arcconfig: -------------------------------------------------------------------------------- 1 | { 2 | "repository.callsign" : "OMP", 3 | "conduit_uri" : "https://reviews.llvm.org/" 4 | } 5 | -------------------------------------------------------------------------------- /runtime/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: LLVM 3 | AlignTrailingComments: false 4 | SortIncludes: false 5 | ... 6 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/guided.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base.h 2 | // REQUIRES: ompt 3 | 4 | #define SCHEDULE guided 5 | #include "base.h" 6 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/dynamic.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base.h 2 | // REQUIRES: ompt 3 | 4 | #define SCHEDULE dynamic 5 | #include "base.h" 6 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/runtime.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base.h 2 | // REQUIRES: ompt 3 | 4 | #define SCHEDULE runtime 5 | #include "base.h" 6 | -------------------------------------------------------------------------------- /cmake/config-ix.cmake: -------------------------------------------------------------------------------- 1 | include(CheckCCompilerFlag) 2 | include(CheckCXXCompilerFlag) 3 | 4 | check_c_compiler_flag(-Werror OPENMP_HAVE_WERROR_FLAG) 5 | 6 | check_cxx_compiler_flag(-std=c++11 OPENMP_HAVE_STD_CPP11_FLAG) -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/dynamic_serialized.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base_serialized.h 2 | // REQUIRES: ompt 3 | 4 | #define SCHEDULE dynamic 5 | #include "base_serialized.h" 6 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/guided_serialized.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base_serialized.h 2 | // REQUIRES: ompt 3 | 4 | #define SCHEDULE guided 5 | #include "base_serialized.h" 6 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/runtime_serialized.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base_serialized.h 2 | // REQUIRES: ompt 3 | 4 | #define SCHEDULE runtime 5 | #include "base_serialized.h" 6 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/static.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base.h 2 | // REQUIRES: ompt 3 | // GCC doesn't call runtime for static schedule 4 | // XFAIL: gcc 5 | 6 | #define SCHEDULE static 7 | #include "base.h" 8 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/auto.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base.h 2 | // REQUIRES: ompt 3 | // GCC doesn't call runtime for auto = static schedule 4 | // XFAIL: gcc 5 | 6 | #define SCHEDULE auto 7 | #include "base.h" 8 | -------------------------------------------------------------------------------- /runtime/test/ompt/misc/control_tool_no_ompt_support.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | 4 | int main() 5 | { 6 | #pragma omp parallel num_threads(1) 7 | { 8 | omp_control_tool(omp_control_tool_flush, 1, NULL); 9 | } 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/static_serialized.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base_serialized.h 2 | // REQUIRES: ompt 3 | // GCC doesn't call runtime for static schedule 4 | // XFAIL: gcc 5 | 6 | #define SCHEDULE static 7 | #include "base_serialized.h" 8 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/auto_serialized.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base_serialized.h 2 | // REQUIRES: ompt 3 | // GCC doesn't call runtime for auto = static schedule 4 | // XFAIL: gcc 5 | 6 | #define SCHEDULE auto 7 | #include "base_serialized.h" 8 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/dynamic_split.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base_split.h 2 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck --check-prefix=CHECK-LOOP %S/base_split.h 3 | // REQUIRES: ompt 4 | // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7 5 | 6 | #define SCHEDULE dynamic 7 | #include "base_split.h" 8 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/guided_split.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base_split.h 2 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck --check-prefix=CHECK-LOOP %S/base_split.h 3 | // REQUIRES: ompt 4 | // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7 5 | 6 | #define SCHEDULE guided 7 | #include "base_split.h" 8 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/runtime_split.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base_split.h 2 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck --check-prefix=CHECK-LOOP %S/base_split.h 3 | // REQUIRES: ompt 4 | // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7 5 | 6 | #define SCHEDULE runtime 7 | #include "base_split.h" 8 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/static_split.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base_split.h 2 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck --check-prefix=CHECK-LOOP %S/base_split.h 3 | // REQUIRES: ompt 4 | // GCC doesn't call runtime for static schedule 5 | // XFAIL: gcc 6 | 7 | #define SCHEDULE static 8 | #include "base_split.h" 9 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/auto_split.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %S/base_split.h 2 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck --check-prefix=CHECK-LOOP %S/base_split.h 3 | // REQUIRES: ompt 4 | // GCC doesn't call runtime for auto = static schedule 5 | // XFAIL: gcc 6 | 7 | #define SCHEDULE auto 8 | #include "base_split.h" 9 | -------------------------------------------------------------------------------- /libomptarget/plugins/exports: -------------------------------------------------------------------------------- 1 | VERS1.0 { 2 | global: 3 | __tgt_rtl_is_valid_binary; 4 | __tgt_rtl_number_of_devices; 5 | __tgt_rtl_init_device; 6 | __tgt_rtl_load_binary; 7 | __tgt_rtl_data_alloc; 8 | __tgt_rtl_data_submit; 9 | __tgt_rtl_data_retrieve; 10 | __tgt_rtl_data_delete; 11 | __tgt_rtl_run_target_team_region; 12 | __tgt_rtl_run_target_region; 13 | local: 14 | *; 15 | }; 16 | -------------------------------------------------------------------------------- /runtime/test/api/has_openmp.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | int test_has_openmp() 7 | { 8 | int rvalue = 0; 9 | #ifdef _OPENMP 10 | rvalue = 1; 11 | #endif 12 | return (rvalue); 13 | } 14 | 15 | int main() 16 | { 17 | int i; 18 | int num_failed=0; 19 | if(!test_has_openmp()) { 20 | num_failed++; 21 | } 22 | return num_failed; 23 | } 24 | -------------------------------------------------------------------------------- /runtime/test/tasking/bug_serial_taskgroup.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | 3 | /* 4 | GCC failed this test because __kmp_get_gtid() instead of __kmp_entry_gtid() 5 | was called in xexpand(KMP_API_NAME_GOMP_TASKGROUP_START)(void). 6 | __kmp_entry_gtid() will initialize the runtime if not yet done which does not 7 | happen with __kmp_get_gtid(). 8 | */ 9 | 10 | int main() 11 | { 12 | #pragma omp taskgroup 13 | { } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /runtime/test/api/omp_get_wtick.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_get_wtick() 6 | { 7 | double tick; 8 | tick = -1.; 9 | tick = omp_get_wtick (); 10 | return ((tick > 0.0) && (tick < 0.01)); 11 | } 12 | 13 | int main() 14 | { 15 | int i; 16 | int num_failed=0; 17 | 18 | for(i = 0; i < REPETITIONS; i++) { 19 | if(!test_omp_get_wtick()) { 20 | num_failed++; 21 | } 22 | } 23 | return num_failed; 24 | } 25 | -------------------------------------------------------------------------------- /runtime/test/env/kmp_aff_disable_hwloc.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile && env KMP_AFFINITY=disabled KMP_TOPOLOGY_METHOD=hwloc %libomp-run 2 | // REQUIRES: hwloc 3 | #include 4 | #include 5 | 6 | // Test will assert() without fix 7 | int test_affinity_disabled_plus_hwloc() { 8 | #pragma omp parallel 9 | {} 10 | return 1; 11 | } 12 | 13 | int main(int argc, char **argv) { 14 | int i, j; 15 | int failed = 0; 16 | 17 | if (!test_affinity_disabled_plus_hwloc()) { 18 | failed = 1; 19 | } 20 | return failed; 21 | } 22 | -------------------------------------------------------------------------------- /cmake/HandleOpenMPOptions.cmake: -------------------------------------------------------------------------------- 1 | if (${OPENMP_STANDALONE_BUILD}) 2 | # From HandleLLVMOptions.cmake 3 | function(append_if condition value) 4 | if (${condition}) 5 | foreach(variable ${ARGN}) 6 | set(${variable} "${${variable}} ${value}" PARENT_SCOPE) 7 | endforeach(variable) 8 | endif() 9 | endfunction() 10 | endif() 11 | 12 | if (${OPENMP_ENABLE_WERROR}) 13 | append_if(OPENMP_HAVE_WERROR_FLAG "-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) 14 | endif() 15 | 16 | append_if(OPENMP_HAVE_STD_CPP11_FLAG "-std=c++11" CMAKE_CXX_FLAGS) -------------------------------------------------------------------------------- /libomptarget/deviceRTLs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##===----------------------------------------------------------------------===## 2 | # 3 | # The LLVM Compiler Infrastructure 4 | # 5 | # This file is dual licensed under the MIT and the University of Illinois Open 6 | # Source Licenses. See LICENSE.txt for details. 7 | # 8 | # ##===----------------------------------------------------------------------===## 9 | # 10 | # Build a device RTL for each available machine available. 11 | # 12 | ##===----------------------------------------------------------------------===## 13 | 14 | add_subdirectory(nvptx) 15 | -------------------------------------------------------------------------------- /runtime/test/tasking/omp_task_priority.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile && env OMP_MAX_TASK_PRIORITY=42 %libomp-run 2 | // Test OMP 4.5 task priorities 3 | // Currently only API function and envirable parsing implemented. 4 | // Test environment sets envirable: OMP_MAX_TASK_PRIORITY=42 as tested below. 5 | #include 6 | #include 7 | 8 | int main (void) { 9 | int passed; 10 | 11 | passed = (omp_get_max_task_priority() == 42); 12 | printf("Got %d\n", omp_get_max_task_priority()); 13 | 14 | if (passed) { 15 | printf("passed\n"); 16 | return 0; 17 | } 18 | 19 | printf("failed\n"); 20 | return 1; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /runtime/test/tasking/nested_task_creation.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_my_sleep.h" 5 | 6 | /* 7 | * This test creates tasks that themselves create a new task. 8 | * The runtime has to take care that they are correctly freed. 9 | */ 10 | 11 | int main() 12 | { 13 | #pragma omp task 14 | { 15 | #pragma omp task 16 | { 17 | my_sleep( 0.1 ); 18 | } 19 | } 20 | 21 | #pragma omp parallel num_threads(2) 22 | { 23 | #pragma omp single 24 | #pragma omp task 25 | { 26 | #pragma omp task 27 | { 28 | my_sleep( 0.1 ); 29 | } 30 | } 31 | } 32 | 33 | printf("pass\n"); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /runtime/test/critical/omp_critical.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_critical() 6 | { 7 | int sum; 8 | int known_sum; 9 | 10 | sum=0; 11 | #pragma omp parallel 12 | { 13 | int mysum=0; 14 | int i; 15 | #pragma omp for 16 | for (i = 0; i < 1000; i++) 17 | mysum = mysum + i; 18 | 19 | #pragma omp critical 20 | sum = mysum +sum; 21 | } 22 | known_sum = 999 * 1000 / 2; 23 | return (known_sum == sum); 24 | } 25 | 26 | int main() 27 | { 28 | int i; 29 | int num_failed=0; 30 | 31 | for(i = 0; i < REPETITIONS; i++) { 32 | if(!test_omp_critical()) { 33 | num_failed++; 34 | } 35 | } 36 | return num_failed; 37 | } 38 | -------------------------------------------------------------------------------- /www/content.css: -------------------------------------------------------------------------------- 1 | html { margin: 0px; } body { margin: 8px; } 2 | 3 | html, body { 4 | padding:0px; 5 | font-size:small; font-family:"Lucida Grande", "Lucida Sans Unicode", Arial, Verdana, Helvetica, sans-serif; background-color: #fff; color: #222; 6 | line-height:1.5; 7 | } 8 | 9 | h1, h2, h3, tt { color: #000 } 10 | 11 | h1 { padding-top:0px; margin-top:0px;} 12 | h2 { color:#333333; padding-top:0.5em; } 13 | h3 { padding-top: 0.5em; margin-bottom: -0.25em; color:#2d58b7} 14 | li { padding-bottom: 0.5em; } 15 | ul { padding-left:1.5em; } 16 | 17 | /* Slides */ 18 | IMG.img_slide { 19 | display: block; 20 | margin-left: auto; 21 | margin-right: auto 22 | } 23 | 24 | .itemTitle { color:#2d58b7 } 25 | 26 | /* Tables */ 27 | tr { vertical-align:top } 28 | -------------------------------------------------------------------------------- /www/menu.css: -------------------------------------------------------------------------------- 1 | /***************/ 2 | /* page layout */ 3 | /***************/ 4 | 5 | [id=menu] { 6 | position:fixed; 7 | width:25ex; 8 | } 9 | [id=content] { 10 | /* ***** EDIT THIS VALUE IF CONTENT OVERLAPS MENU ***** */ 11 | position:absolute; 12 | left:29ex; 13 | padding-right:4ex; 14 | } 15 | 16 | /**************/ 17 | /* menu style */ 18 | /**************/ 19 | 20 | #menu .submenu { 21 | padding-top:1em; 22 | display:block; 23 | } 24 | 25 | #menu label { 26 | display:block; 27 | font-weight: bold; 28 | text-align: center; 29 | background-color: rgb(192,192,192); 30 | } 31 | #menu a { 32 | padding:0 .2em; 33 | display:block; 34 | text-align: center; 35 | background-color: rgb(235,235,235); 36 | } 37 | #menu a:visited { 38 | color:rgb(100,50,100); 39 | } 40 | -------------------------------------------------------------------------------- /runtime/test/ompt/misc/idle.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | FileCheck %s 2 | // REQUIRES: ompt 3 | #include "callback.h" 4 | #include 5 | 6 | int main() 7 | { 8 | int x = 0; 9 | #pragma omp parallel num_threads(3) 10 | { 11 | #pragma omp atomic 12 | x++; 13 | } 14 | #pragma omp parallel num_threads(2) 15 | { 16 | #pragma omp atomic 17 | x++; 18 | } 19 | 20 | 21 | printf("x=%d\n", x); 22 | 23 | // Check if libomp supports the callbacks for this test. 24 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_idle' 25 | 26 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 27 | 28 | // CHECK: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_idle_begin: 29 | // CHECK: {{^}}[[THREAD_ID]]: ompt_event_idle_end: 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /libomptarget/test/offloading/offloading_success.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomptarget-compile-run-and-check-aarch64-unknown-linux-gnu 2 | // RUN: %libomptarget-compile-run-and-check-powerpc64-ibm-linux-gnu 3 | // RUN: %libomptarget-compile-run-and-check-powerpc64le-ibm-linux-gnu 4 | // RUN: %libomptarget-compile-run-and-check-x86_64-pc-linux-gnu 5 | 6 | #include 7 | #include 8 | 9 | int main(void) { 10 | int isHost = -1; 11 | 12 | #pragma omp target map(from: isHost) 13 | { isHost = omp_is_initial_device(); } 14 | 15 | if (isHost < 0) { 16 | printf("Runtime error, isHost=%d\n", isHost); 17 | } 18 | 19 | // CHECK: Target region executed on the device 20 | printf("Target region executed on the %s\n", isHost ? "host" : "device"); 21 | 22 | return isHost; 23 | } 24 | -------------------------------------------------------------------------------- /runtime/test/api/omp_get_wtime.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | #include "omp_my_sleep.h" 6 | 7 | int test_omp_get_wtime() 8 | { 9 | double start; 10 | double end; 11 | double measured_time; 12 | double wait_time = 5.0; 13 | start = 0; 14 | end = 0; 15 | start = omp_get_wtime(); 16 | my_sleep (wait_time); 17 | end = omp_get_wtime(); 18 | measured_time = end-start; 19 | return ((measured_time > 0.97 * wait_time) && (measured_time < 1.03 * wait_time)) ; 20 | } 21 | 22 | int main() 23 | { 24 | int i; 25 | int num_failed=0; 26 | 27 | for(i = 0; i < REPETITIONS; i++) { 28 | if(!test_omp_get_wtime()) { 29 | num_failed++; 30 | } 31 | } 32 | return num_failed; 33 | } 34 | -------------------------------------------------------------------------------- /libomptarget/src/exports: -------------------------------------------------------------------------------- 1 | VERS1.0 { 2 | global: 3 | __tgt_register_lib; 4 | __tgt_unregister_lib; 5 | __tgt_target_data_begin; 6 | __tgt_target_data_end; 7 | __tgt_target_data_update; 8 | __tgt_target; 9 | __tgt_target_teams; 10 | __tgt_target_data_begin_nowait; 11 | __tgt_target_data_end_nowait; 12 | __tgt_target_data_update_nowait; 13 | __tgt_target_nowait; 14 | __tgt_target_teams_nowait; 15 | omp_get_num_devices; 16 | omp_get_initial_device; 17 | omp_target_alloc; 18 | omp_target_free; 19 | omp_target_is_present; 20 | omp_target_memcpy; 21 | omp_target_memcpy_rect; 22 | omp_target_associate_ptr; 23 | omp_target_disassociate_ptr; 24 | __kmpc_push_target_tripcount; 25 | local: 26 | *; 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /libomptarget/test/offloading/offloading_success.cpp: -------------------------------------------------------------------------------- 1 | // RUN: %libomptarget-compilexx-run-and-check-aarch64-unknown-linux-gnu 2 | // RUN: %libomptarget-compilexx-run-and-check-powerpc64-ibm-linux-gnu 3 | // RUN: %libomptarget-compilexx-run-and-check-powerpc64le-ibm-linux-gnu 4 | // RUN: %libomptarget-compilexx-run-and-check-x86_64-pc-linux-gnu 5 | 6 | #include 7 | #include 8 | 9 | int main(void) { 10 | int isHost = 0; 11 | 12 | #pragma omp target map(from: isHost) 13 | { isHost = omp_is_initial_device(); } 14 | 15 | if (isHost < 0) { 16 | printf("Runtime error, isHost=%d\n", isHost); 17 | } 18 | 19 | // CHECK: Target region executed on the device 20 | printf("Target region executed on the %s\n", isHost ? "host" : "device"); 21 | 22 | return isHost; 23 | } 24 | -------------------------------------------------------------------------------- /libomptarget/plugins/ppc64/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##===----------------------------------------------------------------------===## 2 | # 3 | # The LLVM Compiler Infrastructure 4 | # 5 | # This file is dual licensed under the MIT and the University of Illinois Open 6 | # Source Licenses. See LICENSE.txt for details. 7 | # 8 | ##===----------------------------------------------------------------------===## 9 | # 10 | # Build a plugin for a ppc64 machine if available. 11 | # 12 | ##===----------------------------------------------------------------------===## 13 | 14 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 15 | build_generic_elf64("ppc64" "PPC64" "ppc64" "powerpc64-ibm-linux-gnu" "21") 16 | else() 17 | libomptarget_say("Not building ppc64 offloading plugin: machine not found in the system.") 18 | endif() -------------------------------------------------------------------------------- /libomptarget/plugins/x86_64/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##===----------------------------------------------------------------------===## 2 | # 3 | # The LLVM Compiler Infrastructure 4 | # 5 | # This file is dual licensed under the MIT and the University of Illinois Open 6 | # Source Licenses. See LICENSE.txt for details. 7 | # 8 | ##===----------------------------------------------------------------------===## 9 | # 10 | # Build a plugin for a x86_64 machine if available. 11 | # 12 | ##===----------------------------------------------------------------------===## 13 | 14 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 15 | build_generic_elf64("x86_64" "x86_64" "x86_64" "x86_64-pc-linux-gnu" "62") 16 | else() 17 | libomptarget_say("Not building x86_64 offloading plugin: machine not found in the system.") 18 | endif() -------------------------------------------------------------------------------- /runtime/test/master/omp_master.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_master() 6 | { 7 | int nthreads; 8 | int executing_thread; 9 | 10 | nthreads = 0; 11 | executing_thread = -1; 12 | 13 | #pragma omp parallel 14 | { 15 | #pragma omp master 16 | { 17 | #pragma omp critical 18 | { 19 | nthreads++; 20 | } 21 | executing_thread = omp_get_thread_num(); 22 | } /* end of master*/ 23 | } /* end of parallel*/ 24 | return ((nthreads == 1) && (executing_thread == 0)); 25 | } 26 | 27 | int main() 28 | { 29 | int i; 30 | int num_failed=0; 31 | 32 | for(i = 0; i < REPETITIONS; i++) { 33 | if(!test_omp_master()) { 34 | num_failed++; 35 | } 36 | } 37 | return num_failed; 38 | } 39 | -------------------------------------------------------------------------------- /libomptarget/plugins/ppc64le/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##===----------------------------------------------------------------------===## 2 | # 3 | # The LLVM Compiler Infrastructure 4 | # 5 | # This file is dual licensed under the MIT and the University of Illinois Open 6 | # Source Licenses. See LICENSE.txt for details. 7 | # 8 | ##===----------------------------------------------------------------------===## 9 | # 10 | # Build a plugin for a ppc64le machine if available. 11 | # 12 | ##===----------------------------------------------------------------------===## 13 | 14 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 15 | build_generic_elf64("ppc64le" "PPC64le" "ppc64" "powerpc64le-ibm-linux-gnu" "21") 16 | else() 17 | libomptarget_say("Not building ppc64le offloading plugin: machine not found in the system.") 18 | endif() -------------------------------------------------------------------------------- /libomptarget/plugins/aarch64/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##===----------------------------------------------------------------------===## 2 | # 3 | # The LLVM Compiler Infrastructure 4 | # 5 | # This file is dual licensed under the MIT and the University of Illinois Open 6 | # Source Licenses. See LICENSE.txt for details. 7 | # 8 | ##===----------------------------------------------------------------------===## 9 | # 10 | # Build a plugin for an aarch64 machine if available. 11 | # 12 | ##===----------------------------------------------------------------------===## 13 | 14 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") 15 | build_generic_elf64("aarch64" "aarch64" "aarch64" "aarch64-unknown-linux-gnu" "183") 16 | else() 17 | libomptarget_say("Not building aarch64 offloading plugin: machine not found in the system.") 18 | endif() 19 | -------------------------------------------------------------------------------- /runtime/src/test-touch.c: -------------------------------------------------------------------------------- 1 | // test-touch.c // 2 | 3 | 4 | //===----------------------------------------------------------------------===// 5 | // 6 | // The LLVM Compiler Infrastructure 7 | // 8 | // This file is dual licensed under the MIT and the University of Illinois Open 9 | // Source Licenses. See LICENSE.txt for details. 10 | // 11 | //===----------------------------------------------------------------------===// 12 | 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | extern double omp_get_wtime(); 18 | extern int omp_get_num_threads(); 19 | extern int omp_get_max_threads(); 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | int main() { 25 | omp_get_wtime(); 26 | omp_get_num_threads(); 27 | omp_get_max_threads(); 28 | return 0; 29 | } 30 | 31 | // end of file // 32 | -------------------------------------------------------------------------------- /runtime/test/ompt/ompt-signal.h: -------------------------------------------------------------------------------- 1 | #if defined(WIN32) || defined(_WIN32) 2 | #include 3 | #define delay() Sleep(1); 4 | #else 5 | #include 6 | #define delay(t) usleep(t); 7 | #endif 8 | 9 | // These functions are used to provide a signal-wait mechanism to enforce expected scheduling for the test cases. 10 | // Conditional variable (s) needs to be shared! Initialize to 0 11 | 12 | #define OMPT_SIGNAL(s) ompt_signal(&s) 13 | //inline 14 | void ompt_signal(int* s) 15 | { 16 | #pragma omp atomic 17 | (*s)++; 18 | } 19 | 20 | #define OMPT_WAIT(s,v) ompt_wait(&s,v) 21 | // wait for s >= v 22 | //inline 23 | void ompt_wait(int *s, int v) 24 | { 25 | int wait=0; 26 | do{ 27 | delay(10); 28 | #pragma omp atomic read 29 | wait = (*s); 30 | }while(wait 3 | #include 4 | 5 | /* 6 | * This test would hang when level instead of active level 7 | * used to push task state. 8 | */ 9 | 10 | int main() 11 | { 12 | // If num_threads is changed to a value greater than 1, then the test passes 13 | #pragma omp parallel num_threads(1) 14 | { 15 | #pragma omp parallel 16 | printf("Hello World from thread %d\n", omp_get_thread_num()); 17 | } 18 | 19 | printf("omp_num_threads: %d\n", omp_get_max_threads()); 20 | 21 | #pragma omp parallel 22 | { 23 | #pragma omp master 24 | #pragma omp task default(none) 25 | { 26 | printf("%d is executing this task\n", omp_get_thread_num()); 27 | } 28 | } 29 | 30 | printf("pass\n"); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /runtime/test/api/omp_in_parallel.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | /* 6 | * Checks that false is returned when called from serial region 7 | * and true is returned when called within parallel region. 8 | */ 9 | int test_omp_in_parallel() 10 | { 11 | int serial; 12 | int isparallel; 13 | 14 | serial = 1; 15 | isparallel = 0; 16 | serial = omp_in_parallel(); 17 | 18 | #pragma omp parallel 19 | { 20 | #pragma omp single 21 | { 22 | isparallel = omp_in_parallel(); 23 | } 24 | } 25 | return (!(serial) && isparallel); 26 | } 27 | 28 | int main() 29 | { 30 | int i; 31 | int num_failed=0; 32 | 33 | for(i = 0; i < REPETITIONS; i++) { 34 | if(!test_omp_in_parallel()) { 35 | num_failed++; 36 | } 37 | } 38 | return num_failed; 39 | } 40 | -------------------------------------------------------------------------------- /runtime/test/parallel/omp_parallel_if.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_parallel_if() 6 | { 7 | int i; 8 | int sum; 9 | int known_sum; 10 | int mysum; 11 | int control=1; 12 | 13 | sum =0; 14 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2 ; 15 | #pragma omp parallel private(i) if(control==0) 16 | { 17 | mysum = 0; 18 | for (i = 1; i <= LOOPCOUNT; i++) { 19 | mysum = mysum + i; 20 | } 21 | #pragma omp critical 22 | { 23 | sum = sum + mysum; 24 | } 25 | } 26 | return (known_sum == sum); 27 | } 28 | 29 | int main() 30 | { 31 | int i; 32 | int num_failed=0; 33 | 34 | for(i = 0; i < REPETITIONS; i++) { 35 | if(!test_omp_parallel_if()) { 36 | num_failed++; 37 | } 38 | } 39 | return num_failed; 40 | } 41 | -------------------------------------------------------------------------------- /runtime/test/omp_my_sleep.h: -------------------------------------------------------------------------------- 1 | #ifndef MY_SLEEP_H 2 | #define MY_SLEEP_H 3 | 4 | /*! Utility function to have a sleep function with better resolution and 5 | * which only stops one thread. */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #if defined(_WIN32) 13 | # include 14 | // Windows version of my_sleep() function 15 | static void my_sleep(double sleeptime) { 16 | DWORD ms = (DWORD) (sleeptime * 1000.0); 17 | Sleep(ms); 18 | } 19 | 20 | 21 | #else // _WIN32 22 | 23 | // Unices version of my_sleep() function 24 | static void my_sleep(double sleeptime) { 25 | struct timespec ts; 26 | ts.tv_sec = (time_t)sleeptime; 27 | ts.tv_nsec = (long)((sleeptime - (double)ts.tv_sec) * 1E9); 28 | nanosleep(&ts, NULL); 29 | } 30 | 31 | #endif // _WIN32 32 | 33 | #endif // MY_SLEEP_H 34 | -------------------------------------------------------------------------------- /runtime/test/ompt/misc/unset_callback.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | FileCheck %s 2 | // REQUIRES: ompt 3 | #include "callback.h" 4 | #include 5 | 6 | int main() 7 | { 8 | #pragma omp parallel num_threads(1) 9 | { 10 | 11 | } 12 | ompt_set_callback(ompt_callback_parallel_begin, NULL); 13 | #pragma omp parallel num_threads(1) 14 | { 15 | 16 | } 17 | 18 | // Check if libomp supports the callbacks for this test. 19 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_idle' 20 | 21 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 22 | 23 | // CHECK: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_parallel_begin: 24 | // CHECK: {{^}}[[THREAD_ID]]: ompt_event_parallel_end: 25 | // CHECK-NOT: {{^}}[[THREAD_ID]]: ompt_event_parallel_begin: 26 | // CHECK: {{^}}[[THREAD_ID]]: ompt_event_parallel_end: 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_parallel_for_firstprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_parallel_for_firstprivate() 6 | { 7 | int sum ; 8 | int i2; 9 | int i; 10 | int known_sum; 11 | 12 | sum=0; 13 | i2=3; 14 | 15 | #pragma omp parallel for reduction(+:sum) private(i) firstprivate(i2) 16 | for (i = 1; i <= LOOPCOUNT; i++) { 17 | sum = sum + (i + i2); 18 | } 19 | 20 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2 + i2 * LOOPCOUNT; 21 | return (known_sum == sum); 22 | } /* end of check_parallel_for_fistprivate */ 23 | 24 | int main() 25 | { 26 | int i; 27 | int num_failed=0; 28 | 29 | for(i = 0; i < REPETITIONS; i++) { 30 | if(!test_omp_parallel_for_firstprivate()) { 31 | num_failed++; 32 | } 33 | } 34 | return num_failed; 35 | } 36 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/bug_set_schedule_0.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | /* Test that the chunk size is set to default (1) when 7 | chunk size <= 0 is specified */ 8 | int a = 0; 9 | 10 | int test_set_schedule_0() 11 | { 12 | int i; 13 | a = 0; 14 | omp_set_schedule(omp_sched_dynamic,0); 15 | 16 | #pragma omp parallel 17 | { 18 | #pragma omp for schedule(runtime) 19 | for(i = 0; i < 10; i++) { 20 | #pragma omp atomic 21 | a++; 22 | if(a > 10) 23 | exit(1); 24 | } 25 | } 26 | return a==10; 27 | } 28 | 29 | int main() 30 | { 31 | int i; 32 | int num_failed=0; 33 | 34 | for(i = 0; i < REPETITIONS; i++) { 35 | if(!test_set_schedule_0()) { 36 | num_failed++; 37 | } 38 | } 39 | return num_failed; 40 | } 41 | -------------------------------------------------------------------------------- /runtime/src/kmp_wait_release.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * kmp_wait_release.cpp -- Wait/Release implementation 3 | */ 4 | 5 | //===----------------------------------------------------------------------===// 6 | // 7 | // The LLVM Compiler Infrastructure 8 | // 9 | // This file is dual licensed under the MIT and the University of Illinois Open 10 | // Source Licenses. See LICENSE.txt for details. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "kmp_wait_release.h" 15 | 16 | void __kmp_wait_64(kmp_info_t *this_thr, kmp_flag_64 *flag, 17 | int final_spin USE_ITT_BUILD_ARG(void *itt_sync_obj)) { 18 | __kmp_wait_template(this_thr, flag, 19 | final_spin USE_ITT_BUILD_ARG(itt_sync_obj)); 20 | } 21 | 22 | void __kmp_release_64(kmp_flag_64 *flag) { __kmp_release_template(flag); } 23 | -------------------------------------------------------------------------------- /runtime/test/tasking/omp_task_shared.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | /* Utility function do spend some time in a loop */ 7 | int test_omp_task_imp_shared() 8 | { 9 | int i; 10 | int k = 0; 11 | int result = 0; 12 | i=0; 13 | 14 | #pragma omp parallel 15 | { 16 | #pragma omp single 17 | for (k = 0; k < NUM_TASKS; k++) { 18 | #pragma omp task shared(i) 19 | { 20 | #pragma omp atomic 21 | i++; 22 | //this should be shared implicitly 23 | } 24 | } 25 | } 26 | result = i; 27 | return ((result == NUM_TASKS)); 28 | } 29 | 30 | int main() 31 | { 32 | int i; 33 | int num_failed=0; 34 | 35 | for(i = 0; i < REPETITIONS; i++) { 36 | if(!test_omp_task_imp_shared()) { 37 | num_failed++; 38 | } 39 | } 40 | return num_failed; 41 | } 42 | -------------------------------------------------------------------------------- /runtime/test/api/omp_get_num_threads.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_get_num_threads() 6 | { 7 | /* checks that omp_get_num_threads is equal to the number of 8 | threads */ 9 | int nthreads_lib; 10 | int nthreads = 0; 11 | 12 | nthreads_lib = -1; 13 | 14 | #pragma omp parallel 15 | { 16 | #pragma omp critical 17 | { 18 | nthreads++; 19 | } /* end of critical */ 20 | #pragma omp single 21 | { 22 | nthreads_lib = omp_get_num_threads (); 23 | } /* end of single */ 24 | } /* end of parallel */ 25 | return (nthreads == nthreads_lib); 26 | } 27 | 28 | int main() 29 | { 30 | int i; 31 | int num_failed=0; 32 | 33 | for(i = 0; i < REPETITIONS; i++) { 34 | if(!test_omp_get_num_threads()) { 35 | num_failed++; 36 | } 37 | } 38 | return num_failed; 39 | } 40 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_parallel_for_lastprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_parallel_for_lastprivate() 6 | { 7 | int sum; 8 | int i; 9 | int i0; 10 | int known_sum; 11 | 12 | sum =0; 13 | i0 = -1; 14 | 15 | #pragma omp parallel for reduction(+:sum) \ 16 | schedule(static,7) private(i) lastprivate(i0) 17 | for (i = 1; i <= LOOPCOUNT; i++) { 18 | sum = sum + i; 19 | i0 = i; 20 | } /* end of parallel for */ 21 | 22 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; 23 | return ((known_sum == sum) && (i0 == LOOPCOUNT)); 24 | } /* end of check_parallel_for_lastprivate */ 25 | 26 | int main() 27 | { 28 | int i; 29 | int num_failed=0; 30 | 31 | for(i = 0; i < REPETITIONS; i++) { 32 | if(!test_omp_parallel_for_lastprivate()) { 33 | num_failed++; 34 | } 35 | } 36 | return num_failed; 37 | } 38 | -------------------------------------------------------------------------------- /runtime/test/misc_bugs/many-microtask-args.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | 4 | int main() 5 | { 6 | 7 | int i; 8 | int i1 = 0; 9 | int i2 = 1; 10 | int i3 = 2; 11 | int i4 = 3; 12 | int i5 = 4; 13 | int i6 = 6; 14 | int i7 = 7; 15 | int i8 = 8; 16 | int i9 = 9; 17 | int i10 = 10; 18 | int i11 = 11; 19 | int i12 = 12; 20 | int i13 = 13; 21 | int i14 = 14; 22 | int i15 = 15; 23 | int i16 = 16; 24 | 25 | int r = 0; 26 | #pragma omp parallel for firstprivate(i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16) reduction(+:r) 27 | for (i = 0; i < i16; i++) { 28 | r += i + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10 + i11 + i12 + i13 + i14 + i15 + i16; 29 | } 30 | 31 | int rf = 2216; 32 | if (r != rf) { 33 | fprintf(stderr, "r should be %d but instead equals %d\n", rf, r); 34 | return 1; 35 | } 36 | 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /runtime/test/parallel/omp_nested.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | /* 6 | * Test if the compiler supports nested parallelism 7 | * By Chunhua Liao, University of Houston 8 | * Oct. 2005 9 | */ 10 | int test_omp_nested() 11 | { 12 | #ifdef _OPENMP 13 | if (omp_get_max_threads() > 4) 14 | omp_set_num_threads(4); 15 | #endif 16 | 17 | int counter = 0; 18 | #ifdef _OPENMP 19 | omp_set_nested(1); 20 | #endif 21 | 22 | #pragma omp parallel shared(counter) 23 | { 24 | #pragma omp critical 25 | counter++; 26 | #pragma omp parallel 27 | { 28 | #pragma omp critical 29 | counter--; 30 | } 31 | } 32 | return (counter != 0); 33 | } 34 | 35 | int main() 36 | { 37 | int i; 38 | int num_failed=0; 39 | 40 | for(i = 0; i < REPETITIONS; i++) { 41 | if(!test_omp_nested()) { 42 | num_failed++; 43 | } 44 | } 45 | return num_failed; 46 | } 47 | -------------------------------------------------------------------------------- /runtime/test/parallel/omp_parallel_shared.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_parallel_shared() 6 | { 7 | int i; 8 | int sum; 9 | int known_sum; 10 | 11 | sum = 0; 12 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2 ; 13 | 14 | #pragma omp parallel private(i) shared(sum) 15 | { 16 | 17 | int mysum = 0; 18 | #pragma omp for 19 | for (i = 1; i <= LOOPCOUNT; i++) { 20 | mysum = mysum + i; 21 | } 22 | #pragma omp critical 23 | { 24 | sum = sum + mysum; 25 | } 26 | 27 | 28 | } 29 | if (known_sum != sum) { 30 | fprintf(stderr, "KNOWN_SUM = %d; SUM = %d\n", known_sum, sum); 31 | } 32 | return (known_sum == sum); 33 | } 34 | 35 | int main() 36 | { 37 | int i; 38 | int num_failed=0; 39 | 40 | for(i = 0; i < REPETITIONS; i++) { 41 | if(!test_omp_parallel_shared()) { 42 | num_failed++; 43 | } 44 | } 45 | return num_failed; 46 | } 47 | -------------------------------------------------------------------------------- /runtime/test/tasking/omp_task_if.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | #include "omp_my_sleep.h" 6 | 7 | int test_omp_task_if() 8 | { 9 | int condition_false; 10 | int count; 11 | int result; 12 | 13 | count=0; 14 | condition_false = (count == 1); 15 | #pragma omp parallel 16 | { 17 | #pragma omp single 18 | { 19 | #pragma omp task if (condition_false) shared(count, result) 20 | { 21 | my_sleep (SLEEPTIME); 22 | #pragma omp critical 23 | result = (0 == count); 24 | } /* end of omp task */ 25 | #pragma omp critical 26 | count = 1; 27 | } /* end of single */ 28 | } /*end of parallel */ 29 | return result; 30 | } 31 | 32 | int main() 33 | { 34 | int i; 35 | int num_failed=0; 36 | 37 | for(i = 0; i < REPETITIONS; i++) { 38 | if(!test_omp_task_if()) { 39 | num_failed++; 40 | } 41 | } 42 | return num_failed; 43 | } 44 | -------------------------------------------------------------------------------- /libomptarget/test/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | @AUTO_GEN_COMMENT@ 2 | 3 | config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@" 4 | config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@" 5 | config.test_openmp_flags = "@OPENMP_TEST_OPENMP_FLAGS@" 6 | config.test_extra_flags = "@OPENMP_TEST_FLAGS@" 7 | config.libomptarget_obj_root = "@CMAKE_CURRENT_BINARY_DIR@" 8 | config.library_dir = "@LIBOMPTARGET_LIBRARY_DIR@" 9 | config.omp_header_directory = "@LIBOMPTARGET_OPENMP_HEADER_FOLDER@" 10 | config.omp_host_rtl_directory = "@LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER@" 11 | config.operating_system = "@CMAKE_SYSTEM_NAME@" 12 | config.libomptarget_all_targets = "@LIBOMPTARGET_ALL_TARGETS@".split() 13 | config.libomptarget_system_targets = "@LIBOMPTARGET_SYSTEM_TARGETS@".split() 14 | config.libomptarget_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@" 15 | config.libomptarget_debug = @LIBOMPTARGET_DEBUG@ 16 | 17 | # Let the main config do the real work. 18 | lit_config.load_config(config, "@LIBOMPTARGET_BASE_DIR@/test/lit.cfg") 19 | -------------------------------------------------------------------------------- /runtime/test/lit.site.cfg.in: -------------------------------------------------------------------------------- 1 | @AUTO_GEN_COMMENT@ 2 | 3 | config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@" 4 | config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@" 5 | config.test_compiler_features = @OPENMP_TEST_COMPILER_FEATURES@ 6 | config.test_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@" 7 | config.test_openmp_flags = "@OPENMP_TEST_OPENMP_FLAGS@" 8 | config.test_extra_flags = "@OPENMP_TEST_FLAGS@" 9 | config.libomp_obj_root = "@CMAKE_CURRENT_BINARY_DIR@" 10 | config.library_dir = "@LIBOMP_LIBRARY_DIR@" 11 | config.omp_header_directory = "@LIBOMP_BINARY_DIR@/src" 12 | config.operating_system = "@CMAKE_SYSTEM_NAME@" 13 | config.hwloc_library_dir = "@LIBOMP_HWLOC_LIBRARY_DIR@" 14 | config.using_hwloc = @LIBOMP_USE_HWLOC@ 15 | config.has_ompt = @LIBOMP_OMPT_SUPPORT@ and @LIBOMP_OMPT_OPTIONAL@ 16 | config.has_libm = @LIBOMP_HAVE_LIBM@ 17 | config.has_libatomic = @LIBOMP_HAVE_LIBATOMIC@ 18 | 19 | # Let the main config do the real work. 20 | lit_config.load_config(config, "@LIBOMP_BASE_DIR@/test/lit.cfg") 21 | -------------------------------------------------------------------------------- /runtime/test/parallel/omp_parallel_private.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | //static int sum1 = 789; 7 | 8 | int test_omp_parallel_private() 9 | { 10 | int sum, num_threads,sum1; 11 | int known_sum; 12 | 13 | sum = 0; 14 | num_threads = 0; 15 | 16 | #pragma omp parallel private(sum1) 17 | { 18 | int i; 19 | sum1 = 7; 20 | /*printf("sum1=%d\n",sum1);*/ 21 | #pragma omp for 22 | for (i = 1; i < 1000; i++) { 23 | sum1 = sum1 + i; 24 | } 25 | #pragma omp critical 26 | { 27 | sum = sum + sum1; 28 | num_threads++; 29 | } 30 | } 31 | known_sum = (999 * 1000) / 2 + 7 * num_threads; 32 | return (known_sum == sum); 33 | } 34 | 35 | int main() 36 | { 37 | int i; 38 | int num_failed=0; 39 | 40 | for(i = 0; i < REPETITIONS; i++) { 41 | if(!test_omp_parallel_private()) { 42 | num_failed++; 43 | } 44 | } 45 | return num_failed; 46 | } 47 | -------------------------------------------------------------------------------- /runtime/test/flush/omp_flush.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | #include "omp_my_sleep.h" 5 | 6 | int test_omp_flush() 7 | { 8 | int result1; 9 | int result2; 10 | int dummy; 11 | 12 | result1 = 0; 13 | result2 = 0; 14 | 15 | #pragma omp parallel 16 | { 17 | int rank; 18 | rank = omp_get_thread_num (); 19 | #pragma omp barrier 20 | if (rank == 1) { 21 | result2 = 3; 22 | #pragma omp flush (result2) 23 | dummy = result2; 24 | } 25 | if (rank == 0) { 26 | my_sleep(SLEEPTIME); 27 | #pragma omp flush (result2) 28 | result1 = result2; 29 | } 30 | } /* end of parallel */ 31 | return ((result1 == result2) && (result2 == dummy) && (result2 == 3)); 32 | } 33 | 34 | int main() 35 | { 36 | int i; 37 | int num_failed=0; 38 | 39 | for (i = 0; i < REPETITIONS; i++) { 40 | if(!test_omp_flush()) { 41 | num_failed++; 42 | } 43 | } 44 | return num_failed; 45 | } 46 | -------------------------------------------------------------------------------- /runtime/test/barrier/omp_barrier.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | #include "omp_my_sleep.h" 5 | 6 | int test_omp_barrier() 7 | { 8 | int result1; 9 | int result2; 10 | result1 = 0; 11 | result2 = 0; 12 | 13 | #pragma omp parallel 14 | { 15 | int rank; 16 | rank = omp_get_thread_num (); 17 | if (rank ==1) { 18 | my_sleep(((double)SLEEPTIME)/REPETITIONS); // give 1 sec to whole test 19 | result2 = 3; 20 | } 21 | #pragma omp barrier 22 | if (rank == 2) { 23 | result1 = result2; 24 | } 25 | } 26 | return (result1 == 3); 27 | } 28 | 29 | int main() 30 | { 31 | int i; 32 | int num_failed=0; 33 | 34 | #ifdef _OPENMP 35 | omp_set_dynamic(0); // prevent runtime to change number of threads 36 | omp_set_num_threads(4); // the test expects at least 3 threads 37 | for(i = 0; i < REPETITIONS; i++) { 38 | if(!test_omp_barrier()) { 39 | num_failed++; 40 | } 41 | } 42 | #endif 43 | return num_failed; 44 | } 45 | -------------------------------------------------------------------------------- /runtime/test/parallel/omp_parallel_default.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_parallel_default() 6 | { 7 | int i; 8 | int sum; 9 | int mysum; 10 | int known_sum; 11 | sum =0; 12 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2 ; 13 | 14 | #pragma omp parallel default(shared) private(i) private(mysum) 15 | { 16 | mysum = 0; 17 | #pragma omp for 18 | for (i = 1; i <= LOOPCOUNT; i++) { 19 | mysum = mysum + i; 20 | } 21 | #pragma omp critical 22 | { 23 | sum = sum + mysum; 24 | } /* end of critical */ 25 | } /* end of parallel */ 26 | if (known_sum != sum) { 27 | fprintf(stderr, "KNOWN_SUM = %d; SUM = %d\n", known_sum, sum); 28 | } 29 | return (known_sum == sum); 30 | } 31 | 32 | int main() 33 | { 34 | int i; 35 | int num_failed=0; 36 | 37 | for(i = 0; i < REPETITIONS; i++) { 38 | if(!test_omp_parallel_default()) { 39 | num_failed++; 40 | } 41 | } 42 | return num_failed; 43 | } 44 | -------------------------------------------------------------------------------- /runtime/test/worksharing/single/omp_single.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_single() 6 | { 7 | int nr_threads_in_single; 8 | int result; 9 | int nr_iterations; 10 | int i; 11 | 12 | nr_threads_in_single = 0; 13 | result = 0; 14 | nr_iterations = 0; 15 | 16 | #pragma omp parallel private(i) 17 | { 18 | for (i = 0; i < LOOPCOUNT; i++) { 19 | #pragma omp single 20 | { 21 | #pragma omp flush 22 | nr_threads_in_single++; 23 | #pragma omp flush 24 | nr_iterations++; 25 | nr_threads_in_single--; 26 | result = result + nr_threads_in_single; 27 | } 28 | } 29 | } 30 | return ((result == 0) && (nr_iterations == LOOPCOUNT)); 31 | } /* end of check_single*/ 32 | 33 | int main() 34 | { 35 | int i; 36 | int num_failed=0; 37 | 38 | for(i = 0; i < REPETITIONS; i++) { 39 | if(!test_omp_single()) { 40 | num_failed++; 41 | } 42 | } 43 | return num_failed; 44 | } 45 | -------------------------------------------------------------------------------- /runtime/src/kmp_ftn_stdcall.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * kmp_ftn_stdcall.cpp -- Fortran __stdcall linkage support for OpenMP. 3 | */ 4 | 5 | //===----------------------------------------------------------------------===// 6 | // 7 | // The LLVM Compiler Infrastructure 8 | // 9 | // This file is dual licensed under the MIT and the University of Illinois Open 10 | // Source Licenses. See LICENSE.txt for details. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "kmp.h" 15 | 16 | // Note: This string is not printed when KMP_VERSION=1. 17 | char const __kmp_version_ftnstdcall[] = 18 | KMP_VERSION_PREFIX "Fortran __stdcall OMP support: " 19 | #ifdef USE_FTN_STDCALL 20 | "yes"; 21 | #else 22 | "no"; 23 | #endif 24 | 25 | #ifdef USE_FTN_STDCALL 26 | 27 | #define FTN_STDCALL KMP_STDCALL 28 | #define KMP_FTN_ENTRIES USE_FTN_STDCALL 29 | 30 | #include "kmp_ftn_entry.h" 31 | #include "kmp_ftn_os.h" 32 | 33 | #endif /* USE_FTN_STDCALL */ 34 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_parallel_for_if.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | int test_omp_parallel_for_if() 7 | { 8 | int known_sum; 9 | int num_threads; 10 | int sum, sum2; 11 | int i; 12 | int control; 13 | 14 | control = 0; 15 | num_threads=0; 16 | sum = 0; 17 | sum2 = 0; 18 | 19 | #pragma omp parallel for private(i) if (control==1) 20 | for (i=0; i <= LOOPCOUNT; i++) { 21 | num_threads = omp_get_num_threads(); 22 | sum = sum + i; 23 | } 24 | 25 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; 26 | fprintf(stderr, "Number of threads determined by" 27 | " omp_get_num_threads: %d\n", num_threads); 28 | return (known_sum == sum && num_threads == 1); 29 | } /* end of check_parallel_for_private */ 30 | 31 | int main() 32 | { 33 | int i; 34 | int num_failed=0; 35 | 36 | for(i = 0; i < REPETITIONS; i++) { 37 | if(!test_omp_parallel_for_if()) { 38 | num_failed++; 39 | } 40 | } 41 | return num_failed; 42 | } 43 | -------------------------------------------------------------------------------- /runtime/test/ompt/synchronization/flush.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s 2 | // REQUIRES: ompt 3 | // GCC generates code that does not call the runtime for the flush construct 4 | // XFAIL: gcc 5 | 6 | #include "callback.h" 7 | #include 8 | 9 | int main() { 10 | #pragma omp parallel num_threads(2) 11 | { 12 | int tid = omp_get_thread_num(); 13 | 14 | #pragma omp flush 15 | print_current_address(1); 16 | } 17 | 18 | return 0; 19 | } 20 | // Check if libomp supports the callbacks for this test. 21 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_flush' 22 | 23 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 24 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_flush: 25 | // CHECK-SAME: codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]] 26 | // CHECK: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS]] 27 | // 28 | // CHECK: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_flush: 29 | // CHECK-SAME: codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]] 30 | // CHECK: {{^}}[[THREAD_ID]]: current_address={{.*}}[[RETURN_ADDRESS]] 31 | -------------------------------------------------------------------------------- /runtime/test/lock/omp_nest_lock.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | omp_nest_lock_t lck; 6 | 7 | int test_omp_nest_lock() 8 | { 9 | int nr_threads_in_single = 0; 10 | int result = 0; 11 | int nr_iterations = 0; 12 | int i; 13 | 14 | omp_init_nest_lock(&lck); 15 | #pragma omp parallel shared(lck) 16 | { 17 | #pragma omp for 18 | for(i = 0; i < LOOPCOUNT; i++) { 19 | omp_set_nest_lock(&lck); 20 | #pragma omp flush 21 | nr_threads_in_single++; 22 | #pragma omp flush 23 | nr_iterations++; 24 | nr_threads_in_single--; 25 | result = result + nr_threads_in_single; 26 | omp_unset_nest_lock(&lck); 27 | } 28 | } 29 | omp_destroy_nest_lock(&lck); 30 | 31 | return ((result == 0) && (nr_iterations == LOOPCOUNT)); 32 | } 33 | 34 | int main() 35 | { 36 | int i; 37 | int num_failed=0; 38 | 39 | for(i = 0; i < REPETITIONS; i++) { 40 | if(!test_omp_nest_lock()) { 41 | num_failed++; 42 | } 43 | } 44 | return num_failed; 45 | } 46 | -------------------------------------------------------------------------------- /runtime/test/parallel/omp_parallel_firstprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | //static int sum1 = 789; 7 | 8 | int test_omp_parallel_firstprivate() 9 | { 10 | int sum, num_threads,sum1; 11 | int known_sum; 12 | 13 | sum = 0; 14 | sum1=7; 15 | num_threads = 0; 16 | 17 | #pragma omp parallel firstprivate(sum1) 18 | { 19 | /*printf("sum1=%d\n",sum1);*/ 20 | int i; 21 | #pragma omp for 22 | for (i = 1; i < 1000; i++) { 23 | sum1 = sum1 + i; 24 | } /*end of for*/ 25 | #pragma omp critical 26 | { 27 | sum = sum + sum1; 28 | num_threads++; 29 | } /*end of critical*/ 30 | } /* end of parallel*/ 31 | known_sum = (999 * 1000) / 2 + 7 * num_threads; 32 | return (known_sum == sum); 33 | } 34 | 35 | int main() 36 | { 37 | int i; 38 | int num_failed=0; 39 | 40 | for(i = 0; i < REPETITIONS; i++) { 41 | if(!test_omp_parallel_firstprivate()) { 42 | num_failed++; 43 | } 44 | } 45 | return num_failed; 46 | } 47 | -------------------------------------------------------------------------------- /runtime/test/parallel/omp_parallel_copyin.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | static int sum1 = 789; 7 | #pragma omp threadprivate(sum1) 8 | 9 | int test_omp_parallel_copyin() 10 | { 11 | int sum, num_threads; 12 | int known_sum; 13 | 14 | sum = 0; 15 | sum1 = 7; 16 | num_threads = 0; 17 | 18 | #pragma omp parallel copyin(sum1) 19 | { 20 | /*printf("sum1=%d\n",sum1);*/ 21 | int i; 22 | #pragma omp for 23 | for (i = 1; i < 1000; i++) { 24 | sum1 = sum1 + i; 25 | } /*end of for*/ 26 | #pragma omp critical 27 | { 28 | sum = sum + sum1; 29 | num_threads++; 30 | } /*end of critical*/ 31 | } /* end of parallel*/ 32 | known_sum = (999 * 1000) / 2 + 7 * num_threads; 33 | return (known_sum == sum); 34 | } 35 | 36 | int main() 37 | { 38 | int i; 39 | int num_failed=0; 40 | 41 | for(i = 0; i < REPETITIONS; i++) { 42 | if(!test_omp_parallel_copyin()) { 43 | num_failed++; 44 | } 45 | } 46 | return num_failed; 47 | } 48 | -------------------------------------------------------------------------------- /runtime/test/threadprivate/omp_threadprivate_for.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include "omp_testsuite.h" 3 | #include 4 | #include 5 | 6 | static int i; 7 | #pragma omp threadprivate(i) 8 | 9 | int test_omp_threadprivate_for() 10 | { 11 | int known_sum; 12 | int sum; 13 | 14 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; 15 | sum = 0; 16 | 17 | #pragma omp parallel 18 | { 19 | int sum0 = 0, i0; 20 | #pragma omp for 21 | for (i0 = 1; i0 <= LOOPCOUNT; i0++) { 22 | i = i0; 23 | sum0 = sum0 + i; 24 | } 25 | #pragma omp critical 26 | { 27 | sum = sum + sum0; 28 | } 29 | } /* end of parallel */ 30 | 31 | if (known_sum != sum ) { 32 | fprintf(stderr, " known_sum = %d, sum = %d\n", known_sum, sum); 33 | } 34 | return (known_sum == sum); 35 | } /* end of check_threadprivate*/ 36 | 37 | int main() 38 | { 39 | int i; 40 | int num_failed=0; 41 | 42 | for(i = 0; i < REPETITIONS; i++) { 43 | if(!test_omp_threadprivate_for()) { 44 | num_failed++; 45 | } 46 | } 47 | return num_failed; 48 | } 49 | -------------------------------------------------------------------------------- /runtime/test/master/omp_master_3.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_master_3() 6 | { 7 | int nthreads; 8 | int executing_thread; 9 | int tid_result = 0; /* counts up the number of wrong thread no. for 10 | the master thread. (Must be 0) */ 11 | nthreads = 0; 12 | executing_thread = -1; 13 | 14 | #pragma omp parallel 15 | { 16 | #pragma omp master 17 | { 18 | int tid = omp_get_thread_num(); 19 | if (tid != 0) { 20 | #pragma omp critical 21 | { tid_result++; } 22 | } 23 | #pragma omp critical 24 | { 25 | nthreads++; 26 | } 27 | executing_thread = omp_get_thread_num (); 28 | } /* end of master*/ 29 | } /* end of parallel*/ 30 | return ((nthreads == 1) && (executing_thread == 0) && (tid_result == 0)); 31 | } 32 | 33 | int main() 34 | { 35 | int i; 36 | int num_failed=0; 37 | 38 | for(i = 0; i < REPETITIONS; i++) { 39 | if(!test_omp_master_3()) { 40 | num_failed++; 41 | } 42 | } 43 | return num_failed; 44 | } 45 | -------------------------------------------------------------------------------- /runtime/src/kmp_ftn_extra.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * kmp_ftn_extra.cpp -- Fortran 'extra' linkage support for OpenMP. 3 | */ 4 | 5 | //===----------------------------------------------------------------------===// 6 | // 7 | // The LLVM Compiler Infrastructure 8 | // 9 | // This file is dual licensed under the MIT and the University of Illinois Open 10 | // Source Licenses. See LICENSE.txt for details. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "kmp.h" 15 | #include "kmp_affinity.h" 16 | 17 | #if KMP_OS_WINDOWS 18 | #define KMP_FTN_ENTRIES KMP_FTN_PLAIN 19 | #elif KMP_OS_UNIX 20 | #define KMP_FTN_ENTRIES KMP_FTN_APPEND 21 | #endif 22 | 23 | // Note: This string is not printed when KMP_VERSION=1. 24 | char const __kmp_version_ftnextra[] = 25 | KMP_VERSION_PREFIX "Fortran \"extra\" OMP support: " 26 | #ifdef KMP_FTN_ENTRIES 27 | "yes"; 28 | #define FTN_STDCALL /* nothing to do */ 29 | #include "kmp_ftn_os.h" 30 | #include "kmp_ftn_entry.h" 31 | #else 32 | "no"; 33 | #endif /* KMP_FTN_ENTRIES */ 34 | -------------------------------------------------------------------------------- /libomptarget/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##===----------------------------------------------------------------------===## 2 | # 3 | # The LLVM Compiler Infrastructure 4 | # 5 | # This file is dual licensed under the MIT and the University of Illinois Open 6 | # Source Licenses. See LICENSE.txt for details. 7 | # 8 | ##===----------------------------------------------------------------------===## 9 | # 10 | # Build offloading library libomptarget.so. 11 | # 12 | ##===----------------------------------------------------------------------===## 13 | 14 | libomptarget_say("Building offloading runtime library libomptarget.") 15 | 16 | set(src_files 17 | api.cpp 18 | device.cpp 19 | interface.cpp 20 | rtl.cpp 21 | omptarget.cpp 22 | ) 23 | 24 | # Build libomptarget library with libdl dependency. 25 | add_library(omptarget SHARED ${src_files}) 26 | target_link_libraries(omptarget 27 | ${CMAKE_DL_LIBS} 28 | "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports") 29 | 30 | # Install libomptarget under the lib destination folder. 31 | install(TARGETS omptarget LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}") 32 | -------------------------------------------------------------------------------- /runtime/test/env/omp_wait_policy.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile && env OMP_WAIT_POLICY=active %libomp-run active 2 | // RUN: %libomp-compile && env OMP_WAIT_POLICY=passive %libomp-run passive 3 | // 4 | // OMP_WAIT_POLICY=active should imply blocktime == INT_MAX 5 | // i.e., threads spin-wait forever 6 | // OMP_WAIT_POLICY=passive should imply blocktime == 0 7 | // i.e., threads immediately sleep 8 | #include 9 | #include 10 | #include 11 | #include "omp_testsuite.h" 12 | 13 | void usage() { 14 | fprintf(stderr, "usage: omp_wait_policy active|passive\n"); 15 | } 16 | 17 | int main(int argc, char** argv) 18 | { 19 | int blocktime, retval=1; 20 | const char* env_var_value; 21 | 22 | if (argc != 2) { 23 | usage(); 24 | return 1; 25 | } 26 | 27 | blocktime = kmp_get_blocktime(); 28 | 29 | env_var_value = argv[1]; 30 | if (!strcmp(env_var_value, "active")) { 31 | retval = (blocktime != INT_MAX); 32 | } else if (!strcmp(env_var_value, "passive")) { 33 | retval = (blocktime != 0); 34 | } else { 35 | usage(); 36 | retval = 1; 37 | } 38 | 39 | return retval; 40 | } 41 | -------------------------------------------------------------------------------- /runtime/test/worksharing/sections/omp_parallel_sections_firstprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_parallel_sections_firstprivate() 6 | { 7 | int sum; 8 | int sum0; 9 | int known_sum; 10 | 11 | sum =7; 12 | sum0=11; 13 | 14 | #pragma omp parallel sections firstprivate(sum0) 15 | { 16 | #pragma omp section 17 | { 18 | #pragma omp critical 19 | { 20 | sum= sum+sum0; 21 | } 22 | } 23 | #pragma omp section 24 | { 25 | #pragma omp critical 26 | { 27 | sum= sum+sum0; 28 | } 29 | } 30 | #pragma omp section 31 | { 32 | #pragma omp critical 33 | { 34 | sum= sum+sum0; 35 | } 36 | } 37 | } 38 | 39 | known_sum=11*3+7; 40 | return (known_sum==sum); 41 | } /* end of check_section_firstprivate*/ 42 | 43 | int main() 44 | { 45 | int i; 46 | int num_failed=0; 47 | 48 | for(i = 0; i < REPETITIONS; i++) { 49 | if(!test_omp_parallel_sections_firstprivate()) { 50 | num_failed++; 51 | } 52 | } 53 | return num_failed; 54 | } 55 | -------------------------------------------------------------------------------- /libomptarget/deviceRTLs/nvptx/src/cancel.cu: -------------------------------------------------------------------------------- 1 | //===------ cancel.cu - NVPTX OpenMP cancel interface ------------ CUDA -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.txt for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // Interface to be used in the implementation of OpenMP cancel. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "omptarget-nvptx.h" 15 | 16 | EXTERN int32_t __kmpc_cancellationpoint(kmp_Indent *loc, int32_t global_tid, 17 | int32_t cancelVal) { 18 | PRINT(LD_IO, "call kmpc_cancellationpoint(cancel val %d)\n", cancelVal); 19 | // disabled 20 | return FALSE; 21 | } 22 | 23 | EXTERN int32_t __kmpc_cancel(kmp_Indent *loc, int32_t global_tid, 24 | int32_t cancelVal) { 25 | PRINT(LD_IO, "call kmpc_cancel(cancel val %d)\n", cancelVal); 26 | // disabled 27 | return FALSE; 28 | } 29 | -------------------------------------------------------------------------------- /libomptarget/cmake/Modules/LibomptargetUtils.cmake: -------------------------------------------------------------------------------- 1 | # 2 | #//===----------------------------------------------------------------------===// 3 | #// 4 | #// The LLVM Compiler Infrastructure 5 | #// 6 | #// This file is dual licensed under the MIT and the University of Illinois Open 7 | #// Source Licenses. See LICENSE.txt for details. 8 | #// 9 | #//===----------------------------------------------------------------------===// 10 | # 11 | 12 | # void libomptarget_say(string message_to_user); 13 | # - prints out message_to_user 14 | macro(libomptarget_say message_to_user) 15 | message(STATUS "LIBOMPTARGET: ${message_to_user}") 16 | endmacro() 17 | 18 | # void libomptarget_warning_say(string message_to_user); 19 | # - prints out message_to_user with a warning 20 | macro(libomptarget_warning_say message_to_user) 21 | message(WARNING "LIBOMPTARGET: ${message_to_user}") 22 | endmacro() 23 | 24 | # void libomptarget_error_say(string message_to_user); 25 | # - prints out message_to_user with an error and exits cmake 26 | macro(libomptarget_error_say message_to_user) 27 | message(FATAL_ERROR "LIBOMPTARGET: ${message_to_user}") 28 | endmacro() 29 | -------------------------------------------------------------------------------- /runtime/test/lock/omp_test_nest_lock.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | static omp_nest_lock_t lck; 6 | 7 | int test_omp_test_nest_lock() 8 | { 9 | int nr_threads_in_single = 0; 10 | int result = 0; 11 | int nr_iterations = 0; 12 | int i; 13 | 14 | omp_init_nest_lock (&lck); 15 | #pragma omp parallel shared(lck) 16 | { 17 | #pragma omp for 18 | for (i = 0; i < LOOPCOUNT; i++) 19 | { 20 | /*omp_set_lock(&lck);*/ 21 | while(!omp_test_nest_lock (&lck)) 22 | {}; 23 | #pragma omp flush 24 | nr_threads_in_single++; 25 | #pragma omp flush 26 | nr_iterations++; 27 | nr_threads_in_single--; 28 | result = result + nr_threads_in_single; 29 | omp_unset_nest_lock (&lck); 30 | } 31 | } 32 | omp_destroy_nest_lock (&lck); 33 | return ((result == 0) && (nr_iterations == LOOPCOUNT)); 34 | } 35 | 36 | int main() 37 | { 38 | int i; 39 | int num_failed=0; 40 | 41 | for(i = 0; i < REPETITIONS; i++) { 42 | if(!test_omp_test_nest_lock()) { 43 | num_failed++; 44 | } 45 | } 46 | return num_failed; 47 | } 48 | -------------------------------------------------------------------------------- /runtime/test/lock/omp_lock.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | // RUN: env KMP_LOCK_KIND=tas KMP_SPIN_BACKOFF_PARAMS=2048,200 %libomp-run 3 | // RUN: env KMP_LOCK_KIND=futex %libomp-run 4 | #include 5 | #include "omp_testsuite.h" 6 | 7 | omp_lock_t lck; 8 | 9 | int test_omp_lock() 10 | { 11 | int nr_threads_in_single = 0; 12 | int result = 0; 13 | int nr_iterations = 0; 14 | int i; 15 | 16 | omp_init_lock(&lck); 17 | #pragma omp parallel shared(lck) 18 | { 19 | #pragma omp for 20 | for(i = 0; i < LOOPCOUNT; i++) { 21 | omp_set_lock(&lck); 22 | #pragma omp flush 23 | nr_threads_in_single++; 24 | #pragma omp flush 25 | nr_iterations++; 26 | nr_threads_in_single--; 27 | result = result + nr_threads_in_single; 28 | omp_unset_lock(&lck); 29 | } 30 | } 31 | omp_destroy_lock(&lck); 32 | 33 | return ((result == 0) && (nr_iterations == LOOPCOUNT)); 34 | } 35 | 36 | int main() 37 | { 38 | int i; 39 | int num_failed=0; 40 | 41 | for(i = 0; i < REPETITIONS; i++) { 42 | if(!test_omp_lock()) { 43 | num_failed++; 44 | } 45 | } 46 | return num_failed; 47 | } 48 | -------------------------------------------------------------------------------- /runtime/test/lock/omp_test_lock.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | // RUN: env KMP_LOCK_KIND=tas %libomp-run 3 | // RUN: env KMP_LOCK_KIND=futex %libomp-run 4 | #include 5 | #include "omp_testsuite.h" 6 | 7 | omp_lock_t lck; 8 | 9 | int test_omp_test_lock() 10 | { 11 | int nr_threads_in_single = 0; 12 | int result = 0; 13 | int nr_iterations = 0; 14 | int i; 15 | 16 | omp_init_lock (&lck); 17 | #pragma omp parallel shared(lck) 18 | { 19 | #pragma omp for 20 | for (i = 0; i < LOOPCOUNT; i++) { 21 | while (!omp_test_lock (&lck)) 22 | {}; 23 | #pragma omp flush 24 | nr_threads_in_single++; 25 | #pragma omp flush 26 | nr_iterations++; 27 | nr_threads_in_single--; 28 | result = result + nr_threads_in_single; 29 | omp_unset_lock (&lck); 30 | } 31 | } 32 | omp_destroy_lock(&lck); 33 | return ((result == 0) && (nr_iterations == LOOPCOUNT)); 34 | } 35 | 36 | int main() 37 | { 38 | int i; 39 | int num_failed=0; 40 | 41 | for(i = 0; i < REPETITIONS; i++) { 42 | if(!test_omp_test_lock()) { 43 | num_failed++; 44 | } 45 | } 46 | return num_failed; 47 | } 48 | -------------------------------------------------------------------------------- /runtime/test/tasking/omp_task_imp_firstprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | /* Utility function do spend some time in a loop */ 7 | int test_omp_task_imp_firstprivate() 8 | { 9 | int i=5; 10 | int k = 0; 11 | int result = 0; 12 | int task_result = 1; 13 | #pragma omp parallel firstprivate(i) 14 | { 15 | #pragma omp single 16 | { 17 | for (k = 0; k < NUM_TASKS; k++) { 18 | #pragma omp task shared(result , task_result) 19 | { 20 | int j; 21 | //check if i is private 22 | if(i != 5) 23 | task_result = 0; 24 | for(j = 0; j < NUM_TASKS; j++) 25 | i++; 26 | //this should be firstprivate implicitly 27 | } 28 | } 29 | #pragma omp taskwait 30 | result = (task_result && i==5); 31 | } 32 | } 33 | return result; 34 | } 35 | 36 | int main() 37 | { 38 | int i; 39 | int num_failed=0; 40 | 41 | for(i = 0; i < REPETITIONS; i++) { 42 | if(!test_omp_task_imp_firstprivate()) { 43 | num_failed++; 44 | } 45 | } 46 | return num_failed; 47 | } 48 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_parallel_for_private.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | /*! Utility function to spend some time in a loop */ 7 | static void do_some_work (void) 8 | { 9 | int i; 10 | double sum = 0; 11 | for(i = 0; i < 1000; i++){ 12 | sum += sqrt (i); 13 | } 14 | } 15 | 16 | int test_omp_parallel_for_private() 17 | { 18 | int sum; 19 | int i; 20 | int i2; 21 | int known_sum; 22 | 23 | sum =0; 24 | i2=0; 25 | 26 | #pragma omp parallel for reduction(+:sum) schedule(static,1) private(i) private(i2) 27 | for (i=1;i<=LOOPCOUNT;i++) 28 | { 29 | i2 = i; 30 | #pragma omp flush 31 | do_some_work (); 32 | #pragma omp flush 33 | sum = sum + i2; 34 | } /*end of for*/ 35 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; 36 | return (known_sum == sum); 37 | } /* end of check_parallel_for_private */ 38 | 39 | int main() 40 | { 41 | int i; 42 | int num_failed=0; 43 | 44 | for(i = 0; i < REPETITIONS; i++) { 45 | if(!test_omp_parallel_for_private()) { 46 | num_failed++; 47 | } 48 | } 49 | return num_failed; 50 | } 51 | -------------------------------------------------------------------------------- /runtime/src/kmp_ftn_cdecl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * kmp_ftn_cdecl.cpp -- Fortran __cdecl linkage support for OpenMP. 3 | */ 4 | 5 | //===----------------------------------------------------------------------===// 6 | // 7 | // The LLVM Compiler Infrastructure 8 | // 9 | // This file is dual licensed under the MIT and the University of Illinois Open 10 | // Source Licenses. See LICENSE.txt for details. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "kmp.h" 15 | #include "kmp_affinity.h" 16 | 17 | #if KMP_OS_WINDOWS 18 | #if defined KMP_WIN_CDECL || !defined KMP_DYNAMIC_LIB 19 | #define KMP_FTN_ENTRIES KMP_FTN_UPPER 20 | #endif 21 | #elif KMP_OS_UNIX 22 | #define KMP_FTN_ENTRIES KMP_FTN_PLAIN 23 | #endif 24 | 25 | // Note: This string is not printed when KMP_VERSION=1. 26 | char const __kmp_version_ftncdecl[] = 27 | KMP_VERSION_PREFIX "Fortran __cdecl OMP support: " 28 | #ifdef KMP_FTN_ENTRIES 29 | "yes"; 30 | #define FTN_STDCALL /* no stdcall */ 31 | #include "kmp_ftn_os.h" 32 | #include "kmp_ftn_entry.h" 33 | #else 34 | "no"; 35 | #endif /* KMP_FTN_ENTRIES */ 36 | -------------------------------------------------------------------------------- /runtime/test/parallel/omp_parallel_num_threads.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_parallel_num_threads() 6 | { 7 | int num_failed; 8 | int threads; 9 | int nthreads; 10 | int max_threads = 0; 11 | 12 | num_failed = 0; 13 | 14 | /* first we check how many threads are available */ 15 | #pragma omp parallel 16 | { 17 | #pragma omp master 18 | max_threads = omp_get_num_threads (); 19 | } 20 | 21 | /* we increase the number of threads from one to maximum:*/ 22 | for(threads = 1; threads <= max_threads; threads++) { 23 | nthreads = 0; 24 | #pragma omp parallel reduction(+:num_failed) num_threads(threads) 25 | { 26 | num_failed = num_failed + !(threads == omp_get_num_threads()); 27 | #pragma omp atomic 28 | nthreads += 1; 29 | } 30 | num_failed = num_failed + !(nthreads == threads); 31 | } 32 | return (!num_failed); 33 | } 34 | 35 | int main() 36 | { 37 | int i; 38 | int num_failed=0; 39 | 40 | for(i = 0; i < REPETITIONS; i++) { 41 | if(!test_omp_parallel_num_threads()) { 42 | num_failed++; 43 | } 44 | } 45 | return num_failed; 46 | } 47 | -------------------------------------------------------------------------------- /runtime/test/worksharing/sections/omp_section_firstprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_section_firstprivate() 6 | { 7 | int sum; 8 | int sum0; 9 | int known_sum; 10 | 11 | sum0 = 11; 12 | sum = 7; 13 | #pragma omp parallel 14 | { 15 | #pragma omp sections firstprivate(sum0) 16 | { 17 | #pragma omp section 18 | { 19 | #pragma omp critical 20 | { 21 | sum = sum + sum0; 22 | } 23 | } 24 | #pragma omp section 25 | { 26 | #pragma omp critical 27 | { 28 | sum = sum + sum0; 29 | } 30 | } 31 | #pragma omp section 32 | { 33 | #pragma omp critical 34 | { 35 | sum = sum + sum0; 36 | } 37 | } 38 | } 39 | } 40 | known_sum = 11 * 3 + 7; 41 | return (known_sum == sum); 42 | } /* end of check_section_firstprivate*/ 43 | 44 | int main() 45 | { 46 | int i; 47 | int num_failed=0; 48 | 49 | for(i = 0; i < REPETITIONS; i++) { 50 | if(!test_omp_section_firstprivate()) { 51 | num_failed++; 52 | } 53 | } 54 | return num_failed; 55 | } 56 | -------------------------------------------------------------------------------- /runtime/src/kmp_import.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * kmp_import.cpp 3 | */ 4 | 5 | //===----------------------------------------------------------------------===// 6 | // 7 | // The LLVM Compiler Infrastructure 8 | // 9 | // This file is dual licensed under the MIT and the University of Illinois Open 10 | // Source Licenses. See LICENSE.txt for details. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | /* Object generated from this source file is linked to Windows* OS DLL import 15 | library (libompmd.lib) only! It is not a part of regular static or dynamic 16 | OpenMP RTL. Any code that just needs to go in the libompmd.lib (but not in 17 | libompmt.lib and libompmd.dll) should be placed in this file. */ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /*These symbols are required for mutual exclusion with Microsoft OpenMP RTL 24 | (and compatibility with MS Compiler). */ 25 | 26 | int _You_must_link_with_exactly_one_OpenMP_library = 1; 27 | int _You_must_link_with_Intel_OpenMP_library = 1; 28 | int _You_must_link_with_Microsoft_OpenMP_library = 1; 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | // end of file // 35 | -------------------------------------------------------------------------------- /runtime/src/kmp_io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * kmp_io.h -- RTL IO header file. 3 | */ 4 | 5 | //===----------------------------------------------------------------------===// 6 | // 7 | // The LLVM Compiler Infrastructure 8 | // 9 | // This file is dual licensed under the MIT and the University of Illinois Open 10 | // Source Licenses. See LICENSE.txt for details. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef KMP_IO_H 15 | #define KMP_IO_H 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /* ------------------------------------------------------------------------ */ 22 | 23 | enum kmp_io { kmp_out = 0, kmp_err }; 24 | 25 | extern kmp_bootstrap_lock_t __kmp_stdio_lock; /* Control stdio functions */ 26 | extern kmp_bootstrap_lock_t 27 | __kmp_console_lock; /* Control console initialization */ 28 | 29 | extern void __kmp_vprintf(enum kmp_io __kmp_io, char const *format, va_list ap); 30 | extern void __kmp_printf(char const *format, ...); 31 | extern void __kmp_printf_no_lock(char const *format, ...); 32 | extern void __kmp_close_console(void); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* KMP_IO_H */ 39 | -------------------------------------------------------------------------------- /runtime/test/ompt/misc/control_tool.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | FileCheck %s 2 | // REQUIRES: ompt 3 | // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7 4 | #define TEST_NEED_PRINT_FRAME_FROM_OUTLINED_FN 5 | #include "callback.h" 6 | #include 7 | 8 | int main() 9 | { 10 | #pragma omp parallel num_threads(1) 11 | { 12 | print_frame_from_outlined_fn(1); 13 | print_frame(0); 14 | omp_control_tool(omp_control_tool_flush, 1, NULL); 15 | print_current_address(0); 16 | } 17 | 18 | // Check if libomp supports the callbacks for this test. 19 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_control_tool' 20 | 21 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 22 | 23 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: __builtin_frame_address({{.}})=[[EXIT_FRAME:0x[0-f]*]] 24 | // CHECK: {{^}}[[MASTER_ID]]: __builtin_frame_address(0)=[[REENTER_FRAME:0x[0-f]*]] 25 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_control_tool: command=3, modifier=1, arg=[[NULL]], codeptr_ra=[[RETURN_ADDRESS:0x[0-f]*]], current_task_frame.exit=[[EXIT_FRAME]], current_task_frame.reenter=[[REENTER_FRAME]] 26 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS]] 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_for_firstprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | int sum1; 7 | #pragma omp threadprivate(sum1) 8 | 9 | int test_omp_for_firstprivate() 10 | { 11 | int sum; 12 | int sum0; 13 | int known_sum; 14 | int threadsnum; 15 | 16 | sum = 0; 17 | sum0 = 12345; 18 | sum1 = 0; 19 | 20 | #pragma omp parallel 21 | { 22 | #pragma omp single 23 | { 24 | threadsnum=omp_get_num_threads(); 25 | } 26 | /* sum0 = 0; */ 27 | 28 | int i; 29 | #pragma omp for firstprivate(sum0) 30 | for (i = 1; i <= LOOPCOUNT; i++) { 31 | sum0 = sum0 + i; 32 | sum1 = sum0; 33 | } /* end of for */ 34 | 35 | #pragma omp critical 36 | { 37 | sum = sum + sum1; 38 | } /* end of critical */ 39 | } /* end of parallel */ 40 | known_sum = 12345* threadsnum+ (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; 41 | return (known_sum == sum); 42 | } 43 | 44 | int main() 45 | { 46 | int i; 47 | int num_failed=0; 48 | 49 | for(i = 0; i < REPETITIONS; i++) { 50 | if(!test_omp_for_firstprivate()) { 51 | num_failed++; 52 | } 53 | } 54 | return num_failed; 55 | } 56 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_for_collapse.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | /* Utility function to check that i is increasing monotonically 7 | with each call */ 8 | static int check_i_islarger (int i) 9 | { 10 | static int last_i; 11 | int islarger; 12 | if (i==1) 13 | last_i=0; 14 | islarger = ((i >= last_i)&&(i - last_i<=1)); 15 | last_i = i; 16 | return (islarger); 17 | } 18 | 19 | int test_omp_for_collapse() 20 | { 21 | int is_larger = 1; 22 | 23 | #pragma omp parallel 24 | { 25 | int i,j; 26 | int my_islarger = 1; 27 | #pragma omp for private(i,j) schedule(static,1) collapse(2) ordered 28 | for (i = 1; i < 100; i++) { 29 | for (j =1; j <100; j++) { 30 | #pragma omp ordered 31 | my_islarger = check_i_islarger(i)&&my_islarger; 32 | } 33 | } 34 | #pragma omp critical 35 | is_larger = is_larger && my_islarger; 36 | } 37 | return (is_larger); 38 | } 39 | 40 | int main() 41 | { 42 | int i; 43 | int num_failed=0; 44 | 45 | for(i = 0; i < REPETITIONS; i++) { 46 | if(!test_omp_for_collapse()) { 47 | num_failed++; 48 | } 49 | } 50 | return num_failed; 51 | } 52 | -------------------------------------------------------------------------------- /runtime/test/ompt/synchronization/barrier/for_simd.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | FileCheck %s 2 | // REQUIRES: ompt 3 | // XFAIL: gcc-4 4 | 5 | #include "callback.h" 6 | #include 7 | 8 | int main() 9 | { 10 | int y[] = {0,1,2,3}; 11 | 12 | int i; 13 | #pragma omp for simd 14 | for (i = 0; i < 4; i++) 15 | { 16 | y[i]++; 17 | } 18 | 19 | 20 | // Check if libomp supports the callbacks for this test. 21 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_sync_region' 22 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_sync_region_wait' 23 | 24 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 25 | 26 | // master thread implicit barrier at simd loop end 27 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_barrier_begin: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra={{0x[0-f]+}} 28 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_barrier_begin: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra={{0x[0-f]+}} 29 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_barrier_end: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra={{0x[0-f]+}} 30 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_barrier_end: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra={{0x[0-f]+}} 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /libomptarget/deviceRTLs/nvptx/src/critical.cu: -------------------------------------------------------------------------------- 1 | //===------ critical.cu - NVPTX OpenMP critical ------------------ CUDA -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.txt for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file contains the implementation of critical with KMPC interface 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include 15 | 16 | #include "omptarget-nvptx.h" 17 | 18 | EXTERN 19 | void __kmpc_critical(kmp_Indent *loc, int32_t global_tid, 20 | kmp_CriticalName *lck) { 21 | PRINT0(LD_IO, "call to kmpc_critical()\n"); 22 | omptarget_nvptx_TeamDescr &teamDescr = getMyTeamDescriptor(); 23 | omp_set_lock(teamDescr.CriticalLock()); 24 | } 25 | 26 | EXTERN 27 | void __kmpc_end_critical(kmp_Indent *loc, int32_t global_tid, 28 | kmp_CriticalName *lck) { 29 | PRINT0(LD_IO, "call to kmpc_end_critical()\n"); 30 | omptarget_nvptx_TeamDescr &teamDescr = getMyTeamDescriptor(); 31 | omp_unset_lock(teamDescr.CriticalLock()); 32 | } 33 | -------------------------------------------------------------------------------- /runtime/test/tasking/omp_task_firstprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | int test_omp_task_firstprivate() 7 | { 8 | int i; 9 | int sum = 1234; 10 | int known_sum; 11 | int result = 0; /* counts the wrong sums from tasks */ 12 | 13 | known_sum = 1234 + (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; 14 | 15 | #pragma omp parallel 16 | { 17 | #pragma omp single 18 | { 19 | for (i = 0; i < NUM_TASKS; i++) { 20 | #pragma omp task firstprivate(sum) 21 | { 22 | int j; 23 | for (j = 0; j <= LOOPCOUNT; j++) { 24 | #pragma omp flush 25 | sum += j; 26 | } 27 | 28 | /* check if calculated sum was right */ 29 | if (sum != known_sum) { 30 | #pragma omp critical 31 | { result++; } 32 | } 33 | } /* omp task */ 34 | } /* for loop */ 35 | } /* omp single */ 36 | } /* omp parallel */ 37 | return (result == 0); 38 | } 39 | 40 | int main() 41 | { 42 | int i; 43 | int num_failed=0; 44 | 45 | for(i = 0; i < REPETITIONS; i++) { 46 | if(!test_omp_task_firstprivate()) { 47 | num_failed++; 48 | } 49 | } 50 | return num_failed; 51 | } 52 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_for_lastprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | int sum0; 7 | #pragma omp threadprivate(sum0) 8 | 9 | int test_omp_for_lastprivate() 10 | { 11 | int sum = 0; 12 | int known_sum; 13 | int i0; 14 | 15 | i0 = -1; 16 | 17 | #pragma omp parallel 18 | { 19 | sum0 = 0; 20 | { /* Begin of orphaned block */ 21 | int i; 22 | #pragma omp for schedule(static,7) lastprivate(i0) 23 | for (i = 1; i <= LOOPCOUNT; i++) { 24 | sum0 = sum0 + i; 25 | i0 = i; 26 | } /* end of for */ 27 | } /* end of orphaned block */ 28 | 29 | #pragma omp critical 30 | { 31 | sum = sum + sum0; 32 | } /* end of critical */ 33 | } /* end of parallel */ 34 | 35 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; 36 | fprintf(stderr, "known_sum = %d , sum = %d\n",known_sum,sum); 37 | fprintf(stderr, "LOOPCOUNT = %d , i0 = %d\n",LOOPCOUNT,i0); 38 | return ((known_sum == sum) && (i0 == LOOPCOUNT)); 39 | } 40 | 41 | int main() 42 | { 43 | int i; 44 | int num_failed=0; 45 | 46 | for (i = 0; i < REPETITIONS; i++) { 47 | if(!test_omp_for_lastprivate()) { 48 | num_failed++; 49 | } 50 | } 51 | return num_failed; 52 | } 53 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_for_ordered.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | static int last_i = 0; 7 | 8 | /* Utility function to check that i is increasing monotonically 9 | with each call */ 10 | static int check_i_islarger (int i) 11 | { 12 | int islarger; 13 | islarger = (i > last_i); 14 | last_i = i; 15 | return (islarger); 16 | } 17 | 18 | int test_omp_for_ordered() 19 | { 20 | int sum; 21 | int is_larger = 1; 22 | int known_sum; 23 | 24 | last_i = 0; 25 | sum = 0; 26 | 27 | #pragma omp parallel 28 | { 29 | int i; 30 | int my_islarger = 1; 31 | #pragma omp for schedule(static,1) ordered 32 | for (i = 1; i < 100; i++) { 33 | #pragma omp ordered 34 | { 35 | my_islarger = check_i_islarger(i) && my_islarger; 36 | sum = sum + i; 37 | } 38 | } 39 | #pragma omp critical 40 | { 41 | is_larger = is_larger && my_islarger; 42 | } 43 | } 44 | 45 | known_sum=(99 * 100) / 2; 46 | return ((known_sum == sum) && is_larger); 47 | } 48 | 49 | int main() 50 | { 51 | int i; 52 | int num_failed=0; 53 | 54 | for(i = 0; i < REPETITIONS; i++) { 55 | if(!test_omp_for_ordered()) { 56 | num_failed++; 57 | } 58 | } 59 | return num_failed; 60 | } 61 | -------------------------------------------------------------------------------- /libomptarget/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMakeLists.txt file for unit testing OpenMP offloading runtime library. 2 | if(NOT "${OPENMP_TEST_COMPILER_ID}" STREQUAL "Clang" OR 3 | ${OPENMP_TEST_COMPILER_VERSION} VERSION_LESS 6.0.0) 4 | libomptarget_say("Can only test with Clang compiler in version 6.0.0 or later.") 5 | libomptarget_warning_say("The check-libomptarget target will not be available!") 6 | return() 7 | endif() 8 | 9 | if(LIBOMPTARGET_CMAKE_BUILD_TYPE MATCHES debug) 10 | set(LIBOMPTARGET_DEBUG True) 11 | else() 12 | set(LIBOMPTARGET_DEBUG False) 13 | endif() 14 | 15 | add_openmp_testsuite(check-libomptarget "Running libomptarget tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS omptarget omp) 16 | 17 | if(${OPENMP_STANDALONE_BUILD}) 18 | set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/../../runtime/src" CACHE STRING 19 | "Path to folder containing omp.h") 20 | set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/../../runtime/src" CACHE STRING 21 | "Path to folder containing libomp.so") 22 | else() 23 | set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMPTARGET_BINARY_DIR}/../runtime/src") 24 | endif() 25 | 26 | # Configure the lit.site.cfg.in file 27 | set(AUTO_GEN_COMMENT "## Autogenerated by libomptarget configuration.\n# Do not edit!") 28 | configure_file(lit.site.cfg.in lit.site.cfg @ONLY) 29 | -------------------------------------------------------------------------------- /runtime/test/ompt/synchronization/master.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | FileCheck %s 2 | // REQUIRES: ompt 3 | // GCC generates code that does not call the runtime for the master construct 4 | // XFAIL: gcc 5 | 6 | #include "callback.h" 7 | #include 8 | 9 | int main() { 10 | int x = 0; 11 | #pragma omp parallel num_threads(2) 12 | { 13 | #pragma omp master 14 | { 15 | print_fuzzy_address(1); 16 | x++; 17 | } 18 | print_current_address(2); 19 | } 20 | 21 | printf("%" PRIu64 ": x=%d\n", ompt_get_thread_data()->value, x); 22 | 23 | return 0; 24 | } 25 | 26 | // Check if libomp supports the callbacks for this test. 27 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_master' 28 | 29 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 30 | 31 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_master_begin: 32 | // CHECK-SAME: parallel_id=[[PARALLEL_ID:[0-9]+]], task_id=[[TASK_ID:[0-9]+]], 33 | // CHECK-SAME: codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}} 34 | // CHECK: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]] 35 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_master_end: 36 | // CHECK-SAME: parallel_id=[[PARALLEL_ID]], task_id=[[TASK_ID]], 37 | // CHECK-SAME: codeptr_ra=[[RETURN_ADDRESS_END:0x[0-f]+]] 38 | // CHECK: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS_END]] 39 | -------------------------------------------------------------------------------- /runtime/test/worksharing/sections/omp_parallel_sections_private.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_parallel_sections_private() 6 | { 7 | int sum; 8 | int sum0; 9 | int i; 10 | int known_sum; 11 | 12 | sum = 7; 13 | sum0=0; 14 | 15 | #pragma omp parallel sections private(sum0, i) 16 | { 17 | #pragma omp section 18 | { 19 | sum0=0; 20 | for (i=1;i<400;i++) 21 | sum0=sum0+i; 22 | #pragma omp critical 23 | { 24 | sum= sum+sum0; 25 | } 26 | } 27 | #pragma omp section 28 | { 29 | sum0=0; 30 | for(i=400;i<700;i++) 31 | sum0=sum0+i; 32 | #pragma omp critical 33 | { 34 | sum= sum+sum0; 35 | } 36 | } 37 | #pragma omp section 38 | { 39 | sum0=0; 40 | for(i=700;i<1000;i++) 41 | sum0=sum0+i; 42 | #pragma omp critical 43 | { 44 | sum= sum+sum0; 45 | } 46 | } 47 | } 48 | 49 | known_sum=(999*1000)/2+7; 50 | return (known_sum==sum); 51 | } /* end of check_section_private*/ 52 | 53 | int main() 54 | { 55 | int i; 56 | int num_failed=0; 57 | 58 | for(i = 0; i < REPETITIONS; i++) { 59 | if(!test_omp_parallel_sections_private()) { 60 | num_failed++; 61 | } 62 | } 63 | return num_failed; 64 | } 65 | -------------------------------------------------------------------------------- /runtime/cmake/LibompDefinitions.cmake: -------------------------------------------------------------------------------- 1 | # 2 | #//===----------------------------------------------------------------------===// 3 | #// 4 | #// The LLVM Compiler Infrastructure 5 | #// 6 | #// This file is dual licensed under the MIT and the University of Illinois Open 7 | #// Source Licenses. See LICENSE.txt for details. 8 | #// 9 | #//===----------------------------------------------------------------------===// 10 | # 11 | 12 | function(libomp_get_definitions_flags cppflags) 13 | set(cppflags_local) 14 | 15 | if(WIN32) 16 | libomp_append(cppflags_local "-D _CRT_SECURE_NO_WARNINGS") 17 | libomp_append(cppflags_local "-D _CRT_SECURE_NO_DEPRECATE") 18 | libomp_append(cppflags_local "-D _WINDOWS") 19 | libomp_append(cppflags_local "-D _WINNT") 20 | libomp_append(cppflags_local "-D _WIN32_WINNT=0x0501") 21 | libomp_append(cppflags_local "-D _USRDLL") 22 | libomp_append(cppflags_local "-D _ITERATOR_DEBUG_LEVEL=0" IF_TRUE DEBUG_BUILD) 23 | libomp_append(cppflags_local "-D _DEBUG" IF_TRUE DEBUG_BUILD) 24 | else() 25 | libomp_append(cppflags_local "-D _GNU_SOURCE") 26 | libomp_append(cppflags_local "-D _REENTRANT") 27 | endif() 28 | 29 | # CMake doesn't include CPPFLAGS from environment, but we will. 30 | set(${cppflags} ${cppflags_local} ${LIBOMP_CPPFLAGS} $ENV{CPPFLAGS} PARENT_SCOPE) 31 | endfunction() 32 | 33 | -------------------------------------------------------------------------------- /runtime/test/ompt/misc/threads.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s 2 | // REQUIRES: ompt 3 | #include "callback.h" 4 | #include 5 | 6 | int main() { 7 | int x = 0; 8 | #pragma omp parallel num_threads(4) 9 | { 10 | #pragma omp atomic 11 | x++; 12 | } 13 | 14 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 15 | 16 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_thread_begin: 17 | // CHECK-SAME: thread_type=ompt_thread_initial=1, thread_id=[[MASTER_ID]] 18 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_thread_end: 19 | // CHECK-SAME: thread_id=[[MASTER_ID]] 20 | // CHECK: {{^}}[[WORKER_ID1:[0-9]+]]: ompt_event_thread_begin: 21 | // CHECK-SAME: thread_type=ompt_thread_worker=2, thread_id=[[WORKER_ID1]] 22 | // CHECK: {{^}}[[WORKER_ID1]]: ompt_event_thread_end: 23 | // CHECK-SAME: thread_id=[[WORKER_ID1]] 24 | // CHECK: {{^}}[[WORKER_ID2:[0-9]+]]: ompt_event_thread_begin: 25 | // CHECK-SAME: thread_type=ompt_thread_worker=2, thread_id=[[WORKER_ID2]] 26 | // CHECK: {{^}}[[WORKER_ID2]]: ompt_event_thread_end: 27 | // CHECK-SAME: thread_id=[[WORKER_ID2]] 28 | // CHECK: {{^}}[[WORKER_ID3:[0-9]+]]: ompt_event_thread_begin: 29 | // CHECK-SAME: thread_type=ompt_thread_worker=2, thread_id=[[WORKER_ID3]] 30 | // CHECK: {{^}}[[WORKER_ID3]]: ompt_event_thread_end: 31 | // CHECK-SAME: thread_id=[[WORKER_ID3]] 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /runtime/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMakeLists.txt file for unit testing OpenMP host runtime library. 2 | include(CheckFunctionExists) 3 | include(CheckLibraryExists) 4 | 5 | # Some tests use math functions 6 | check_library_exists(m sqrt "" LIBOMP_HAVE_LIBM) 7 | # When using libgcc, -latomic may be needed for atomics 8 | # (but when using compiler-rt, the atomics will be built-in) 9 | # Note: we can not check for __atomic_load because clang treats it 10 | # as special built-in and that breaks CMake checks 11 | check_function_exists(__atomic_load_1 LIBOMP_HAVE_BUILTIN_ATOMIC) 12 | if(NOT LIBOMP_HAVE_BUILTIN_ATOMIC) 13 | check_library_exists(atomic __atomic_load_1 "" LIBOMP_HAVE_LIBATOMIC) 14 | else() 15 | # not needed 16 | set(LIBOMP_HAVE_LIBATOMIC 0) 17 | endif() 18 | 19 | macro(pythonize_bool var) 20 | if (${var}) 21 | set(${var} True) 22 | else() 23 | set(${var} False) 24 | endif() 25 | endmacro() 26 | 27 | pythonize_bool(LIBOMP_USE_HWLOC) 28 | pythonize_bool(LIBOMP_OMPT_SUPPORT) 29 | pythonize_bool(LIBOMP_OMPT_OPTIONAL) 30 | pythonize_bool(LIBOMP_HAVE_LIBM) 31 | pythonize_bool(LIBOMP_HAVE_LIBATOMIC) 32 | 33 | add_openmp_testsuite(check-libomp "Running libomp tests" ${CMAKE_CURRENT_BINARY_DIR} DEPENDS omp) 34 | 35 | # Configure the lit.site.cfg.in file 36 | set(AUTO_GEN_COMMENT "## Autogenerated by libomp configuration.\n# Do not edit!") 37 | configure_file(lit.site.cfg.in lit.site.cfg @ONLY) 38 | -------------------------------------------------------------------------------- /runtime/test/tasking/omp_task_private.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | /* Utility function do spend some time in a loop */ 7 | int test_omp_task_private() 8 | { 9 | int i; 10 | int known_sum; 11 | int sum = 0; 12 | int result = 0; /* counts the wrong sums from tasks */ 13 | 14 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; 15 | 16 | #pragma omp parallel 17 | { 18 | #pragma omp single 19 | { 20 | for (i = 0; i < NUM_TASKS; i++) { 21 | #pragma omp task private(sum) shared(result, known_sum) 22 | { 23 | int j; 24 | //if sum is private, initialize to 0 25 | sum = 0; 26 | for (j = 0; j <= LOOPCOUNT; j++) { 27 | #pragma omp flush 28 | sum += j; 29 | } 30 | /* check if calculated sum was right */ 31 | if (sum != known_sum) { 32 | #pragma omp critical 33 | result++; 34 | } 35 | } /* end of omp task */ 36 | } /* end of for */ 37 | } /* end of single */ 38 | } /* end of parallel*/ 39 | return (result == 0); 40 | } 41 | 42 | int main() 43 | { 44 | int i; 45 | int num_failed=0; 46 | 47 | for(i = 0; i < REPETITIONS; i++) { 48 | if(!test_omp_task_private()) { 49 | num_failed++; 50 | } 51 | } 52 | return num_failed; 53 | } 54 | -------------------------------------------------------------------------------- /runtime/test/worksharing/single/omp_single_private.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int myit = 0; 6 | #pragma omp threadprivate(myit) 7 | int myresult = 0; 8 | #pragma omp threadprivate(myresult) 9 | 10 | int test_omp_single_private() 11 | { 12 | int nr_threads_in_single; 13 | int result; 14 | int nr_iterations; 15 | int i; 16 | 17 | myit = 0; 18 | nr_threads_in_single = 0; 19 | nr_iterations = 0; 20 | result = 0; 21 | 22 | #pragma omp parallel private(i) 23 | { 24 | myresult = 0; 25 | myit = 0; 26 | for (i = 0; i < LOOPCOUNT; i++) { 27 | #pragma omp single private(nr_threads_in_single) nowait 28 | { 29 | nr_threads_in_single = 0; 30 | #pragma omp flush 31 | nr_threads_in_single++; 32 | #pragma omp flush 33 | myit++; 34 | myresult = myresult + nr_threads_in_single; 35 | } 36 | } 37 | #pragma omp critical 38 | { 39 | result += nr_threads_in_single; 40 | nr_iterations += myit; 41 | } 42 | } 43 | return ((result == 0) && (nr_iterations == LOOPCOUNT)); 44 | } /* end of check_single private */ 45 | 46 | int main() 47 | { 48 | int i; 49 | int num_failed=0; 50 | 51 | for(i = 0; i < REPETITIONS; i++) { 52 | if(!test_omp_single_private()) { 53 | num_failed++; 54 | } 55 | } 56 | return num_failed; 57 | } 58 | -------------------------------------------------------------------------------- /runtime/test/api/kmp_set_defaults_lock_bug.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | /* The bug occurs if the lock table is reallocated after 5 | kmp_set_defaults() is called. If the table is reallocated, 6 | then the lock will not point to a valid lock object after the 7 | kmp_set_defaults() call.*/ 8 | omp_lock_t lock; 9 | 10 | int test_kmp_set_defaults_lock_bug() 11 | { 12 | /* checks that omp_get_num_threads is equal to the number of 13 | threads */ 14 | int nthreads_lib; 15 | int nthreads = 0; 16 | 17 | nthreads_lib = -1; 18 | 19 | #pragma omp parallel 20 | { 21 | omp_set_lock(&lock); 22 | nthreads++; 23 | omp_unset_lock(&lock); 24 | #pragma omp single 25 | { 26 | nthreads_lib = omp_get_num_threads (); 27 | } /* end of single */ 28 | } /* end of parallel */ 29 | kmp_set_defaults("OMP_NUM_THREADS"); 30 | #pragma omp parallel 31 | { 32 | omp_set_lock(&lock); 33 | nthreads++; 34 | omp_unset_lock(&lock); 35 | } /* end of parallel */ 36 | 37 | return (nthreads == 2*nthreads_lib); 38 | } 39 | 40 | int main() 41 | { 42 | int i; 43 | int num_failed=0; 44 | omp_init_lock(&lock); 45 | 46 | for(i = 0; i < REPETITIONS; i++) { 47 | if(!test_kmp_set_defaults_lock_bug()) { 48 | num_failed++; 49 | } 50 | } 51 | omp_destroy_lock(&lock); 52 | return num_failed; 53 | } 54 | -------------------------------------------------------------------------------- /runtime/test/ompt/synchronization/ordered.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | FileCheck %s 2 | // REQUIRES: ompt 3 | // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7 4 | #include "callback.h" 5 | #include 6 | 7 | int main() 8 | { 9 | #pragma omp ordered 10 | { 11 | print_current_address(1); 12 | print_ids(0); 13 | } 14 | print_current_address(2); 15 | 16 | 17 | // Check if libomp supports the callbacks for this test. 18 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquire' 19 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquired' 20 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_released' 21 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_nest_lock' 22 | 23 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 24 | 25 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_wait_ordered: wait_id=[[WAIT_ID:[0-9]+]], hint={{[0-9]+}}, impl={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]] 26 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_acquired_ordered: wait_id=[[WAIT_ID]], codeptr_ra=[[RETURN_ADDRESS]] 27 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS]] 28 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_release_ordered: wait_id=[[WAIT_ID]], codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]] 29 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS]] 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /runtime/test/worksharing/single/omp_single_copyprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include "omp_testsuite.h" 3 | 4 | #define DEBUG_TEST 0 5 | 6 | int j; 7 | #pragma omp threadprivate(j) 8 | 9 | int test_omp_single_copyprivate() 10 | { 11 | int result; 12 | int nr_iterations; 13 | 14 | result = 0; 15 | nr_iterations = 0; 16 | #pragma omp parallel num_threads(4) 17 | { 18 | int i; 19 | for (i = 0; i < LOOPCOUNT; i++) 20 | { 21 | #if DEBUG_TEST 22 | int thread; 23 | thread = omp_get_thread_num (); 24 | #endif 25 | #pragma omp single copyprivate(j) 26 | { 27 | nr_iterations++; 28 | j = i; 29 | #if DEBUG_TEST 30 | printf ("thread %d assigns, j = %d, i = %d\n", thread, j, i); 31 | #endif 32 | } 33 | #if DEBUG_TEST 34 | #pragma omp barrier 35 | #endif 36 | #pragma omp critical 37 | { 38 | #if DEBUG_TEST 39 | printf ("thread = %d, j = %d, i = %d\n", thread, j, i); 40 | #endif 41 | result = result + j - i; 42 | } 43 | #pragma omp barrier 44 | } /* end of for */ 45 | } /* end of parallel */ 46 | return ((result == 0) && (nr_iterations == LOOPCOUNT)); 47 | } 48 | 49 | int main() 50 | { 51 | int i; 52 | int num_failed=0; 53 | 54 | for(i = 0; i < REPETITIONS; i++) { 55 | if(!test_omp_single_copyprivate()) { 56 | num_failed++; 57 | } 58 | } 59 | return num_failed; 60 | } 61 | -------------------------------------------------------------------------------- /runtime/test/ompt/synchronization/critical.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | FileCheck %s 2 | // REQUIRES: ompt 3 | // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7 4 | #include "callback.h" 5 | #include 6 | 7 | int main() 8 | { 9 | #pragma omp critical 10 | { 11 | print_current_address(1); 12 | print_ids(0); 13 | } 14 | print_current_address(2); 15 | 16 | 17 | // Check if libomp supports the callbacks for this test. 18 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquire' 19 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquired' 20 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_released' 21 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_nest_lock' 22 | 23 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 24 | 25 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_wait_critical: wait_id=[[WAIT_ID:[0-9]+]], hint={{[0-9]+}}, impl={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]] 26 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_acquired_critical: wait_id=[[WAIT_ID]], codeptr_ra=[[RETURN_ADDRESS]] 27 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS]] 28 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_release_critical: wait_id=[[WAIT_ID]], codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]] 29 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS]] 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /runtime/src/thirdparty/ittnotify/disable_warnings.h: -------------------------------------------------------------------------------- 1 | 2 | //===----------------------------------------------------------------------===// 3 | // 4 | // The LLVM Compiler Infrastructure 5 | // 6 | // This file is dual licensed under the MIT and the University of Illinois Open 7 | // Source Licenses. See LICENSE.txt for details. 8 | // 9 | //===----------------------------------------------------------------------===// 10 | 11 | #include "ittnotify_config.h" 12 | 13 | #if ITT_PLATFORM==ITT_PLATFORM_WIN 14 | 15 | #pragma warning (disable: 593) /* parameter "XXXX" was set but never used */ 16 | #pragma warning (disable: 344) /* typedef name has already been declared (with same type) */ 17 | #pragma warning (disable: 174) /* expression has no effect */ 18 | #pragma warning (disable: 4127) /* conditional expression is constant */ 19 | #pragma warning (disable: 4306) /* conversion from '?' to '?' of greater size */ 20 | 21 | #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */ 22 | 23 | #if defined __INTEL_COMPILER 24 | 25 | #pragma warning (disable: 869) /* parameter "XXXXX" was never referenced */ 26 | #pragma warning (disable: 1418) /* external function definition with no prior declaration */ 27 | #pragma warning (disable: 1419) /* external declaration in primary source file */ 28 | 29 | #endif /* __INTEL_COMPILER */ 30 | -------------------------------------------------------------------------------- /runtime/test/tasking/omp_task.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | #include "omp_my_sleep.h" 6 | 7 | int test_omp_task() 8 | { 9 | int tids[NUM_TASKS]; 10 | int i; 11 | 12 | #pragma omp parallel 13 | { 14 | #pragma omp single 15 | { 16 | for (i = 0; i < NUM_TASKS; i++) { 17 | /* First we have to store the value of the loop index in a new variable 18 | * which will be private for each task because otherwise it will be overwritten 19 | * if the execution of the task takes longer than the time which is needed to 20 | * enter the next step of the loop! 21 | */ 22 | int myi; 23 | myi = i; 24 | #pragma omp task 25 | { 26 | my_sleep (SLEEPTIME); 27 | tids[myi] = omp_get_thread_num(); 28 | } /* end of omp task */ 29 | } /* end of for */ 30 | } /* end of single */ 31 | } /*end of parallel */ 32 | 33 | /* Now we ckeck if more than one thread executed the tasks. */ 34 | for (i = 1; i < NUM_TASKS; i++) { 35 | if (tids[0] != tids[i]) 36 | return 1; 37 | } 38 | return 0; 39 | } /* end of check_parallel_for_private */ 40 | 41 | int main() 42 | { 43 | int i; 44 | int num_failed=0; 45 | 46 | for(i = 0; i < REPETITIONS; i++) { 47 | if(!test_omp_task()) { 48 | num_failed++; 49 | } 50 | } 51 | return num_failed; 52 | } 53 | -------------------------------------------------------------------------------- /runtime/test/ompt/synchronization/taskwait.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s 2 | // REQUIRES: ompt 3 | // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7 4 | #include "callback.h" 5 | #include 6 | 7 | int main() 8 | { 9 | int x = 0; 10 | #pragma omp parallel num_threads(2) 11 | { 12 | #pragma omp master 13 | { 14 | #pragma omp task 15 | { 16 | x++; 17 | } 18 | #pragma omp taskwait 19 | print_current_address(1); 20 | } 21 | } 22 | 23 | // Check if libomp supports the callbacks for this test. 24 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_sync_region' 25 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_sync_region_wait' 26 | 27 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 28 | 29 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_taskwait_begin: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]] 30 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_taskwait_begin: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS]] 31 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_taskwait_end: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS]] 32 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: ompt_event_taskwait_end: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS]] 33 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS]] 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /runtime/test/worksharing/sections/omp_parallel_sections_lastprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_parallel_sections_lastprivate() 6 | { 7 | int sum; 8 | int sum0; 9 | int i; 10 | int i0; 11 | int known_sum; 12 | sum =0; 13 | sum0 = 0; 14 | i0 = -1; 15 | 16 | #pragma omp parallel sections private(i,sum0) lastprivate(i0) 17 | { 18 | #pragma omp section 19 | { 20 | sum0=0; 21 | for (i=1;i<400;i++) { 22 | sum0=sum0+i; 23 | i0=i; 24 | } 25 | #pragma omp critical 26 | { 27 | sum= sum+sum0; 28 | } 29 | } 30 | #pragma omp section 31 | { 32 | sum0=0; 33 | for(i=400;i<700;i++) { 34 | sum0=sum0+i; 35 | i0=i; 36 | } 37 | #pragma omp critical 38 | { 39 | sum= sum+sum0; 40 | } 41 | } 42 | #pragma omp section 43 | { 44 | sum0=0; 45 | for(i=700;i<1000;i++) { 46 | sum0=sum0+i; 47 | i0=i; 48 | } 49 | #pragma omp critical 50 | { 51 | sum= sum+sum0; 52 | } 53 | } 54 | } 55 | 56 | known_sum=(999*1000)/2; 57 | return ((known_sum==sum) && (i0==999) ); 58 | } 59 | 60 | int main() 61 | { 62 | int i; 63 | int num_failed=0; 64 | 65 | for(i = 0; i < REPETITIONS; i++) { 66 | if(!test_omp_parallel_sections_lastprivate()) { 67 | num_failed++; 68 | } 69 | } 70 | return num_failed; 71 | } 72 | -------------------------------------------------------------------------------- /runtime/test/lock/omp_init_lock.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include "omp_testsuite.h" 3 | #include 4 | 5 | // This should be slightly less than KMP_I_LOCK_CHUNK, which is 1024 6 | #define LOCKS_PER_ITER 1000 7 | #define ITERATIONS (REPETITIONS + 1) 8 | 9 | // This tests concurrently using locks on one thread while initializing new 10 | // ones on another thread. This exercises the global lock pool. 11 | int 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 repititions are done. The test is exercising growth of 27 | // 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 | 38 | int main() { 39 | // No use repeating this test, since it's exercising a private global pool 40 | // which is not reset between test iterations. 41 | return test_omp_init_lock(); 42 | } 43 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/single.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s 2 | // REQUIRES: ompt 3 | // GCC generates code that does not call the runtime for the single construct 4 | // XFAIL: gcc 5 | 6 | #include "callback.h" 7 | #include 8 | 9 | int main() 10 | { 11 | int x = 0; 12 | #pragma omp parallel num_threads(2) 13 | { 14 | #pragma omp single 15 | { 16 | printf("%" PRIu64 ": in single\n", ompt_get_thread_data()->value); 17 | x++; 18 | } 19 | } 20 | 21 | printf("x=%d\n", x); 22 | 23 | // Check if libomp supports the callbacks for this test. 24 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_work' 25 | 26 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 27 | 28 | // CHECK-DAG: {{^}}[[THREAD_ID_1:[0-9]+]]: ompt_event_single_in_block_begin: parallel_id=[[PARALLEL_ID:[0-9]+]], parent_task_id=[[TASK_ID:[0-9]+]], codeptr_ra={{0x[0-f]+}}, count=1 29 | // CHECK-DAG: {{^}}[[THREAD_ID_1]]: in single 30 | // CHECK-DAG: {{^}}[[THREAD_ID_1]]: ompt_event_single_in_block_end: parallel_id=[[PARALLEL_ID]], task_id=[[TASK_ID]], codeptr_ra={{0x[0-f]+}}, count=1 31 | 32 | // CHECK-DAG: {{^}}[[THREAD_ID_2:[0-9]+]]: ompt_event_single_others_begin: parallel_id=[[PARALLEL_ID:[0-9]+]], task_id=[[TASK_ID:[0-9]+]], codeptr_ra={{0x[0-f]+}}, count=1 33 | // CHECK-DAG: {{^}}[[THREAD_ID_2]]: ompt_event_single_others_end: parallel_id=[[PARALLEL_ID]], task_id=[[TASK_ID]], codeptr_ra={{0x[0-f]+}}, count=1 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /runtime/test/tasking/omp_taskyield.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | #include "omp_my_sleep.h" 6 | 7 | int test_omp_taskyield() 8 | { 9 | int i; 10 | int count = 0; 11 | int start_tid[NUM_TASKS]; 12 | int current_tid[NUM_TASKS]; 13 | 14 | for (i=0; i< NUM_TASKS; i++) { 15 | start_tid[i]=0; 16 | current_tid[i]=0; 17 | } 18 | 19 | #pragma omp parallel 20 | { 21 | #pragma omp single 22 | { 23 | for (i = 0; i < NUM_TASKS; i++) { 24 | int myi = i; 25 | #pragma omp task untied 26 | { 27 | my_sleep(SLEEPTIME); 28 | start_tid[myi] = omp_get_thread_num(); 29 | #pragma omp taskyield 30 | if((start_tid[myi] %2) ==0){ 31 | my_sleep(SLEEPTIME); 32 | current_tid[myi] = omp_get_thread_num(); 33 | } /*end of if*/ 34 | } /* end of omp task */ 35 | } /* end of for */ 36 | } /* end of single */ 37 | } /* end of parallel */ 38 | for (i=0;i 3 | #include 4 | #include "omp_testsuite.h" 5 | 6 | /* Utility function do spend some time in a loop */ 7 | static void do_some_work() 8 | { 9 | int i; 10 | double sum = 0; 11 | for(i = 0; i < 1000; i++){ 12 | sum += sqrt ((double) i); 13 | } 14 | } 15 | 16 | int sum1; 17 | #pragma omp threadprivate(sum1) 18 | 19 | int test_omp_for_private() 20 | { 21 | int sum = 0; 22 | int sum0; 23 | int known_sum; 24 | 25 | sum0 = 0; /* setting (global) sum0 = 0 */ 26 | 27 | #pragma omp parallel 28 | { 29 | sum1 = 0; /* setting sum1 in each thread to 0 */ 30 | { /* begin of orphaned block */ 31 | int i; 32 | #pragma omp for private(sum0) schedule(static,1) 33 | for (i = 1; i <= LOOPCOUNT; i++) { 34 | sum0 = sum1; 35 | #pragma omp flush 36 | sum0 = sum0 + i; 37 | do_some_work (); 38 | #pragma omp flush 39 | sum1 = sum0; 40 | } 41 | } /* end of orphaned block */ 42 | 43 | #pragma omp critical 44 | { 45 | sum = sum + sum1; 46 | } /*end of critical*/ 47 | } /* end of parallel*/ 48 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; 49 | return (known_sum == sum); 50 | } 51 | 52 | int main() 53 | { 54 | int i; 55 | int num_failed=0; 56 | 57 | for(i = 0; i < REPETITIONS; i++) { 58 | if(!test_omp_for_private()) { 59 | num_failed++; 60 | } 61 | } 62 | return num_failed; 63 | } 64 | -------------------------------------------------------------------------------- /runtime/test/worksharing/sections/omp_section_private.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_section_private() 6 | { 7 | int sum; 8 | int sum0; 9 | int i; 10 | int known_sum; 11 | 12 | sum = 7; 13 | sum0 = 0; 14 | 15 | #pragma omp parallel 16 | { 17 | #pragma omp sections private(sum0,i) 18 | { 19 | #pragma omp section 20 | { 21 | sum0 = 0; 22 | for (i = 1; i < 400; i++) 23 | sum0 = sum0 + i; 24 | #pragma omp critical 25 | { 26 | sum = sum + sum0; 27 | } 28 | } 29 | #pragma omp section 30 | { 31 | sum0 = 0; 32 | for (i = 400; i < 700; i++) 33 | sum0 = sum0 + i; 34 | #pragma omp critical 35 | { 36 | sum = sum + sum0; 37 | } 38 | } 39 | #pragma omp section 40 | { 41 | sum0 = 0; 42 | for (i = 700; i < 1000; i++) 43 | sum0 = sum0 + i; 44 | #pragma omp critical 45 | { 46 | sum = sum + sum0; 47 | } 48 | } 49 | } /*end of sections*/ 50 | } /* end of parallel */ 51 | known_sum = (999 * 1000) / 2 + 7; 52 | return (known_sum == sum); 53 | } /* end of check_section_private*/ 54 | 55 | int main() 56 | { 57 | int i; 58 | int num_failed=0; 59 | 60 | for(i = 0; i < REPETITIONS; i++) { 61 | if(!test_omp_section_private()) { 62 | num_failed++; 63 | } 64 | } 65 | return num_failed; 66 | } 67 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/sections.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s 2 | // REQUIRES: ompt 3 | // Some compilers generate code that does not distinguish between sections and loops 4 | // XFAIL: gcc, clang-3, clang-4, clang-5, icc-16, icc-17 5 | // UNSUPPORTED: icc-18 6 | 7 | #include "callback.h" 8 | #include 9 | 10 | int main() 11 | { 12 | #pragma omp parallel sections num_threads(2) 13 | { 14 | #pragma omp section 15 | { 16 | printf("%lu: section 1\n", ompt_get_thread_data()->value); 17 | } 18 | #pragma omp section 19 | { 20 | printf("%lu: section 2\n", ompt_get_thread_data()->value); 21 | } 22 | } 23 | 24 | // Check if libomp supports the callbacks for this test. 25 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_work' 26 | 27 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 28 | 29 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_sections_begin: parallel_id=[[PARALLEL_ID:[0-9]+]], parent_task_id=[[TASK_ID:[0-9]+]], codeptr_ra=[[SECT_BEGIN:0x[0-f]+]], count=2 30 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_sections_end: parallel_id=[[PARALLEL_ID]], task_id={{[0-9]+}}, codeptr_ra=[[SECT_END:0x[0-f]+]] 31 | 32 | // CHECK: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_sections_begin: parallel_id=[[PARALLEL_ID]], parent_task_id=[[TASK_ID:[0-9]+]], codeptr_ra=[[SECT_BEGIN]], count=2 33 | // CHECK: {{^}}[[THREAD_ID]]: ompt_event_sections_end: parallel_id=[[PARALLEL_ID]], task_id={{[0-9]+}}, codeptr_ra=[[SECT_END]] 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /cmake/DetectTestCompiler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(DetectTestCompiler C CXX) 3 | 4 | include(CheckCCompilerFlag) 5 | include(CheckCXXCompilerFlag) 6 | 7 | function(write_compiler_information lang) 8 | set(information "${CMAKE_${lang}_COMPILER}") 9 | set(information "${information}\\;${CMAKE_${lang}_COMPILER_ID}") 10 | set(information "${information}\\;${CMAKE_${lang}_COMPILER_VERSION}") 11 | set(information "${information}\\;${${lang}_FLAGS}") 12 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${lang}CompilerInformation.txt ${information}) 13 | endfunction(write_compiler_information) 14 | 15 | find_package(OpenMP) 16 | if (NOT OpenMP_Found) 17 | set(OpenMP_C_FLAGS "-fopenmp") 18 | set(OpenMP_CXX_FLAGS "-fopenmp") 19 | endif() 20 | 21 | set(C_FLAGS ${flags} ${OpenMP_C_FLAGS}) 22 | set(CXX_FLAGS ${flags} ${OpenMP_CXX_FLAGS}) 23 | 24 | # TODO: Implement blockaddress in GlobalISel and remove this flag! 25 | if (CMAKE_C_COMPILER_ID STREQUAL "Clang") 26 | check_c_compiler_flag("-fno-experimental-isel" C_HAS_EXPERIMENTAL_ISEL_FLAG) 27 | check_cxx_compiler_flag("-fno-experimental-isel" CXX_HAS_EXPERIMENTAL_ISEL_FLAG) 28 | macro(add_experimental_isel_flag lang) 29 | if (${lang}_HAS_EXPERIMENTAL_ISEL_FLAG) 30 | set(${lang}_FLAGS "-fno-experimental-isel ${${lang}_FLAGS}") 31 | endif() 32 | endmacro(add_experimental_isel_flag) 33 | 34 | add_experimental_isel_flag(C) 35 | add_experimental_isel_flag(CXX) 36 | endif() 37 | 38 | write_compiler_information(C) 39 | write_compiler_information(CXX) 40 | -------------------------------------------------------------------------------- /runtime/test/ompt/misc/threads_nested.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s 2 | // REQUIRES: ompt 3 | #include "callback.h" 4 | #include 5 | 6 | int main() { 7 | 8 | int condition = 0; 9 | int x = 0; 10 | omp_set_nested(1); 11 | #pragma omp parallel num_threads(2) 12 | { 13 | #pragma omp parallel num_threads(2) 14 | { 15 | OMPT_SIGNAL(condition); 16 | OMPT_WAIT(condition, 4); 17 | } 18 | } 19 | 20 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 21 | 22 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_thread_begin: 23 | // CHECK-SAME: thread_type=ompt_thread_initial=1, thread_id=[[MASTER_ID]] 24 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_thread_end: 25 | // CHECK-SAME: thread_id=[[MASTER_ID]] 26 | // CHECK: {{^}}[[WORKER_ID1:[0-9]+]]: ompt_event_thread_begin: 27 | // CHECK-SAME: thread_type=ompt_thread_worker=2, thread_id=[[WORKER_ID1]] 28 | // CHECK: {{^}}[[WORKER_ID1]]: ompt_event_thread_end: 29 | // CHECK-SAME: thread_id=[[WORKER_ID1]] 30 | // CHECK: {{^}}[[WORKER_ID2:[0-9]+]]: ompt_event_thread_begin: 31 | // CHECK-SAME: thread_type=ompt_thread_worker=2, thread_id=[[WORKER_ID2]] 32 | // CHECK: {{^}}[[WORKER_ID2]]: ompt_event_thread_end: 33 | // CHECK-SAME: thread_id=[[WORKER_ID2]] 34 | // CHECK: {{^}}[[WORKER_ID3:[0-9]+]]: ompt_event_thread_begin: 35 | // CHECK-SAME: thread_type=ompt_thread_worker=2, thread_id=[[WORKER_ID3]] 36 | // CHECK: {{^}}[[WORKER_ID3]]: ompt_event_thread_end: 37 | // CHECK-SAME: thread_id=[[WORKER_ID3]] 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /runtime/test/ompt/worksharing/for/base_serialized.h: -------------------------------------------------------------------------------- 1 | #include "callback.h" 2 | #include 3 | 4 | int main() 5 | { 6 | unsigned int i; 7 | 8 | #pragma omp parallel for num_threads(1) schedule(SCHEDULE) 9 | for (i = 0; i < 1; i++) { 10 | } 11 | 12 | // Check if libomp supports the callbacks for this test. 13 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_begin' 14 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_end' 15 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task' 16 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_work' 17 | 18 | 19 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 20 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_parallel_begin: parent_task_id=[[PARENT_TASK_ID:[0-9]+]], parent_task_frame.exit=[[NULL]], parent_task_frame.reenter={{0x[0-f]+}}, parallel_id=[[PARALLEL_ID:[0-9]+]], requested_team_size=1, codeptr_ra=0x{{[0-f]+}}, invoker={{[0-9]+}} 21 | 22 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID:[0-9]+]], task_id=[[IMPLICIT_TASK_ID:[0-9]+]] 23 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_loop_begin: parallel_id=[[PARALLEL_ID]], parent_task_id=[[IMPLICIT_TASK_ID]], codeptr_ra=0x{{[0-f]+}} 24 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_loop_end: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]] 25 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end: parallel_id={{[PARALLEL_ID,0]}}, task_id=[[IMPLICIT_TASK_ID]] 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #==============================================================================# 2 | # This file specifies intentionally untracked files that git should ignore. 3 | # See: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html 4 | # 5 | # This file is intentionally different from the output of `git svn show-ignore`, 6 | # as most of those are useless. 7 | #==============================================================================# 8 | 9 | #==============================================================================# 10 | # File extensions to be ignored anywhere in the tree. 11 | #==============================================================================# 12 | # Temp files created by most text editors. 13 | *~ 14 | # Merge files created by git. 15 | *.orig 16 | # Byte compiled python modules. 17 | *.pyc 18 | # vim swap files 19 | .*.sw? 20 | .sw? 21 | #OS X specific files. 22 | .DS_store 23 | 24 | #==============================================================================# 25 | # Explicit files to ignore (only matches one). 26 | #==============================================================================# 27 | # Various tag programs 28 | tags 29 | /TAGS 30 | /GPATH 31 | /GRTAGS 32 | /GSYMS 33 | /GTAGS 34 | .gitusers 35 | 36 | #==============================================================================# 37 | # Directories to ignore (do not add trailing '/'s, they skip symlinks). 38 | #==============================================================================# 39 | runtime/exports 40 | 41 | # Nested build directory 42 | /build 43 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_parallel_for_ordered.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | static int last_i = 0; 6 | 7 | int i; 8 | #pragma omp threadprivate(i) 9 | 10 | /* Variable ii is used to avoid problems with a threadprivate variable used as a loop 11 | * index. See test omp_threadprivate_for. 12 | */ 13 | static int ii; 14 | #pragma omp threadprivate(ii) 15 | 16 | /*! 17 | Utility function: returns true if the passed argument is larger than 18 | the argument of the last call of this function. 19 | */ 20 | static int check_i_islarger2(int i) 21 | { 22 | int islarger; 23 | islarger = (i > last_i); 24 | last_i = i; 25 | return (islarger); 26 | } 27 | 28 | int test_omp_parallel_for_ordered() 29 | { 30 | int sum; 31 | int is_larger; 32 | int known_sum; 33 | int i; 34 | 35 | sum = 0; 36 | is_larger = 1; 37 | last_i = 0; 38 | #pragma omp parallel for schedule(static,1) private(i) ordered 39 | for (i = 1; i < 100; i++) { 40 | ii = i; 41 | #pragma omp ordered 42 | { 43 | is_larger = check_i_islarger2 (ii) && is_larger; 44 | sum = sum + ii; 45 | } 46 | } 47 | known_sum = (99 * 100) / 2; 48 | fprintf (stderr," known_sum = %d , sum = %d \n", known_sum, sum); 49 | fprintf (stderr," is_larger = %d\n", is_larger); 50 | return (known_sum == sum) && is_larger; 51 | } 52 | 53 | int main() 54 | { 55 | int i; 56 | int num_failed=0; 57 | 58 | for(i = 0; i < REPETITIONS; i++) { 59 | if(!test_omp_parallel_for_ordered()) { 60 | num_failed++; 61 | } 62 | } 63 | return num_failed; 64 | } 65 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/kmp_doacross_check.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | 4 | #define N 1000 5 | 6 | struct dim { 7 | long long lo; // lower 8 | long long up; // upper 9 | long long st; // stride 10 | }; 11 | extern void __kmpc_doacross_init(void*, int, int, struct dim *); 12 | extern void __kmpc_doacross_wait(void*, int, long long*); 13 | extern void __kmpc_doacross_post(void*, int, long long*); 14 | extern void __kmpc_doacross_fini(void*, int); 15 | extern int __kmpc_global_thread_num(void*); 16 | 17 | int main() 18 | { 19 | int i; 20 | int iter[N]; 21 | struct dim dims; 22 | for( i = 0; i < N; ++i ) 23 | iter[i] = 1; 24 | dims.lo = 1; 25 | dims.up = N-1; 26 | dims.st = 1; 27 | #pragma omp parallel num_threads(4) 28 | { 29 | int i, gtid; 30 | long long vec; 31 | gtid = __kmpc_global_thread_num(NULL); 32 | __kmpc_doacross_init(NULL,gtid,1,&dims); // thread starts the loop 33 | #pragma omp for nowait schedule(dynamic) 34 | for( i = 1; i < N; ++i ) 35 | { 36 | // runtime call corresponding to #pragma omp ordered depend(sink:i-1) 37 | vec=i-1; 38 | __kmpc_doacross_wait(NULL,gtid,&vec); 39 | // user's code 40 | iter[i] = iter[i-1] + 1; 41 | // runtime call corresponding to #pragma omp ordered depend(source) 42 | vec=i; 43 | __kmpc_doacross_post(NULL,gtid,&vec); 44 | } 45 | // thread finishes the loop (should be before the loop barrier) 46 | __kmpc_doacross_fini(NULL,gtid); 47 | } 48 | if( iter[N-1] == N ) { 49 | printf("passed\n"); 50 | } else { 51 | printf("failed %d != %d\n", iter[N-1], N); 52 | return 1; 53 | } 54 | return 0; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /runtime/test/misc_bugs/teams-no-par.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | // 3 | // The test checks the teams construct pseudocode executed on host 4 | // 5 | 6 | #include 7 | #include 8 | 9 | #ifndef N_TEAMS 10 | #define N_TEAMS 4 11 | #endif 12 | #ifndef N_THR 13 | #define N_THR 3 14 | #endif 15 | 16 | static int err = 0; 17 | 18 | // Internal library staff to emulate compiler's code generation: 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | typedef struct { 24 | int reserved_1; 25 | int flags; 26 | int reserved_2; 27 | int reserved_3; 28 | char *psource; 29 | } ident_t; 30 | 31 | static ident_t dummy_loc = {0, 2, 0, 0, ";dummyFile;dummyFunc;0;0;;"}; 32 | 33 | int __kmpc_global_thread_num(void*); 34 | void __kmpc_push_num_teams(ident_t const*, int, int, int); 35 | void __kmpc_fork_teams(ident_t const*, int argc, void *microtask, ...); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | // Outlined entry point: 42 | void foo(int *gtid, int *tid, int *nt) 43 | { // start "serial" execution by master threads of each team 44 | if ( nt ) { 45 | printf(" team %d, param %d\n", omp_get_team_num(), *nt); 46 | } else { 47 | printf("ERROR: teams before parallel: gtid, tid: %d %d, bad pointer: %p\n", *gtid, *tid, nt); 48 | err++; 49 | return; 50 | } 51 | } 52 | 53 | int main() 54 | { 55 | int nt = 4; 56 | int th = __kmpc_global_thread_num(NULL); // registers initial thread 57 | __kmpc_push_num_teams(&dummy_loc, th, N_TEAMS, N_THR); 58 | __kmpc_fork_teams(&dummy_loc, 1, &foo, &nt); // pass 1 shared parameter "nt" 59 | if (err) 60 | printf("failed with %d errors\n",err); 61 | else 62 | printf("passed\n"); 63 | return err; 64 | } 65 | -------------------------------------------------------------------------------- /runtime/test/tasking/omp_taskloop_num_tasks.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | // RUN: %libomp-compile && env KMP_TASKLOOP_MIN_TASKS=1 %libomp-run 3 | /* 4 | * Test for taskloop 5 | * Method: caculate how many times the iteration space is dispatched 6 | * and judge if each dispatch has the requested grainsize 7 | * It is possible for two adjacent chunks are executed by the same thread 8 | */ 9 | #include 10 | #include 11 | #include 12 | #include "omp_testsuite.h" 13 | 14 | #define CFDMAX_SIZE 1120 15 | 16 | int test_omp_taskloop_num_tasks() 17 | { 18 | int i; 19 | int *tids; 20 | int *tidsArray; 21 | int count; 22 | int result = 0; 23 | int num_tasks; 24 | 25 | for (num_tasks = 1; num_tasks < 120; ++num_tasks) { 26 | count = 0; 27 | tidsArray = (int *)malloc(sizeof(int) * CFDMAX_SIZE); 28 | tids = tidsArray; 29 | 30 | #pragma omp parallel shared(tids) 31 | { 32 | int i; 33 | #pragma omp master 34 | #pragma omp taskloop num_tasks(num_tasks) 35 | for (i = 0; i < CFDMAX_SIZE; i++) { 36 | tids[i] = omp_get_thread_num(); 37 | } 38 | } 39 | 40 | for (i = 0; i < CFDMAX_SIZE - 1; ++i) { 41 | if (tids[i] != tids[i + 1]) { 42 | count++; 43 | } 44 | } 45 | 46 | if (count > num_tasks) { 47 | fprintf(stderr, "counted too many tasks: (wanted %d, got %d)\n", 48 | num_tasks, count); 49 | result++; 50 | } 51 | } 52 | 53 | return (result==0); 54 | } 55 | 56 | int main() 57 | { 58 | int i; 59 | int num_failed=0; 60 | 61 | for (i = 0; i < REPETITIONS; i++) { 62 | if (!test_omp_taskloop_num_tasks()) { 63 | num_failed++; 64 | } 65 | } 66 | return num_failed; 67 | } 68 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_for_schedule_auto.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include 5 | #include "omp_testsuite.h" 6 | 7 | int sum1; 8 | #pragma omp threadprivate(sum1) 9 | 10 | int test_omp_for_auto() 11 | { 12 | int j; 13 | int sum; 14 | int sum0; 15 | int known_sum; 16 | int threadsnum; 17 | 18 | sum = 0; 19 | sum0 = 12345; 20 | 21 | // array which keeps track of which threads participated in the for loop 22 | // e.g., given 4 threads, [ 0 | 1 | 1 | 0 ] implies 23 | // threads 0 and 3 did not, threads 1 and 2 did 24 | int max_threads = omp_get_max_threads(); 25 | int* active_threads = (int*)malloc(sizeof(int)*max_threads); 26 | for(j = 0; j < max_threads; j++) 27 | active_threads[j] = 0; 28 | 29 | #pragma omp parallel 30 | { 31 | int i; 32 | sum1 = 0; 33 | #pragma omp for firstprivate(sum0) schedule(auto) 34 | for (i = 1; i <= LOOPCOUNT; i++) { 35 | active_threads[omp_get_thread_num()] = 1; 36 | sum0 = sum0 + i; 37 | sum1 = sum0; 38 | } 39 | 40 | #pragma omp critical 41 | { 42 | sum = sum + sum1; 43 | } 44 | } 45 | 46 | // count the threads that participated (sum is stored in threadsnum) 47 | threadsnum=0; 48 | for(j = 0; j < max_threads; j++) { 49 | if(active_threads[j]) 50 | threadsnum++; 51 | } 52 | free(active_threads); 53 | 54 | known_sum = 12345 * threadsnum + (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; 55 | return (known_sum == sum); 56 | } 57 | 58 | int main() 59 | { 60 | int i; 61 | int num_failed=0; 62 | 63 | for(i = 0; i < REPETITIONS; i++) { 64 | if(!test_omp_for_auto()) { 65 | num_failed++; 66 | } 67 | } 68 | return num_failed; 69 | } 70 | -------------------------------------------------------------------------------- /runtime/test/api/kmp_aligned_malloc.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include 5 | #include "omp_testsuite.h" 6 | 7 | int alignments[] = {64, 128, 256, 512, 1024, 2048, 4096}; 8 | 9 | unsigned aligned_by(uint64_t addr) { 10 | uint64_t alignment = 1; 11 | while((addr & (alignment-1)) == 0) { 12 | alignment <<= 1; 13 | } 14 | return (alignment >> 1); 15 | } 16 | 17 | int test_kmp_aligned_malloc() 18 | { 19 | int err = 0; 20 | #pragma omp parallel shared(err) 21 | { 22 | int i; 23 | int* ptr; 24 | uint64_t addr; 25 | int tid = omp_get_thread_num(); 26 | 27 | for(i = 0; i < sizeof(alignments)/sizeof(int); i++) { 28 | int alignment = alignments[i]; 29 | // allocate 64 bytes with 64-byte alignment 30 | // allocate 128 bytes with 128-byte alignment, etc. 31 | ptr = (int*)kmp_aligned_malloc(alignment, alignment); 32 | addr = (uint64_t)ptr; 33 | if(addr & (alignment-1)) { 34 | printf("thread %d: addr = %p (aligned to %u bytes) but expected " 35 | " alignment = %d\n", tid, ptr, aligned_by(addr), alignment); 36 | err = 1; 37 | } 38 | kmp_free(ptr); 39 | } 40 | 41 | ptr = kmp_aligned_malloc(128, 127); 42 | if (ptr != NULL) { 43 | printf("thread %d: kmp_aligned_malloc() didn't return NULL when " 44 | "alignment was not power of 2\n", tid); 45 | err = 1; 46 | } 47 | } /* end of parallel */ 48 | return !err; 49 | } 50 | 51 | int main() 52 | { 53 | int i; 54 | int num_failed=0; 55 | 56 | for(i = 0; i < REPETITIONS; i++) { 57 | if(!test_kmp_aligned_malloc()) { 58 | num_failed++; 59 | } 60 | } 61 | return num_failed; 62 | } 63 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_for_bigbounds.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile -DMY_SCHEDULE=static && %libomp-run 2 | // RUN: %libomp-compile -DMY_SCHEDULE=dynamic && %libomp-run 3 | // RUN: %libomp-compile -DMY_SCHEDULE=guided && %libomp-run 4 | // XFAIL: * 5 | /* 6 | * Test that large bounds are handled properly and calculations of 7 | * loop iterations don't accidently overflow 8 | */ 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "omp_testsuite.h" 14 | 15 | #define INCR 50000000 16 | #define MY_MAX 2000000000 17 | #define MY_MIN -2000000000 18 | #ifndef MY_SCHEDULE 19 | # define MY_SCHEDULE static 20 | #endif 21 | 22 | int a, b, a_known_value, b_known_value; 23 | 24 | int test_omp_for_bigbounds() 25 | { 26 | a = 0; 27 | b = 0; 28 | #pragma omp parallel 29 | { 30 | int i; 31 | #pragma omp for schedule(MY_SCHEDULE) 32 | for (i = INT_MIN; i < MY_MAX; i+=INCR) { 33 | #pragma omp atomic 34 | a++; 35 | } 36 | #pragma omp for schedule(MY_SCHEDULE) 37 | for (i = INT_MAX; i >= MY_MIN; i-=INCR) { 38 | #pragma omp atomic 39 | b++; 40 | } 41 | } 42 | printf("a = %d (should be %d), b = %d (should be %d)\n", a, a_known_value, b, b_known_value); 43 | return (a == a_known_value && b == b_known_value); 44 | } 45 | 46 | int main() 47 | { 48 | int i; 49 | int num_failed=0; 50 | 51 | a_known_value = 0; 52 | for (i = INT_MIN; i < MY_MAX; i+=INCR) { 53 | a_known_value++; 54 | } 55 | 56 | b_known_value = 0; 57 | for (i = INT_MAX; i >= MY_MIN; i-=INCR) { 58 | b_known_value++; 59 | } 60 | 61 | for(i = 0; i < REPETITIONS; i++) { 62 | if(!test_omp_for_bigbounds()) { 63 | num_failed++; 64 | } 65 | } 66 | return num_failed; 67 | } 68 | -------------------------------------------------------------------------------- /runtime/test/worksharing/single/omp_single_nowait.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | /* 6 | * This test will hang if the nowait is not working properly 7 | * 8 | * It relies on a one thread skipping to the last single construct to 9 | * release the threads in the first three single constructs 10 | */ 11 | volatile int release; 12 | volatile int count; 13 | 14 | void wait_for_release_then_increment(int rank) 15 | { 16 | fprintf(stderr, "Thread nr %d enters first section" 17 | " and waits.\n", rank); 18 | while (release == 0); 19 | #pragma omp atomic 20 | count++; 21 | } 22 | 23 | void release_and_increment(int rank) 24 | { 25 | fprintf(stderr, "Thread nr %d sets release to 1\n", rank); 26 | release = 1; 27 | #pragma omp atomic 28 | count++; 29 | } 30 | 31 | int test_omp_single_nowait() 32 | { 33 | release = 0; 34 | count = 0; 35 | 36 | #pragma omp parallel num_threads(4) 37 | { 38 | int rank; 39 | rank = omp_get_thread_num (); 40 | #pragma omp single nowait 41 | { 42 | wait_for_release_then_increment(rank); 43 | } 44 | #pragma omp single nowait 45 | { 46 | wait_for_release_then_increment(rank); 47 | } 48 | #pragma omp single nowait 49 | { 50 | wait_for_release_then_increment(rank); 51 | } 52 | 53 | #pragma omp single 54 | { 55 | release_and_increment(rank); 56 | } 57 | } 58 | // Check to make sure all four singles were executed 59 | return (count==4); 60 | } /* end of check_single_nowait*/ 61 | 62 | int main() 63 | { 64 | int i; 65 | int num_failed=0; 66 | 67 | for(i = 0; i < REPETITIONS; i++) { 68 | if(!test_omp_single_nowait()) { 69 | num_failed++; 70 | } 71 | } 72 | return num_failed; 73 | } 74 | -------------------------------------------------------------------------------- /runtime/test/worksharing/sections/omp_section_lastprivate.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | int test_omp_section_lastprivate() 6 | { 7 | int i0 = -1; 8 | int sum = 0; 9 | int i; 10 | int sum0 = 0; 11 | int known_sum; 12 | 13 | i0 = -1; 14 | sum = 0; 15 | 16 | #pragma omp parallel 17 | { 18 | #pragma omp sections lastprivate(i0) private(i,sum0) 19 | { 20 | #pragma omp section 21 | { 22 | sum0 = 0; 23 | for (i = 1; i < 400; i++) 24 | { 25 | sum0 = sum0 + i; 26 | i0 = i; 27 | } 28 | #pragma omp critical 29 | { 30 | sum = sum + sum0; 31 | } /*end of critical*/ 32 | } /* end of section */ 33 | #pragma omp section 34 | { 35 | sum0 = 0; 36 | for(i = 400; i < 700; i++) 37 | { 38 | sum0 = sum0 + i; 39 | i0 = i; 40 | } 41 | #pragma omp critical 42 | { 43 | sum = sum + sum0; 44 | } /*end of critical*/ 45 | } 46 | #pragma omp section 47 | { 48 | sum0 = 0; 49 | for(i = 700; i < 1000; i++) 50 | { 51 | sum0 = sum0 + i; 52 | i0 = i; 53 | } 54 | #pragma omp critical 55 | { 56 | sum = sum + sum0; 57 | } /*end of critical*/ 58 | } /* end of section */ 59 | } /* end of sections*/ 60 | } /* end of parallel*/ 61 | known_sum = (999 * 1000) / 2; 62 | return ((known_sum == sum) && (i0 == 999) ); 63 | } 64 | 65 | int main() 66 | { 67 | int i; 68 | int num_failed=0; 69 | 70 | for(i = 0; i < REPETITIONS; i++) { 71 | if(!test_omp_section_lastprivate()) { 72 | num_failed++; 73 | } 74 | } 75 | return num_failed; 76 | } 77 | -------------------------------------------------------------------------------- /runtime/test/misc_bugs/cancellation_for_sections.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile && env OMP_CANCELLATION=true %libomp-run 2 | // XFAIL: gcc 3 | // Clang had a bug until version 4.0.1 which resulted in a hang. 4 | // UNSUPPORTED: clang-3, clang-4.0.0 5 | 6 | // Regression test for a bug in cancellation to cover effect of `#pragma omp cancel` 7 | // in a loop construct, on sections construct. 8 | // Pass condition: Cancellation status from `for` does not persist 9 | // to `sections`. 10 | 11 | #include 12 | #include 13 | 14 | int result[2] = {0, 0}; 15 | 16 | void cq416850_for_sections() { 17 | 18 | unsigned i; 19 | // 1) loop 20 | #pragma omp for 21 | for (i = 0; i < 1; i++) { 22 | result[0] = 1; 23 | #pragma omp cancel for 24 | result[0] = 2; 25 | } 26 | 27 | // printf("thread %d: result[0] = %d, result[1] = %d \n", omp_get_thread_num(), result[0], result[1]); 28 | 29 | 30 | // 2) sections 31 | #pragma omp sections 32 | { 33 | #pragma omp section 34 | { 35 | result[1] = 1; 36 | #pragma omp cancellation point sections 37 | result[1] = 2; 38 | } 39 | } 40 | } 41 | 42 | int main(void) { 43 | if(!omp_get_cancellation()) { 44 | printf("Cancellation not enabled!\n"); 45 | return 2; 46 | } 47 | 48 | #pragma omp parallel num_threads(4) 49 | { 50 | cq416850_for_sections(); 51 | } 52 | 53 | if (result[0] != 1 || result[1] != 2) { 54 | printf("Incorrect values. " 55 | "result[0] = %d (expected 1), " 56 | "result[1] = %d (expected 2).\n", 57 | result[0], result[1]); 58 | printf("FAILED\n"); 59 | return 1; 60 | } 61 | 62 | printf("PASSED\n"); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /libomptarget/test/env/omp_target_debug.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomptarget-compile-aarch64-unknown-linux-gnu && env LIBOMPTARGET_DEBUG=1 %libomptarget-run-aarch64-unknown-linux-gnu 2>&1 | %fcheck-aarch64-unknown-linux-gnu -allow-empty -check-prefix=DEBUG 2 | // RUN: %libomptarget-compile-aarch64-unknown-linux-gnu && env LIBOMPTARGET_DEBUG=0 %libomptarget-run-aarch64-unknown-linux-gnu 2>&1 | %fcheck-aarch64-unknown-linux-gnu -allow-empty -check-prefix=NDEBUG 3 | // RUN: %libomptarget-compile-powerpc64-ibm-linux-gnu && env LIBOMPTARGET_DEBUG=1 %libomptarget-run-powerpc64-ibm-linux-gnu 2>&1 | %fcheck-powerpc64-ibm-linux-gnu -allow-empty -check-prefix=DEBUG 4 | // RUN: %libomptarget-compile-powerpc64-ibm-linux-gnu && env LIBOMPTARGET_DEBUG=0 %libomptarget-run-powerpc64-ibm-linux-gnu 2>&1 | %fcheck-powerpc64-ibm-linux-gnu -allow-empty -check-prefix=NDEBUG 5 | // RUN: %libomptarget-compile-powerpc64le-ibm-linux-gnu && env LIBOMPTARGET_DEBUG=1 %libomptarget-run-powerpc64le-ibm-linux-gnu 2>&1 | %fcheck-powerpc64le-ibm-linux-gnu -allow-empty -check-prefix=DEBUG 6 | // RUN: %libomptarget-compile-powerpc64le-ibm-linux-gnu && env LIBOMPTARGET_DEBUG=0 %libomptarget-run-powerpc64le-ibm-linux-gnu 2>&1 | %fcheck-powerpc64le-ibm-linux-gnu -allow-empty -check-prefix=NDEBUG 7 | // RUN: %libomptarget-compile-x86_64-pc-linux-gnu && env LIBOMPTARGET_DEBUG=1 %libomptarget-run-x86_64-pc-linux-gnu 2>&1 | %fcheck-x86_64-pc-linux-gnu -allow-empty -check-prefix=DEBUG 8 | // RUN: %libomptarget-compile-x86_64-pc-linux-gnu && env LIBOMPTARGET_DEBUG=0 %libomptarget-run-x86_64-pc-linux-gnu 2>&1 | %fcheck-x86_64-pc-linux-gnu -allow-empty -check-prefix=NDEBUG 9 | // REQUIRES: libomptarget-debug 10 | 11 | int main(void) { 12 | #pragma omp target 13 | {} 14 | return 0; 15 | } 16 | 17 | // DEBUG: Libomptarget 18 | // NDEBUG-NOT: Libomptarget 19 | // NDEBUG-NOT: Target 20 | 21 | -------------------------------------------------------------------------------- /CREDITS.txt: -------------------------------------------------------------------------------- 1 | This file is a partial list of people who have contributed to the LLVM/openmp 2 | project. If you have contributed a patch or made some other contribution to 3 | LLVM/openmp, please submit a patch to this file to add yourself, and it will be 4 | done! 5 | 6 | The list is sorted by surname and formatted to allow easy grepping and 7 | beautification by scripts. The fields are: name (N), email (E), web-address 8 | (W), PGP key ID and fingerprint (P), description (D), and snail-mail address 9 | (S). 10 | 11 | N: Adam Azarchs 12 | W: 10xgenomics.com 13 | D: Bug fix for lock code 14 | 15 | N: Carlo Bertolli 16 | W: http://ibm.com 17 | D: IBM contributor to PowerPC support in CMake files and elsewhere. 18 | 19 | N: Diego Caballero 20 | E: diego.l.caballero@gmail.com 21 | D: Fork performance improvements 22 | 23 | N: Sunita Chandrasekaran 24 | D: Contributor to testsuite from OpenUH 25 | 26 | N: Barbara Chapman 27 | D: Contributor to testsuite from OpenUH 28 | 29 | N: University of Houston 30 | W: http://web.cs.uh.edu/~openuh/download/ 31 | D: OpenUH test suite 32 | 33 | N: Intel Corporation OpenMP runtime team 34 | W: http://openmprtl.org 35 | D: Created the runtime. 36 | 37 | N: John Mellor-Crummey and other members of the OpenMP Tools Working Group 38 | E: johnmc@rice.edu 39 | D: OpenMP Tools Interface (OMPT) 40 | 41 | N: Matthias Muller 42 | D: Contributor to testsuite from OpenUH 43 | 44 | N: Tal Nevo 45 | E: tal@scalemp.com 46 | D: ScaleMP contributor to improve runtime performance there. 47 | W: http://scalemp.com 48 | 49 | N: Pavel Neytchev 50 | D: Contributor to testsuite from OpenUH 51 | 52 | N: Steven Noonan 53 | E: steven@uplinklabs.net 54 | D: Patches for the ARM architecture and removal of several inconsistencies. 55 | 56 | N: Alp Toker 57 | E: alp@nuanti.com 58 | D: Making build work for FreeBSD. 59 | 60 | N: Cheng Wang 61 | D: Contributor to testsuite from OpenUH 62 | -------------------------------------------------------------------------------- /libomptarget/deviceRTLs/nvptx/src/state-queue.h: -------------------------------------------------------------------------------- 1 | //===--------- statequeue.h - NVPTX OpenMP GPU State Queue ------- CUDA -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.txt for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file contains a queue to hand out OpenMP state objects to teams of 11 | // one or more kernels. 12 | // 13 | // Reference: 14 | // Thomas R.W. Scogland and Wu-chun Feng. 2015. 15 | // Design and Evaluation of Scalable Concurrent Queues for Many-Core 16 | // Architectures. International Conference on Performance Engineering. 17 | // 18 | //===----------------------------------------------------------------------===// 19 | 20 | #ifndef __STATE_QUEUE_H 21 | #define __STATE_QUEUE_H 22 | 23 | #include 24 | 25 | #include "option.h" // choices we have 26 | 27 | template class omptarget_nvptx_Queue { 28 | private: 29 | ElementType elements[SIZE]; 30 | volatile ElementType *elementQueue[SIZE]; 31 | volatile uint32_t head; 32 | volatile uint32_t ids[SIZE]; 33 | volatile uint32_t tail; 34 | 35 | static const uint32_t MAX_ID = (1u << 31) / SIZE / 2; 36 | INLINE uint32_t ENQUEUE_TICKET(); 37 | INLINE uint32_t DEQUEUE_TICKET(); 38 | INLINE uint32_t ID(uint32_t ticket); 39 | INLINE bool IsServing(uint32_t slot, uint32_t id); 40 | INLINE void PushElement(uint32_t slot, ElementType *element); 41 | INLINE ElementType *PopElement(uint32_t slot); 42 | INLINE void DoneServing(uint32_t slot, uint32_t id); 43 | 44 | public: 45 | INLINE omptarget_nvptx_Queue(){}; 46 | INLINE void Enqueue(ElementType *element); 47 | INLINE ElementType *Dequeue(); 48 | }; 49 | 50 | #include "state-queuei.h" 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /runtime/src/kmp_stub.h: -------------------------------------------------------------------------------- 1 | /* 2 | * kmp_stub.h 3 | */ 4 | 5 | //===----------------------------------------------------------------------===// 6 | // 7 | // The LLVM Compiler Infrastructure 8 | // 9 | // This file is dual licensed under the MIT and the University of Illinois Open 10 | // Source Licenses. See LICENSE.txt for details. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef KMP_STUB_H 15 | #define KMP_STUB_H 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif // __cplusplus 20 | 21 | void __kmps_set_blocktime(int arg); 22 | int __kmps_get_blocktime(void); 23 | void __kmps_set_dynamic(int arg); 24 | int __kmps_get_dynamic(void); 25 | void __kmps_set_library(int arg); 26 | int __kmps_get_library(void); 27 | void __kmps_set_nested(int arg); 28 | int __kmps_get_nested(void); 29 | void __kmps_set_stacksize(int arg); 30 | int __kmps_get_stacksize(); 31 | 32 | #ifndef KMP_SCHED_TYPE_DEFINED 33 | #define KMP_SCHED_TYPE_DEFINED 34 | typedef enum kmp_sched { 35 | kmp_sched_static = 1, // mapped to kmp_sch_static_chunked (33) 36 | kmp_sched_dynamic = 2, // mapped to kmp_sch_dynamic_chunked (35) 37 | kmp_sched_guided = 3, // mapped to kmp_sch_guided_chunked (36) 38 | kmp_sched_auto = 4, // mapped to kmp_sch_auto (38) 39 | kmp_sched_default = kmp_sched_static // default scheduling 40 | } kmp_sched_t; 41 | #endif 42 | void __kmps_set_schedule(kmp_sched_t kind, int modifier); 43 | void __kmps_get_schedule(kmp_sched_t *kind, int *modifier); 44 | 45 | #if OMP_40_ENABLED 46 | void __kmps_set_proc_bind(kmp_proc_bind_t arg); 47 | kmp_proc_bind_t __kmps_get_proc_bind(void); 48 | #endif /* OMP_40_ENABLED */ 49 | 50 | double __kmps_get_wtime(); 51 | double __kmps_get_wtick(); 52 | 53 | #ifdef __cplusplus 54 | } // extern "C" 55 | #endif // __cplusplus 56 | 57 | #endif // KMP_STUB_H 58 | 59 | // end of file // 60 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_for_nowait.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | /* 6 | * This test will hang if the nowait is not working properly. 7 | * 8 | * It relies on a thread skipping to the second for construct to 9 | * release the threads in the first for construct. 10 | * 11 | * Also, we use static scheduling to guarantee that one 12 | * thread will make it to the second for construct. 13 | */ 14 | volatile int release; 15 | volatile int count; 16 | 17 | void wait_for_release_then_increment(int rank) 18 | { 19 | fprintf(stderr, "Thread nr %d enters first for construct" 20 | " and waits.\n", rank); 21 | while (release == 0); 22 | #pragma omp atomic 23 | count++; 24 | } 25 | 26 | void release_and_increment(int rank) 27 | { 28 | fprintf(stderr, "Thread nr %d sets release to 1\n", rank); 29 | release = 1; 30 | #pragma omp atomic 31 | count++; 32 | } 33 | 34 | int test_omp_for_nowait() 35 | { 36 | release = 0; 37 | count = 0; 38 | 39 | #pragma omp parallel num_threads(4) 40 | { 41 | int rank; 42 | int i; 43 | 44 | rank = omp_get_thread_num(); 45 | 46 | #pragma omp for schedule(static) nowait 47 | for (i = 0; i < 4; i++) { 48 | if (i < 3) 49 | wait_for_release_then_increment(rank); 50 | else { 51 | fprintf(stderr, "Thread nr %d enters first for and goes " 52 | "immediately to the next for construct to release.\n", rank); 53 | #pragma omp atomic 54 | count++; 55 | } 56 | } 57 | 58 | #pragma omp for schedule(static) 59 | for (i = 0; i < 4; i++) { 60 | release_and_increment(rank); 61 | } 62 | } 63 | return (count==8); 64 | } 65 | 66 | int main() 67 | { 68 | int i; 69 | int num_failed=0; 70 | 71 | for(i = 0; i < REPETITIONS; i++) { 72 | if(!test_omp_for_nowait()) { 73 | num_failed++; 74 | } 75 | } 76 | return num_failed; 77 | } 78 | -------------------------------------------------------------------------------- /runtime/test/tasking/omp_task_final.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | #include "omp_my_sleep.h" 6 | 7 | int 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 parallel 14 | { 15 | #pragma omp single 16 | { 17 | for (i = 0; i < NUM_TASKS; i++) { 18 | /* First we have to store the value of the loop index in a new variable 19 | * which will be private for each task because otherwise it will be overwritten 20 | * if the execution of the task takes longer than the time which is needed to 21 | * 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 task 33 | { 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 | 53 | int 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 | -------------------------------------------------------------------------------- /runtime/test/ompt/synchronization/taskgroup.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s 2 | // REQUIRES: ompt 3 | // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7 4 | 5 | #include "callback.h" 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | int condition=0; 12 | int x=0; 13 | #pragma omp parallel num_threads(2) 14 | { 15 | #pragma omp master 16 | { 17 | #pragma omp taskgroup 18 | { 19 | print_current_address(1); 20 | #pragma omp task 21 | { 22 | #pragma omp atomic 23 | x++; 24 | } 25 | } 26 | print_current_address(2); 27 | } 28 | } 29 | 30 | 31 | // Check if libomp supports the callbacks for this test. 32 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_master' 33 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create' 34 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_schedule' 35 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_cancel' 36 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_thread_begin' 37 | 38 | 39 | // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]] 40 | 41 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_taskgroup_begin: parallel_id=[[PARALLEL_ID:[0-9]+]], task_id=[[TASK_ID:[0-9]+]], codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]] 42 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS]] 43 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_taskgroup_begin: parallel_id=[[PARALLEL_ID]], task_id=[[TASK_ID]], codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]] 44 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_taskgroup_end: parallel_id=[[PARALLEL_ID]], task_id=[[TASK_ID]], codeptr_ra=[[RETURN_ADDRESS]] 45 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_taskgroup_end: parallel_id=[[PARALLEL_ID]], task_id=[[TASK_ID]], codeptr_ra=[[RETURN_ADDRESS]] 46 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: current_address={{.*}}[[RETURN_ADDRESS]] 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /libomptarget/deviceRTLs/nvptx/src/counter_group.h: -------------------------------------------------------------------------------- 1 | //===------ counter_group.h - NVPTX OpenMP loop scheduling ------- CUDA -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.txt for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // Interface to implement OpenMP loop scheduling 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef _OMPTARGET_NVPTX_COUNTER_GROUP_H_ 15 | #define _OMPTARGET_NVPTX_COUNTER_GROUP_H_ 16 | 17 | #include "option.h" 18 | 19 | // counter group type for synchronizations 20 | class omptarget_nvptx_CounterGroup { 21 | public: 22 | // getters and setters 23 | INLINE Counter &Event() { return v_event; } 24 | INLINE volatile Counter &Start() { return v_start; } 25 | INLINE Counter &Init() { return v_init; } 26 | 27 | // Synchronization Interface 28 | 29 | INLINE void Clear(); // first time start=event 30 | INLINE void Reset(); // init = first 31 | INLINE void Init(Counter &priv); // priv = init 32 | INLINE Counter Next(); // just counts number of events 33 | 34 | // set priv to n, to be used in later waitOrRelease 35 | INLINE void Complete(Counter &priv, Counter n); 36 | 37 | // check priv and decide if we have to wait or can free the other warps 38 | INLINE void Release(Counter priv, Counter current_event_value); 39 | INLINE void WaitOrRelease(Counter priv, Counter current_event_value); 40 | 41 | private: 42 | Counter v_event; // counter of events (atomic) 43 | 44 | // volatile is needed to force loads to read from global 45 | // memory or L2 cache and see the write by the last master 46 | volatile Counter v_start; // signal when events registered are finished 47 | 48 | Counter v_init; // used to initialize local thread variables 49 | }; 50 | 51 | #endif /* SRC_COUNTER_GROUP_H_ */ 52 | -------------------------------------------------------------------------------- /runtime/test/ompt/synchronization/barrier/parallel_region.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | %sort-threads | FileCheck %s 2 | // REQUIRES: ompt 3 | #include "callback.h" 4 | #include 5 | 6 | int main() 7 | { 8 | int x = 0; 9 | 10 | //implicit barrier at end of a parallel region 11 | #pragma omp parallel num_threads(2) 12 | { 13 | #pragma omp atomic 14 | x++; 15 | } 16 | print_fuzzy_address(); 17 | 18 | 19 | // Check if libomp supports the callbacks for this test. 20 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_sync_region' 21 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_sync_region_wait' 22 | 23 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 24 | 25 | // master thread implicit barrier at parallel end 26 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_barrier_begin: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}} 27 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_barrier_begin: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS]]{{[0-f][0-f]}} 28 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_barrier_end: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS]]{{[0-f][0-f]}} 29 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_barrier_end: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS]]{{[0-f][0-f]}} 30 | // CHECK: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]] 31 | 32 | 33 | // worker thread implicit barrier at parallel end 34 | // CHECK: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_barrier_begin: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[NULL]] 35 | // CHECK: {{^}}[[THREAD_ID]]: ompt_event_wait_barrier_begin: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[NULL]] 36 | // CHECK: {{^}}[[THREAD_ID]]: ompt_event_wait_barrier_end: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[NULL]] 37 | // CHECK: {{^}}[[THREAD_ID]]: ompt_event_barrier_end: parallel_id={{[0-9]+}}, task_id={{[0-9]+}}, codeptr_ra=[[NULL]] 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /libomptarget/src/private.h: -------------------------------------------------------------------------------- 1 | //===---------- private.h - Target independent OpenMP target RTL ----------===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.txt for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // Private function declarations and helper macros for debugging output. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef _OMPTARGET_PRIVATE_H 15 | #define _OMPTARGET_PRIVATE_H 16 | 17 | #include 18 | 19 | #include 20 | 21 | extern int target_data_begin(DeviceTy &Device, int32_t arg_num, 22 | void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types); 23 | 24 | extern int target_data_end(DeviceTy &Device, int32_t arg_num, void **args_base, 25 | void **args, int64_t *arg_sizes, int64_t *arg_types); 26 | 27 | extern void target_data_update(DeviceTy &Device, int32_t arg_num, 28 | void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types); 29 | 30 | extern int target(int64_t device_id, void *host_ptr, int32_t arg_num, 31 | void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types, 32 | int32_t team_num, int32_t thread_limit, int IsTeamConstruct); 33 | 34 | extern int CheckDeviceAndCtors(int64_t device_id); 35 | 36 | // Implemented in libomp, they are called from within __tgt_* functions. 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | int omp_get_default_device(void) __attribute__((weak)); 41 | int32_t __kmpc_omp_taskwait(void *loc_ref, int32_t gtid) __attribute__((weak)); 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #ifdef OMPTARGET_DEBUG 47 | extern int DebugLevel; 48 | 49 | #define DP(...) \ 50 | do { \ 51 | if (DebugLevel > 0) { \ 52 | DEBUGP("Libomptarget", __VA_ARGS__); \ 53 | } \ 54 | } while (false) 55 | #else // OMPTARGET_DEBUG 56 | #define DP(...) {} 57 | #endif // OMPTARGET_DEBUG 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /runtime/test/misc_bugs/teams-reduction.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | // 3 | // The test checks the teams construct with reduction executed on the host. 4 | // 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #ifndef N_TEAMS 12 | #define N_TEAMS 4 13 | #endif 14 | #ifndef N_THR 15 | #define N_THR 3 16 | #endif 17 | 18 | // Internal library stuff to emulate compiler's code generation: 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | typedef struct { 24 | int32_t reserved_1; 25 | int32_t flags; 26 | int32_t reserved_2; 27 | int32_t reserved_3; 28 | char const *psource; 29 | } ident_t; 30 | 31 | static ident_t dummy_loc = {0, 2, 0, 0, ";dummyFile;dummyFunc;0;0;;"}; 32 | 33 | typedef union { 34 | // The global will be used as pointer, so we need to make sure that the 35 | // compiler correctly aligns the global... 36 | void *ptr; 37 | int32_t data[8]; 38 | } kmp_critical_name; 39 | kmp_critical_name crit; 40 | 41 | int32_t __kmpc_global_thread_num(ident_t *); 42 | void __kmpc_push_num_teams(ident_t *, int32_t global_tid, int32_t num_teams, 43 | int32_t num_threads); 44 | void __kmpc_fork_teams(ident_t *, int32_t argc, void *microtask, ...); 45 | int32_t __kmpc_reduce(ident_t *, int32_t global_tid, int32_t num_vars, 46 | size_t reduce_size, void *reduce_data, void *reduce_func, 47 | kmp_critical_name *lck); 48 | void __kmpc_end_reduce(ident_t *, int32_t global_tid, kmp_critical_name *lck); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | // Outlined entry point: 55 | void outlined(int32_t *gtid, int32_t *tid) { 56 | int32_t ret = __kmpc_reduce(&dummy_loc, *gtid, 0, 0, NULL, NULL, &crit); 57 | __kmpc_end_reduce(&dummy_loc, *gtid, &crit); 58 | } 59 | 60 | int main() { 61 | int32_t th = __kmpc_global_thread_num(NULL); // registers initial thread 62 | __kmpc_push_num_teams(&dummy_loc, th, N_TEAMS, N_THR); 63 | __kmpc_fork_teams(&dummy_loc, 0, &outlined); 64 | 65 | // Test did not hang -> passed! 66 | printf("passed\n"); 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /runtime/src/kmp_safe_c_api.h: -------------------------------------------------------------------------------- 1 | 2 | //===----------------------------------------------------------------------===// 3 | // 4 | // The LLVM Compiler Infrastructure 5 | // 6 | // This file is dual licensed under the MIT and the University of Illinois Open 7 | // Source Licenses. See LICENSE.txt for details. 8 | // 9 | //===----------------------------------------------------------------------===// 10 | 11 | #ifndef KMP_SAFE_C_API_H 12 | #define KMP_SAFE_C_API_H 13 | 14 | // Replacement for banned C API 15 | 16 | // Not every unsafe call listed here is handled now, but keeping everything 17 | // in one place should be handy for future maintenance. 18 | #if KMP_OS_WINDOWS 19 | 20 | #define RSIZE_MAX_STR (4UL << 10) // 4KB 21 | 22 | // _malloca was suggested, but it is not a drop-in replacement for _alloca 23 | #define KMP_ALLOCA _alloca 24 | 25 | #define KMP_MEMCPY_S memcpy_s 26 | #define KMP_SNPRINTF sprintf_s 27 | #define KMP_SSCANF sscanf_s 28 | #define KMP_STRCPY_S strcpy_s 29 | #define KMP_STRNCPY_S strncpy_s 30 | 31 | // Use this only when buffer size is unknown 32 | #define KMP_MEMCPY(dst, src, cnt) memcpy_s(dst, cnt, src, cnt) 33 | 34 | #define KMP_STRLEN(str) strnlen_s(str, RSIZE_MAX_STR) 35 | 36 | // Use this only when buffer size is unknown 37 | #define KMP_STRNCPY(dst, src, cnt) strncpy_s(dst, cnt, src, cnt) 38 | 39 | // _TRUNCATE insures buffer size > max string to print. 40 | #define KMP_VSNPRINTF(dst, cnt, fmt, arg) \ 41 | vsnprintf_s(dst, cnt, _TRUNCATE, fmt, arg) 42 | 43 | #else // KMP_OS_WINDOWS 44 | 45 | // For now, these macros use the existing API. 46 | 47 | #define KMP_ALLOCA alloca 48 | #define KMP_MEMCPY_S(dst, bsz, src, cnt) memcpy(dst, src, cnt) 49 | #define KMP_SNPRINTF snprintf 50 | #define KMP_SSCANF sscanf 51 | #define KMP_STRCPY_S(dst, bsz, src) strcpy(dst, src) 52 | #define KMP_STRNCPY_S(dst, bsz, src, cnt) strncpy(dst, src, cnt) 53 | #define KMP_VSNPRINTF vsnprintf 54 | #define KMP_STRNCPY strncpy 55 | #define KMP_STRLEN strlen 56 | #define KMP_MEMCPY memcpy 57 | 58 | #endif // KMP_OS_WINDOWS 59 | 60 | #endif // KMP_SAFE_C_API_H 61 | -------------------------------------------------------------------------------- /runtime/src/kmp_wrapper_getpid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * kmp_wrapper_getpid.h -- getpid() declaration. 3 | */ 4 | 5 | //===----------------------------------------------------------------------===// 6 | // 7 | // The LLVM Compiler Infrastructure 8 | // 9 | // This file is dual licensed under the MIT and the University of Illinois Open 10 | // Source Licenses. See LICENSE.txt for details. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef KMP_WRAPPER_GETPID_H 15 | #define KMP_WRAPPER_GETPID_H 16 | 17 | #if KMP_OS_UNIX 18 | 19 | // On Unix-like systems (Linux* OS and OS X*) getpid() is declared in standard 20 | // headers. 21 | #include 22 | #include 23 | #include 24 | #if KMP_OS_DARWIN 25 | // OS X 26 | #define __kmp_gettid() syscall(SYS_thread_selfid) 27 | #elif defined(SYS_gettid) 28 | // Hopefully other Unix systems define SYS_gettid syscall for getting os thread 29 | // id 30 | #define __kmp_gettid() syscall(SYS_gettid) 31 | #else 32 | #warning No gettid found, use getpid instead 33 | #define __kmp_gettid() getpid() 34 | #endif 35 | 36 | #elif KMP_OS_WINDOWS 37 | 38 | // On Windows* OS _getpid() returns int (not pid_t) and is declared in 39 | // "process.h". 40 | #include 41 | // Let us simulate Unix. 42 | typedef int pid_t; 43 | #define getpid _getpid 44 | #define __kmp_gettid() GetCurrentThreadId() 45 | 46 | #else 47 | 48 | #error Unknown or unsupported OS. 49 | 50 | #endif 51 | 52 | /* TODO: All the libomp source code uses pid_t type for storing the result of 53 | getpid(), it is good. But often it printed as "%d", that is not good, because 54 | it ignores pid_t definition (may pid_t be longer that int?). It seems all pid 55 | prints should be rewritten as: 56 | 57 | printf( "%" KMP_UINT64_SPEC, (kmp_uint64) pid ); 58 | 59 | or (at least) as 60 | 61 | printf( "%" KMP_UINT32_SPEC, (kmp_uint32) pid ); 62 | 63 | (kmp_uint32, kmp_uint64, KMP_UINT64_SPEC, and KMP_UNIT32_SPEC are defined in 64 | "kmp_os.h".) */ 65 | 66 | #endif // KMP_WRAPPER_GETPID_H 67 | 68 | // end of file // 69 | -------------------------------------------------------------------------------- /runtime/test/ompt/cancel/cancel_parallel.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile && env OMP_CANCELLATION=true %libomp-run | %sort-threads | FileCheck %s 2 | // REQUIRES: ompt 3 | // Current GOMP interface implementation does not support cancellation 4 | // XFAIL: gcc 5 | 6 | #include "callback.h" 7 | #include "omp.h" 8 | 9 | int main() { 10 | #pragma omp parallel num_threads(2) 11 | { 12 | if (omp_get_thread_num() == 0) { 13 | print_fuzzy_address_blocks(get_ompt_label_address(1)); 14 | #pragma omp cancel parallel 15 | define_ompt_label(1); 16 | // We cannot print at this location because the parallel region is cancelled! 17 | } else { 18 | delay(100); 19 | print_fuzzy_address_blocks(get_ompt_label_address(2)); 20 | #pragma omp cancellation point parallel 21 | define_ompt_label(2); 22 | // We cannot print at this location because the parallel region is cancelled! 23 | } 24 | } 25 | 26 | // Check if libomp supports the callbacks for this test. 27 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create' 28 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_cancel' 29 | 30 | // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]] 31 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_task_create: parent_task_id=[[PARENT_TASK_ID:[0-9]+]], parent_task_frame.exit=[[NULL]], parent_task_frame.reenter=[[NULL]], new_task_id=[[TASK_ID:[0-9]+]], codeptr_ra=[[NULL]], task_type=ompt_task_initial=1, has_dependences=no 32 | // CHECK-DAG: {{^}}[[MASTER_ID]]: ompt_event_cancel: task_data=[[TASK_ID:[0-9]+]], flags=ompt_cancel_parallel|ompt_cancel_activated=17, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}} 33 | // CHECK-DAG: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]] 34 | 35 | // CHECK: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_implicit_task_begin 36 | // CHECK-DAG: {{^}}[[THREAD_ID]]: ompt_event_cancel: task_data=[[TASK_ID:[0-9]+]], flags=ompt_cancel_parallel|ompt_cancel_detected=33, codeptr_ra=[[OTHER_RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}} 37 | // CHECK-DAG: {{^}}[[THREAD_ID]]: fuzzy_address={{.*}}[[OTHER_RETURN_ADDRESS]] 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /runtime/src/kmp_debugger.h: -------------------------------------------------------------------------------- 1 | #if USE_DEBUGGER 2 | /* 3 | * kmp_debugger.h -- debugger support. 4 | */ 5 | 6 | //===----------------------------------------------------------------------===// 7 | // 8 | // The LLVM Compiler Infrastructure 9 | // 10 | // This file is dual licensed under the MIT and the University of Illinois Open 11 | // Source Licenses. See LICENSE.txt for details. 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #ifndef KMP_DEBUGGER_H 16 | #define KMP_DEBUGGER_H 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif // __cplusplus 21 | 22 | /* This external variable can be set by any debugger to flag to the runtime 23 | that we are currently executing inside a debugger. This will allow the 24 | debugger to override the number of threads spawned in a parallel region by 25 | using __kmp_omp_num_threads() (below). 26 | * When __kmp_debugging is TRUE, each team and each task gets a unique integer 27 | identifier that can be used by debugger to conveniently identify teams and 28 | tasks. 29 | * The debugger has access to __kmp_omp_debug_struct_info which contains 30 | information about the OpenMP library's important internal structures. This 31 | access will allow the debugger to read detailed information from the typical 32 | OpenMP constructs (teams, threads, tasking, etc. ) during a debugging 33 | session and offer detailed and useful information which the user can probe 34 | about the OpenMP portion of their code. */ 35 | extern int __kmp_debugging; /* Boolean whether currently debugging OpenMP RTL */ 36 | // Return number of threads specified by the debugger for given parallel region. 37 | /* The ident field, which represents a source file location, is used to check if 38 | the debugger has changed the number of threads for the parallel region at 39 | source file location ident. This way, specific parallel regions' number of 40 | threads can be changed at the debugger's request. */ 41 | int __kmp_omp_num_threads(ident_t const *ident); 42 | 43 | #ifdef __cplusplus 44 | } // extern "C" 45 | #endif // __cplusplus 46 | 47 | #endif // KMP_DEBUGGER_H 48 | 49 | #endif // USE_DEBUGGER 50 | -------------------------------------------------------------------------------- /runtime/test/tasking/omp_taskwait.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run 2 | #include 3 | #include 4 | #include "omp_testsuite.h" 5 | #include "omp_my_sleep.h" 6 | 7 | int test_omp_taskwait() 8 | { 9 | int result1 = 0; /* Stores number of not finished tasks after the taskwait */ 10 | int result2 = 0; /* Stores number of wrong array elements at the end */ 11 | int array[NUM_TASKS]; 12 | int i; 13 | 14 | /* fill array */ 15 | for (i = 0; i < NUM_TASKS; i++) 16 | array[i] = 0; 17 | 18 | #pragma omp parallel 19 | { 20 | #pragma omp single 21 | { 22 | for (i = 0; i < NUM_TASKS; i++) { 23 | /* First we have to store the value of the loop index in a new variable 24 | * which will be private for each task because otherwise it will be overwritten 25 | * if the execution of the task takes longer than the time which is needed to 26 | * enter the next step of the loop! 27 | */ 28 | int myi; 29 | myi = i; 30 | #pragma omp task 31 | { 32 | my_sleep (SLEEPTIME); 33 | array[myi] = 1; 34 | } /* end of omp task */ 35 | } /* end of for */ 36 | #pragma omp taskwait 37 | /* check if all tasks were finished */ 38 | for (i = 0; i < NUM_TASKS; i++) 39 | if (array[i] != 1) 40 | result1++; 41 | 42 | /* generate some more tasks which now shall overwrite 43 | * the values in the tids array */ 44 | for (i = 0; i < NUM_TASKS; i++) { 45 | int myi; 46 | myi = i; 47 | #pragma omp task 48 | { 49 | array[myi] = 2; 50 | } /* end of omp task */ 51 | } /* end of for */ 52 | } /* end of single */ 53 | } /*end of parallel */ 54 | 55 | /* final check, if all array elements contain the right values: */ 56 | for (i = 0; i < NUM_TASKS; i++) { 57 | if (array[i] != 2) 58 | result2++; 59 | } 60 | return ((result1 == 0) && (result2 == 0)); 61 | } 62 | 63 | int main() 64 | { 65 | int i; 66 | int num_failed=0; 67 | 68 | for(i = 0; i < REPETITIONS; i++) { 69 | if(!test_omp_taskwait()) { 70 | num_failed++; 71 | } 72 | } 73 | return num_failed; 74 | } 75 | -------------------------------------------------------------------------------- /runtime/test/ompt/parallel/dynamic_enough_threads.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | FileCheck %s 2 | // REQUIRES: ompt 3 | #include "callback.h" 4 | 5 | int main() 6 | { 7 | omp_set_dynamic(1); 8 | 9 | #pragma omp parallel num_threads(4) 10 | { 11 | print_ids(0); 12 | print_ids(1); 13 | } 14 | print_fuzzy_address(1); 15 | 16 | // Check if libomp supports the callbacks for this test. 17 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_thread_begin' 18 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_thread_end' 19 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_begin' 20 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_end' 21 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task' 22 | 23 | //team-size of 1-4 is expected 24 | 25 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 26 | 27 | // make sure initial data pointers are null 28 | // CHECK-NOT: 0: parallel_data initially not null 29 | // CHECK-NOT: 0: task_data initially not null 30 | // CHECK-NOT: 0: thread_data initially not null 31 | 32 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_parallel_begin: parent_task_id=[[PARENT_TASK_ID:[0-9]+]], parent_task_frame.exit=[[NULL]], parent_task_frame.reenter={{0x[0-f]+}}, parallel_id=[[PARALLEL_ID:[0-9]+]], requested_team_size=4, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}}, invoker=[[PARALLEL_INVOKER:[0-9]+]] 33 | 34 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID:[0-9]+]], team_size={{[1-4]}} 35 | // CHECK: {{^}}[[MASTER_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]] 36 | // CHECK: {{^}}[[MASTER_ID]]: task level 1: parallel_id=[[IMPLICIT_PARALLEL_ID:[0-9]+]], task_id=[[PARENT_TASK_ID]] 37 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]] 38 | 39 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_parallel_end: parallel_id=[[PARALLEL_ID]], task_id=[[PARENT_TASK_ID]], invoker=[[PARALLEL_INVOKER]] 40 | // CHECK: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]] 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /runtime/test/ompt/parallel/dynamic_not_enough_threads.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile && env OMP_THREAD_LIMIT=2 %libomp-run | FileCheck %s 2 | // REQUIRES: ompt 3 | #include "callback.h" 4 | 5 | int main() 6 | { 7 | omp_set_dynamic(1); 8 | 9 | #pragma omp parallel num_threads(4) 10 | { 11 | print_ids(0); 12 | print_ids(1); 13 | } 14 | print_fuzzy_address(1); 15 | 16 | // Check if libomp supports the callbacks for this test. 17 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_thread_begin' 18 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_thread_end' 19 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_begin' 20 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_end' 21 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task' 22 | 23 | //team-size of 1-4 is expected 24 | 25 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 26 | 27 | // make sure initial data pointers are null 28 | // CHECK-NOT: 0: parallel_data initially not null 29 | // CHECK-NOT: 0: task_data initially not null 30 | // CHECK-NOT: 0: thread_data initially not null 31 | 32 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_parallel_begin: parent_task_id=[[PARENT_TASK_ID:[0-9]+]], parent_task_frame.exit=[[NULL]], parent_task_frame.reenter={{0x[0-f]+}}, parallel_id=[[PARALLEL_ID:[0-9]+]], requested_team_size=4, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}}, invoker=[[PARALLEL_INVOKER:[0-9]+]] 33 | 34 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID:[0-9]+]], team_size={{[1-4]}} 35 | // CHECK: {{^}}[[MASTER_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]] 36 | // CHECK: {{^}}[[MASTER_ID]]: task level 1: parallel_id=[[IMPLICIT_PARALLEL_ID:[0-9]+]], task_id=[[PARENT_TASK_ID]] 37 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]] 38 | 39 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_parallel_end: parallel_id=[[PARALLEL_ID]], task_id=[[PARENT_TASK_ID]], invoker=[[PARALLEL_INVOKER]] 40 | // CHECK: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]] 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /libomptarget/plugins/cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ##===----------------------------------------------------------------------===## 2 | # 3 | # The LLVM Compiler Infrastructure 4 | # 5 | # This file is dual licensed under the MIT and the University of Illinois Open 6 | # Source Licenses. See LICENSE.txt for details. 7 | # 8 | ##===----------------------------------------------------------------------===## 9 | # 10 | # Build a plugin for a CUDA machine if available. 11 | # 12 | ##===----------------------------------------------------------------------===## 13 | if (NOT(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(ppc64le)$" AND CMAKE_SYSTEM_NAME MATCHES "Linux")) 14 | libomptarget_say("Not building CUDA offloading plugin: only support CUDA in Linux x86_64 or ppc64le hosts.") 15 | return() 16 | elseif (NOT LIBOMPTARGET_DEP_LIBELF_FOUND) 17 | libomptarget_say("Not building CUDA offloading plugin: libelf dependency not found.") 18 | return() 19 | elseif(NOT LIBOMPTARGET_DEP_CUDA_FOUND) 20 | libomptarget_say("Not building CUDA offloading plugin: CUDA not found in system.") 21 | return() 22 | elseif(NOT LIBOMPTARGET_DEP_CUDA_DRIVER_FOUND) 23 | libomptarget_say("Not building CUDA offloading plugin: CUDA Driver API not found in system.") 24 | return() 25 | endif() 26 | 27 | libomptarget_say("Building CUDA offloading plugin.") 28 | 29 | # Define the suffix for the runtime messaging dumps. 30 | add_definitions(-DTARGET_NAME=CUDA) 31 | 32 | if(LIBOMPTARGET_CMAKE_BUILD_TYPE MATCHES debug) 33 | add_definitions(-DCUDA_ERROR_REPORT) 34 | endif() 35 | 36 | include_directories(${LIBOMPTARGET_DEP_CUDA_INCLUDE_DIRS}) 37 | include_directories(${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIRS}) 38 | 39 | add_library(omptarget.rtl.cuda SHARED src/rtl.cpp) 40 | 41 | # Install plugin under the lib destination folder. 42 | install(TARGETS omptarget.rtl.cuda LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}") 43 | 44 | target_link_libraries(omptarget.rtl.cuda 45 | ${LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES} 46 | ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES} 47 | "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports") 48 | 49 | # Report to the parent scope that we are building a plugin for CUDA. 50 | set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS} nvptx64-nvidia-cuda" PARENT_SCOPE) 51 | -------------------------------------------------------------------------------- /runtime/test/ompt/synchronization/test_nest_lock.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | FileCheck %s 2 | // REQUIRES: ompt 3 | 4 | #include "callback.h" 5 | #include 6 | 7 | int main() 8 | { 9 | omp_nest_lock_t nest_lock; 10 | omp_init_nest_lock(&nest_lock); 11 | 12 | omp_test_nest_lock(&nest_lock); 13 | omp_unset_nest_lock(&nest_lock); 14 | 15 | omp_set_nest_lock(&nest_lock); 16 | omp_test_nest_lock(&nest_lock); 17 | omp_unset_nest_lock(&nest_lock); 18 | omp_unset_nest_lock(&nest_lock); 19 | 20 | omp_destroy_nest_lock(&nest_lock); 21 | 22 | // Check if libomp supports the callbacks for this test. 23 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquire' 24 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquired' 25 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_released' 26 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_nest_lock' 27 | 28 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 29 | 30 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_init_nest_lock: wait_id=[[WAIT_ID:[0-9]+]], hint=0, impl={{[0-9]+}}, codeptr_ra={{0x[0-f]+}} 31 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_nest_lock: wait_id=[[WAIT_ID]], hint=0, impl={{[0-9]+}}, codeptr_ra={{0x[0-f]+}} 32 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_acquired_nest_lock_first: wait_id=[[WAIT_ID]], codeptr_ra={{0x[0-f]+}} 33 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_release_nest_lock_last: wait_id=[[WAIT_ID]], codeptr_ra={{0x[0-f]+}} 34 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_nest_lock: wait_id=[[WAIT_ID]], hint=0, impl={{[0-9]+}}, codeptr_ra={{0x[0-f]+}} 35 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_acquired_nest_lock_first: wait_id=[[WAIT_ID]], codeptr_ra={{0x[0-f]+}} 36 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_nest_lock: wait_id=[[WAIT_ID]], hint=0, impl={{[0-9]+}}, codeptr_ra={{0x[0-f]+}} 37 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_acquired_nest_lock_next: wait_id=[[WAIT_ID]], codeptr_ra={{0x[0-f]+}} 38 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_release_nest_lock_prev: wait_id=[[WAIT_ID]], codeptr_ra={{0x[0-f]+}} 39 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_release_nest_lock_last: wait_id=[[WAIT_ID]], codeptr_ra={{0x[0-f]+}} 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /runtime/test/ompt/synchronization/lock.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile-and-run | FileCheck %s 2 | // REQUIRES: ompt 3 | #include "callback.h" 4 | #include 5 | 6 | int main() 7 | { 8 | //need to use an OpenMP construct so that OMPT will be initalized 9 | #pragma omp parallel num_threads(1) 10 | print_ids(0); 11 | 12 | omp_lock_t lock; 13 | printf("%" PRIu64 ": &lock: %" PRIu64 "\n", ompt_get_thread_data()->value, (uint64_t) &lock); 14 | omp_init_lock(&lock); 15 | print_fuzzy_address(1); 16 | omp_set_lock(&lock); 17 | print_fuzzy_address(2); 18 | omp_unset_lock(&lock); 19 | print_fuzzy_address(3); 20 | omp_destroy_lock(&lock); 21 | print_fuzzy_address(4); 22 | 23 | 24 | // Check if libomp supports the callbacks for this test. 25 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquire' 26 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquired' 27 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_released' 28 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_nest_lock' 29 | 30 | // CHECK: 0: NULL_POINTER=[[NULL:.*$]] 31 | 32 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: &lock: [[WAIT_ID:[0-9]+]] 33 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_init_lock: wait_id=[[WAIT_ID]], hint={{[0-9]+}}, impl={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}} 34 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]] 35 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_wait_lock: wait_id=[[WAIT_ID]], hint={{[0-9]+}}, impl={{[0-9]+}}, codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}} 36 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_acquired_lock: wait_id=[[WAIT_ID]], codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}} 37 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]] 38 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_release_lock: wait_id=[[WAIT_ID]], codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}} 39 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]] 40 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_destroy_lock: wait_id=[[WAIT_ID]], codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}} 41 | // CHECK-NEXT: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]] 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /runtime/test/env/kmp_set_dispatch_buf.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile && env KMP_DISP_NUM_BUFFERS=0 %libomp-run 2 | // RUN: env KMP_DISP_NUM_BUFFERS=1 %libomp-run && env KMP_DISP_NUM_BUFFERS=3 %libomp-run 3 | // RUN: env KMP_DISP_NUM_BUFFERS=4 %libomp-run && env KMP_DISP_NUM_BUFFERS=7 %libomp-run 4 | // RUN: %libomp-compile -DMY_SCHEDULE=guided && env KMP_DISP_NUM_BUFFERS=1 %libomp-run 5 | // RUN: env KMP_DISP_NUM_BUFFERS=3 %libomp-run && env KMP_DISP_NUM_BUFFERS=4 %libomp-run 6 | // RUN: env KMP_DISP_NUM_BUFFERS=7 %libomp-run 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "omp_testsuite.h" 12 | 13 | #define INCR 7 14 | #define MY_MAX 200 15 | #define MY_MIN -200 16 | #define NUM_LOOPS 100 17 | #ifndef MY_SCHEDULE 18 | # define MY_SCHEDULE dynamic 19 | #endif 20 | 21 | int a, b, a_known_value, b_known_value; 22 | 23 | int test_kmp_set_disp_num_buffers() 24 | { 25 | int success = 1; 26 | a = 0; 27 | b = 0; 28 | // run many small dynamic loops to stress the dispatch buffer system 29 | #pragma omp parallel 30 | { 31 | int i,j; 32 | for (j = 0; j < NUM_LOOPS; j++) { 33 | #pragma omp for schedule(MY_SCHEDULE) nowait 34 | for (i = MY_MIN; i < MY_MAX; i+=INCR) { 35 | #pragma omp atomic 36 | a++; 37 | } 38 | #pragma omp for schedule(MY_SCHEDULE) nowait 39 | for (i = MY_MAX; i >= MY_MIN; i-=INCR) { 40 | #pragma omp atomic 41 | b++; 42 | } 43 | } 44 | } 45 | // detect failure 46 | if (a != a_known_value || b != b_known_value) { 47 | success = 0; 48 | printf("a = %d (should be %d), b = %d (should be %d)\n", a, a_known_value, 49 | b, b_known_value); 50 | } 51 | return success; 52 | } 53 | 54 | int main(int argc, char** argv) 55 | { 56 | int i,j; 57 | int num_failed=0; 58 | 59 | // figure out the known values to compare with calculated result 60 | a_known_value = 0; 61 | b_known_value = 0; 62 | 63 | for (j = 0; j < NUM_LOOPS; j++) { 64 | for (i = MY_MIN; i < MY_MAX; i+=INCR) 65 | a_known_value++; 66 | for (i = MY_MAX; i >= MY_MIN; i-=INCR) 67 | b_known_value++; 68 | } 69 | 70 | for(i = 0; i < REPETITIONS; i++) { 71 | if(!test_kmp_set_disp_num_buffers()) { 72 | num_failed++; 73 | } 74 | } 75 | return num_failed; 76 | } 77 | -------------------------------------------------------------------------------- /libomptarget/plugins/common/elf_common.c: -------------------------------------------------------------------------------- 1 | //===-- elf_common.c - Common ELF functionality -------------------*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.txt for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // Common ELF functionality for target plugins. 11 | // Must be included in the plugin source file AFTER omptarget.h has been 12 | // included and macro DP(...) has been defined. 13 | // . 14 | // 15 | //===----------------------------------------------------------------------===// 16 | 17 | #if !(defined(_OMPTARGET_H_) && defined(DP)) 18 | #error Include elf_common.c in the plugin source AFTER omptarget.h has been\ 19 | included and macro DP(...) has been defined. 20 | #endif 21 | 22 | #include 23 | #include 24 | 25 | // Check whether an image is valid for execution on target_id 26 | static inline int32_t elf_check_machine(__tgt_device_image *image, 27 | uint16_t target_id) { 28 | 29 | // Is the library version incompatible with the header file? 30 | if (elf_version(EV_CURRENT) == EV_NONE) { 31 | DP("Incompatible ELF library!\n"); 32 | return 0; 33 | } 34 | 35 | char *img_begin = (char *)image->ImageStart; 36 | char *img_end = (char *)image->ImageEnd; 37 | size_t img_size = img_end - img_begin; 38 | 39 | // Obtain elf handler 40 | Elf *e = elf_memory(img_begin, img_size); 41 | if (!e) { 42 | DP("Unable to get ELF handle: %s!\n", elf_errmsg(-1)); 43 | return 0; 44 | } 45 | 46 | // Check if ELF is the right kind. 47 | if (elf_kind(e) != ELF_K_ELF) { 48 | DP("Unexpected ELF type!\n"); 49 | return 0; 50 | } 51 | Elf64_Ehdr *eh64 = elf64_getehdr(e); 52 | Elf32_Ehdr *eh32 = elf32_getehdr(e); 53 | 54 | if (!eh64 && !eh32) { 55 | DP("Unable to get machine ID from ELF file!\n"); 56 | elf_end(e); 57 | return 0; 58 | } 59 | 60 | uint16_t MachineID; 61 | if (eh64 && !eh32) 62 | MachineID = eh64->e_machine; 63 | else if (eh32 && !eh64) 64 | MachineID = eh32->e_machine; 65 | else { 66 | DP("Ambiguous ELF header!\n"); 67 | elf_end(e); 68 | return 0; 69 | } 70 | 71 | elf_end(e); 72 | return MachineID == target_id; 73 | } 74 | -------------------------------------------------------------------------------- /runtime/test/env/omp_thread_limit.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile && env OMP_THREAD_LIMIT=4 %libomp-run 4 2 | // RUN: %libomp-compile && env OMP_THREAD_LIMIT=7 %libomp-run 7 3 | // 4 | // OMP_THREAD_LIMIT=N should imply that no more than N threads are active in 5 | // a contention group 6 | #include 7 | #include 8 | #include 9 | #include "omp_testsuite.h" 10 | 11 | int failed = 0; 12 | 13 | void usage() { 14 | fprintf(stderr, "usage: omp_thread_limit \n"); 15 | } 16 | 17 | void verify(const char* file_name, int line_number, int team_size) { 18 | int num_threads = omp_get_num_threads(); 19 | if (team_size != num_threads) { 20 | #pragma omp critical(A) 21 | { 22 | char label[256]; 23 | snprintf(label, sizeof(label), "%s:%d", file_name, line_number); 24 | failed = 1; 25 | printf("failed: %s: team_size(%d) != omp_get_num_threads(%d)\n", 26 | label, team_size, num_threads); 27 | } 28 | } 29 | } 30 | 31 | int main(int argc, char** argv) 32 | { 33 | int cl_thread_limit; 34 | 35 | if (argc != 2) { 36 | usage(); 37 | return 1; 38 | } 39 | cl_thread_limit = atoi(argv[1]); 40 | 41 | omp_set_dynamic(0); 42 | if (omp_get_thread_limit() != cl_thread_limit) { 43 | fprintf(stderr, "omp_get_thread_limit failed with %d, should be%d\n", 44 | omp_get_thread_limit(), cl_thread_limit); 45 | return 1; 46 | } 47 | else if (omp_get_max_threads() > cl_thread_limit) { 48 | #if _OPENMP 49 | int team_size = cl_thread_limit; 50 | #else 51 | int team_size = 1; 52 | #endif 53 | omp_set_num_threads(19); 54 | verify(__FILE__, __LINE__, 1); 55 | #pragma omp parallel 56 | { 57 | verify(__FILE__, __LINE__, team_size); 58 | verify(__FILE__, __LINE__, team_size); 59 | } 60 | verify(__FILE__, __LINE__, 1); 61 | 62 | omp_set_nested(1); 63 | #pragma omp parallel num_threads(3) 64 | { 65 | verify(__FILE__, __LINE__, 3); 66 | #pragma omp master 67 | #pragma omp parallel num_threads(21) 68 | { 69 | verify(__FILE__, __LINE__, team_size-2); 70 | verify(__FILE__, __LINE__, team_size-2); 71 | } 72 | } 73 | verify(__FILE__, __LINE__, 1); 74 | 75 | return failed; 76 | } else { 77 | fprintf(stderr, "This test is not applicable for max num_threads='%d'\n", 78 | omp_get_max_threads()); 79 | return 0; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /runtime/src/kmp_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * kmp_error.h -- PTS functions for error checking at runtime. 3 | */ 4 | 5 | //===----------------------------------------------------------------------===// 6 | // 7 | // The LLVM Compiler Infrastructure 8 | // 9 | // This file is dual licensed under the MIT and the University of Illinois Open 10 | // Source Licenses. See LICENSE.txt for details. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef KMP_ERROR_H 15 | #define KMP_ERROR_H 16 | 17 | #include "kmp_i18n.h" 18 | 19 | /* ------------------------------------------------------------------------ */ 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | void __kmp_error_construct(kmp_i18n_id_t id, enum cons_type ct, 25 | ident_t const *ident); 26 | void __kmp_error_construct2(kmp_i18n_id_t id, enum cons_type ct, 27 | ident_t const *ident, struct cons_data const *cons); 28 | 29 | struct cons_header *__kmp_allocate_cons_stack(int gtid); 30 | void __kmp_free_cons_stack(void *ptr); 31 | 32 | void __kmp_push_parallel(int gtid, ident_t const *ident); 33 | void __kmp_push_workshare(int gtid, enum cons_type ct, ident_t const *ident); 34 | #if KMP_USE_DYNAMIC_LOCK 35 | void __kmp_push_sync(int gtid, enum cons_type ct, ident_t const *ident, 36 | kmp_user_lock_p name, kmp_uint32); 37 | #else 38 | void __kmp_push_sync(int gtid, enum cons_type ct, ident_t const *ident, 39 | kmp_user_lock_p name); 40 | #endif 41 | 42 | void __kmp_check_workshare(int gtid, enum cons_type ct, ident_t const *ident); 43 | #if KMP_USE_DYNAMIC_LOCK 44 | void __kmp_check_sync(int gtid, enum cons_type ct, ident_t const *ident, 45 | kmp_user_lock_p name, kmp_uint32); 46 | #else 47 | void __kmp_check_sync(int gtid, enum cons_type ct, ident_t const *ident, 48 | kmp_user_lock_p name); 49 | #endif 50 | 51 | void __kmp_pop_parallel(int gtid, ident_t const *ident); 52 | enum cons_type __kmp_pop_workshare(int gtid, enum cons_type ct, 53 | ident_t const *ident); 54 | void __kmp_pop_sync(int gtid, enum cons_type ct, ident_t const *ident); 55 | void __kmp_check_barrier(int gtid, enum cons_type ct, ident_t const *ident); 56 | 57 | #ifdef __cplusplus 58 | } // extern "C" 59 | #endif 60 | 61 | #endif // KMP_ERROR_H 62 | -------------------------------------------------------------------------------- /runtime/test/misc_bugs/omp_foreign_thread_team_reuse.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile -lpthread && %libomp-run 2 | #include 3 | #include "omp_testsuite.h" 4 | 5 | #define NUM_THREADS 10 6 | 7 | /* 8 | After hot teams were enabled by default, the library started using levels 9 | kept in the team structure. The levels are broken in case foreign thread 10 | exits and puts its team into the pool which is then re-used by another foreign 11 | thread. The broken behavior observed is when printing the levels for each 12 | new team, one gets 1, 2, 1, 2, 1, 2, etc. This makes the library believe that 13 | every other team is nested which is incorrect. What is wanted is for the 14 | levels to be 1, 1, 1, etc. 15 | */ 16 | 17 | int a = 0; 18 | int level; 19 | 20 | typedef struct thread_arg_t { 21 | int iterations; 22 | } thread_arg_t; 23 | 24 | void* thread_function(void* arg) { 25 | int i; 26 | thread_arg_t* targ = (thread_arg_t*)arg; 27 | int iterations = targ->iterations; 28 | #pragma omp parallel private(i) 29 | { 30 | // level should always be 1 31 | #pragma omp single 32 | level = omp_get_level(); 33 | 34 | #pragma omp for 35 | for(i = 0; i < iterations; i++) { 36 | #pragma omp atomic 37 | a++; 38 | } 39 | } 40 | } 41 | 42 | int test_omp_team_reuse() 43 | { 44 | int i; 45 | int success = 1; 46 | pthread_t thread[NUM_THREADS]; 47 | thread_arg_t thread_arg[NUM_THREADS]; 48 | // launch NUM_THREADS threads, one at a time to perform thread_function() 49 | for(i = 0; i < NUM_THREADS; i++) { 50 | thread_arg[i].iterations = i + 1; 51 | pthread_create(thread+i, NULL, thread_function, thread_arg+i); 52 | pthread_join(*(thread+i), NULL); 53 | // level read in thread_function()'s parallel region should be 1 54 | if(level != 1) { 55 | fprintf(stderr, "error: for pthread %d level should be 1 but " 56 | "instead equals %d\n", i, level); 57 | success = 0; 58 | } 59 | } 60 | // make sure the for loop works 61 | int known_sum = (NUM_THREADS * (NUM_THREADS+1)) / 2; 62 | if(a != known_sum) { 63 | fprintf(stderr, "a should be %d but instead equals %d\n", known_sum, a); 64 | success = 0; 65 | } 66 | return success; 67 | } 68 | 69 | int main() 70 | { 71 | int i; 72 | int num_failed=0; 73 | 74 | for(i = 0; i < REPETITIONS; i++) { 75 | a = 0; 76 | if(!test_omp_team_reuse()) { 77 | num_failed++; 78 | } 79 | } 80 | return num_failed; 81 | } 82 | -------------------------------------------------------------------------------- /runtime/doc/doxygen/header.tex: -------------------------------------------------------------------------------- 1 | % Latex header for doxygen 1.8.3.1 2 | \documentclass{book} 3 | \usepackage[a4paper,top=2.5cm,bottom=2.5cm,left=2.5cm,right=2.5cm]{geometry} 4 | \usepackage{makeidx} 5 | \usepackage{natbib} 6 | \usepackage{graphicx} 7 | \usepackage{multicol} 8 | \usepackage{float} 9 | \usepackage{listings} 10 | \usepackage{color} 11 | \usepackage{ifthen} 12 | \usepackage[table]{xcolor} 13 | \usepackage{textcomp} 14 | \usepackage{alltt} 15 | \usepackage{ifpdf} 16 | \ifpdf 17 | \usepackage[pdftex, 18 | pagebackref=true, 19 | colorlinks=true, 20 | linkcolor=blue, 21 | unicode 22 | ]{hyperref} 23 | \else 24 | \usepackage[ps2pdf, 25 | pagebackref=true, 26 | colorlinks=true, 27 | linkcolor=blue, 28 | unicode 29 | ]{hyperref} 30 | \usepackage{pspicture} 31 | \fi 32 | \usepackage[utf8]{inputenc} 33 | \usepackage{mathptmx} 34 | \usepackage[scaled=.90]{helvet} 35 | \usepackage{courier} 36 | \usepackage{sectsty} 37 | \usepackage{amssymb} 38 | \usepackage[titles]{tocloft} 39 | \usepackage{doxygen} 40 | \lstset{language=C++,inputencoding=utf8,basicstyle=\footnotesize,breaklines=true,breakatwhitespace=true,tabsize=4,numbers=left } 41 | \makeindex 42 | \setcounter{tocdepth}{3} 43 | \renewcommand{\footrulewidth}{0.4pt} 44 | \renewcommand{\familydefault}{\sfdefault} 45 | \hfuzz=15pt 46 | \setlength{\emergencystretch}{15pt} 47 | \hbadness=750 48 | \tolerance=750 49 | \begin{document} 50 | \hypersetup{pageanchor=false,citecolor=blue} 51 | \begin{titlepage} 52 | \vspace*{7cm} 53 | \begin{center} 54 | {\Large LLVM OpenMP\textsuperscript{*} Runtime Library }\\ 55 | \vspace*{1cm} 56 | {\large Generated by Doxygen $doxygenversion }\\ 57 | \vspace*{0.5cm} 58 | {\small $datetime }\\ 59 | \end{center} 60 | \end{titlepage} 61 | 62 | {\bf Trademarks} 63 | The OpenMP name and the OpenMP logo are registered trademarks of the OpenMP Architecture Review Board. 64 | 65 | Intel, Xeon, and Intel Xeon Phi are trademarks of Intel Corporation in the U.S. and/or other countries. 66 | 67 | This document is Copyright \textcopyright~\the\year the LLVM Project. It is 68 | subject to the same license terms as the LLVM OpenMP runtime. 69 | 70 | \textsuperscript{*} Other names and brands may be claimed as the property of others. 71 | 72 | \clearemptydoublepage 73 | \pagenumbering{roman} 74 | \tableofcontents 75 | \clearemptydoublepage 76 | \pagenumbering{arabic} 77 | \hypersetup{pageanchor=true,citecolor=blue} 78 | -------------------------------------------------------------------------------- /runtime/tools/lib/LibOMP.pm: -------------------------------------------------------------------------------- 1 | # 2 | #//===----------------------------------------------------------------------===// 3 | #// 4 | #// The LLVM Compiler Infrastructure 5 | #// 6 | #// This file is dual licensed under the MIT and the University of Illinois Open 7 | #// Source Licenses. See LICENSE.txt for details. 8 | #// 9 | #//===----------------------------------------------------------------------===// 10 | # 11 | package LibOMP; 12 | 13 | use strict; 14 | use warnings; 15 | 16 | use tools; 17 | 18 | sub empty($) { 19 | my ( $var ) = @_; 20 | return (not exists($ENV{$var})) or (not defined($ENV{$var})) or ($ENV{$var} eq ""); 21 | }; # sub empty 22 | 23 | my ( $base, $out, $tmp ); 24 | if ( empty( "LIBOMP_WORK" ) ) { 25 | # $FindBin::Bin is not used intentionally because it gives real path. I want to use absolute, 26 | # but not real one (real path does not contain symlinks while absolute path may contain 27 | # symlinks). 28 | $base = get_dir( get_dir( abs_path( $0 ) ) ); 29 | } else { 30 | $base = abs_path( $ENV{ LIBOMP_WORK } ); 31 | }; # if 32 | 33 | if ( empty( "LIBOMP_EXPORTS" ) ) { 34 | $out = cat_dir( $base, "exports" ); 35 | } else { 36 | $out = abs_path( $ENV{ LIBOMP_EXPORTS } ); 37 | }; # if 38 | 39 | if ( empty( "LIBOMP_TMP" ) ) { 40 | $tmp = cat_dir( $base, "tmp" ); 41 | } else { 42 | $tmp = abs_path( $ENV{ LIBOMP_TMP } ); 43 | }; # if 44 | 45 | $ENV{ LIBOMP_WORK } = $base; 46 | $ENV{ LIBOMP_EXPORTS } = $out; 47 | $ENV{ LIBOMP_TMP } = $tmp; 48 | 49 | return 1; 50 | 51 | __END__ 52 | 53 | =pod 54 | 55 | =head1 NAME 56 | 57 | B -- 58 | 59 | =head1 SYNOPSIS 60 | 61 | use FindBin; 62 | use lib "$FindBin::Bin/lib"; 63 | use LibOMP; 64 | 65 | $ENV{ LIBOMP_WORK } 66 | $ENV{ LIBOMP_TMP } 67 | $ENV{ LIBOMP_EXPORTS } 68 | 69 | =head1 DESCRIPTION 70 | 71 | The module checks C, C, and C environments variables. 72 | If a variable set, the module makes sure it is absolute. If a variable does not exist, the module 73 | sets it to default value. 74 | 75 | Default value for C is C<$LIBOMP_WORK/exports>, for C -- 76 | C<$LIBOMP_WORK/tmp>. 77 | 78 | Value for C is guessed. The module assumes the script (which uses the module) is 79 | located in C directory of libomp directory tree, and uses path of the script to calculate 80 | C, 81 | 82 | =cut 83 | 84 | # end of file # 85 | 86 | -------------------------------------------------------------------------------- /runtime/src/thirdparty/ittnotify/ittnotify_types.h: -------------------------------------------------------------------------------- 1 | 2 | //===----------------------------------------------------------------------===// 3 | // 4 | // The LLVM Compiler Infrastructure 5 | // 6 | // This file is dual licensed under the MIT and the University of Illinois Open 7 | // Source Licenses. See LICENSE.txt for details. 8 | // 9 | //===----------------------------------------------------------------------===// 10 | 11 | #ifndef _ITTNOTIFY_TYPES_H_ 12 | #define _ITTNOTIFY_TYPES_H_ 13 | 14 | typedef enum ___itt_group_id 15 | { 16 | __itt_group_none = 0, 17 | __itt_group_legacy = 1<<0, 18 | __itt_group_control = 1<<1, 19 | __itt_group_thread = 1<<2, 20 | __itt_group_mark = 1<<3, 21 | __itt_group_sync = 1<<4, 22 | __itt_group_fsync = 1<<5, 23 | __itt_group_jit = 1<<6, 24 | __itt_group_model = 1<<7, 25 | __itt_group_splitter_min = 1<<7, 26 | __itt_group_counter = 1<<8, 27 | __itt_group_frame = 1<<9, 28 | __itt_group_stitch = 1<<10, 29 | __itt_group_heap = 1<<11, 30 | __itt_group_splitter_max = 1<<12, 31 | __itt_group_structure = 1<<12, 32 | __itt_group_suppress = 1<<13, 33 | __itt_group_arrays = 1<<14, 34 | __itt_group_all = -1 35 | } __itt_group_id; 36 | 37 | #pragma pack(push, 8) 38 | 39 | typedef struct ___itt_group_list 40 | { 41 | __itt_group_id id; 42 | const char* name; 43 | } __itt_group_list; 44 | 45 | #pragma pack(pop) 46 | 47 | #define ITT_GROUP_LIST(varname) \ 48 | static __itt_group_list varname[] = { \ 49 | { __itt_group_all, "all" }, \ 50 | { __itt_group_control, "control" }, \ 51 | { __itt_group_thread, "thread" }, \ 52 | { __itt_group_mark, "mark" }, \ 53 | { __itt_group_sync, "sync" }, \ 54 | { __itt_group_fsync, "fsync" }, \ 55 | { __itt_group_jit, "jit" }, \ 56 | { __itt_group_model, "model" }, \ 57 | { __itt_group_counter, "counter" }, \ 58 | { __itt_group_frame, "frame" }, \ 59 | { __itt_group_stitch, "stitch" }, \ 60 | { __itt_group_heap, "heap" }, \ 61 | { __itt_group_structure, "structure" }, \ 62 | { __itt_group_suppress, "suppress" }, \ 63 | { __itt_group_arrays, "arrays" }, \ 64 | { __itt_group_none, NULL } \ 65 | } 66 | 67 | #endif /* _ITTNOTIFY_TYPES_H_ */ 68 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/omp_for_schedule_runtime.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile 2 | // RUN: env OMP_SCHEDULE=static %libomp-run 1 0 3 | // RUN: env OMP_SCHEDULE=static,10 %libomp-run 1 10 4 | // RUN: env OMP_SCHEDULE=dynamic %libomp-run 2 1 5 | // RUN: env OMP_SCHEDULE=dynamic,11 %libomp-run 2 11 6 | // RUN: env OMP_SCHEDULE=guided %libomp-run 3 1 7 | // RUN: env OMP_SCHEDULE=guided,12 %libomp-run 3 12 8 | // RUN: env OMP_SCHEDULE=auto %libomp-run 4 1 9 | // RUN: env OMP_SCHEDULE=trapezoidal %libomp-run 101 1 10 | // RUN: env OMP_SCHEDULE=trapezoidal,13 %libomp-run 101 13 11 | // RUN: env OMP_SCHEDULE=static_steal %libomp-run 102 1 12 | // RUN: env OMP_SCHEDULE=static_steal,14 %libomp-run 102 14 13 | #include 14 | #include 15 | #include 16 | #include "omp_testsuite.h" 17 | 18 | int sum; 19 | char* correct_kind_string; 20 | omp_sched_t correct_kind; 21 | int correct_chunk_size; 22 | 23 | int test_omp_for_runtime() 24 | { 25 | int sum; 26 | int known_sum; 27 | int chunk_size; 28 | int error; 29 | omp_sched_t kind; 30 | 31 | sum = 0; 32 | error = 0; 33 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; 34 | omp_get_schedule(&kind, &chunk_size); 35 | 36 | printf("omp_get_schedule() returns: Schedule = %d, Chunk Size = %d\n", 37 | kind, chunk_size); 38 | if (kind != correct_kind) { 39 | printf("kind(%d) != correct_kind(%d)\n", kind, correct_kind); 40 | error = 1; 41 | } 42 | if (chunk_size != correct_chunk_size) { 43 | printf("chunk_size(%d) != correct_chunk_size(%d)\n", chunk_size, 44 | correct_chunk_size); 45 | error = 1; 46 | } 47 | 48 | #pragma omp parallel 49 | { 50 | int i; 51 | #pragma omp for schedule(runtime) 52 | for (i = 1; i <= LOOPCOUNT; i++) { 53 | #pragma omp critical 54 | sum+=i; 55 | } 56 | } 57 | if (known_sum != sum) { 58 | printf("Known Sum = %d, Calculated Sum = %d\n", known_sum, sum); 59 | error = 1; 60 | } 61 | return !error; 62 | } 63 | 64 | int main(int argc, char** argv) 65 | { 66 | int i; 67 | int num_failed=0; 68 | if (argc != 3) { 69 | fprintf(stderr, "usage: %s schedule_kind chunk_size\n", argv[0]); 70 | fprintf(stderr, " Run with envirable OMP_SCHEDULE=kind[,chunk_size]\n"); 71 | return 1; 72 | } 73 | correct_kind = atoi(argv[1]); 74 | correct_chunk_size = atoi(argv[2]); 75 | 76 | for (i = 0; i < REPETITIONS; i++) { 77 | if (!test_omp_for_runtime()) { 78 | num_failed++; 79 | } 80 | } 81 | return num_failed; 82 | } 83 | -------------------------------------------------------------------------------- /runtime/test/ompt/cancel/cancel_worksharing.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile && env OMP_CANCELLATION=true %libomp-run | %sort-threads | FileCheck %s 2 | // REQUIRES: ompt 3 | // Current GOMP interface implementation does not support cancellation; icc 16 does not distinguish between sections and loops 4 | // XFAIL: gcc, icc-16 5 | 6 | #include "callback.h" 7 | #include 8 | 9 | int main() 10 | { 11 | int condition=0; 12 | #pragma omp parallel num_threads(2) 13 | { 14 | int x = 0; 15 | int i; 16 | #pragma omp for 17 | for(i = 0; i < 2; i++) 18 | { 19 | if(i == 0) 20 | { 21 | x++; 22 | OMPT_SIGNAL(condition); 23 | #pragma omp cancel for 24 | } 25 | else 26 | { 27 | x++; 28 | OMPT_WAIT(condition,1); 29 | delay(10000); 30 | #pragma omp cancellation point for 31 | } 32 | } 33 | } 34 | #pragma omp parallel num_threads(2) 35 | { 36 | #pragma omp sections 37 | { 38 | #pragma omp section 39 | { 40 | OMPT_SIGNAL(condition); 41 | #pragma omp cancel sections 42 | } 43 | #pragma omp section 44 | { 45 | OMPT_WAIT(condition,2); 46 | delay(10000); 47 | #pragma omp cancellation point sections 48 | } 49 | } 50 | } 51 | 52 | 53 | // Check if libomp supports the callbacks for this test. 54 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create' 55 | // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_cancel' 56 | 57 | // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]] 58 | // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_task_create: parent_task_id=[[PARENT_TASK_ID:[0-9]+]], parent_task_frame.exit=[[NULL]], parent_task_frame.reenter=[[NULL]], new_task_id=[[TASK_ID:[0-9]+]], codeptr_ra=[[NULL]], task_type=ompt_task_initial=1, has_dependences=no 59 | 60 | // cancel for and sections 61 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_cancel: task_data=[[TASK_ID:[0-9]+]], flags=ompt_cancel_do|ompt_cancel_activated=20, codeptr_ra={{0x[0-f]*}} 62 | // CHECK: {{^}}[[MASTER_ID]]: ompt_event_cancel: task_data=[[TASK_ID:[0-9]+]], flags=ompt_cancel_sections|ompt_cancel_activated=18, codeptr_ra={{0x[0-f]*}} 63 | // CHECK: {{^}}[[OTHER_THREAD_ID:[0-9]+]]: ompt_event_cancel: task_data=[[TASK_ID:[0-9]+]], flags=ompt_cancel_do|ompt_cancel_detected=36, codeptr_ra={{0x[0-f]*}} 64 | // CHECK: {{^}}[[OTHER_THREAD_ID:[0-9]+]]: ompt_event_cancel: task_data=[[TASK_ID:[0-9]+]], flags=ompt_cancel_sections|ompt_cancel_detected=34, codeptr_ra={{0x[0-f]*}} 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /runtime/test/worksharing/for/kmp_set_dispatch_buf.c: -------------------------------------------------------------------------------- 1 | // RUN: %libomp-compile && %libomp-run 7 2 | // RUN: %libomp-run 0 && %libomp-run -1 3 | // RUN: %libomp-run 1 && %libomp-run 2 && %libomp-run 5 4 | // RUN: %libomp-compile -DMY_SCHEDULE=guided && %libomp-run 7 5 | // RUN: %libomp-run 1 && %libomp-run 2 && %libomp-run 5 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "omp_testsuite.h" 11 | 12 | #define INCR 7 13 | #define MY_MAX 200 14 | #define MY_MIN -200 15 | #ifndef MY_SCHEDULE 16 | # define MY_SCHEDULE dynamic 17 | #endif 18 | 19 | int num_disp_buffers, num_loops; 20 | int a, b, a_known_value, b_known_value; 21 | 22 | int test_kmp_set_disp_num_buffers() 23 | { 24 | int success = 1; 25 | a = 0; 26 | b = 0; 27 | // run many small dynamic loops to stress the dispatch buffer system 28 | #pragma omp parallel 29 | { 30 | int i,j; 31 | for (j = 0; j < num_loops; j++) { 32 | #pragma omp for schedule(MY_SCHEDULE) nowait 33 | for (i = MY_MIN; i < MY_MAX; i+=INCR) { 34 | #pragma omp atomic 35 | a++; 36 | } 37 | #pragma omp for schedule(MY_SCHEDULE) nowait 38 | for (i = MY_MAX; i >= MY_MIN; i-=INCR) { 39 | #pragma omp atomic 40 | b++; 41 | } 42 | } 43 | } 44 | // detect failure 45 | if (a != a_known_value || b != b_known_value) { 46 | success = 0; 47 | printf("a = %d (should be %d), b = %d (should be %d)\n", a, a_known_value, 48 | b, b_known_value); 49 | } 50 | return success; 51 | } 52 | 53 | int main(int argc, char** argv) 54 | { 55 | int i,j; 56 | int num_failed=0; 57 | 58 | if (argc != 2) { 59 | fprintf(stderr, "usage: %s num_disp_buffers\n", argv[0]); 60 | exit(1); 61 | } 62 | 63 | // set the number of dispatch buffers 64 | num_disp_buffers = atoi(argv[1]); 65 | kmp_set_disp_num_buffers(num_disp_buffers); 66 | 67 | // figure out the known values to compare with calculated result 68 | a_known_value = 0; 69 | b_known_value = 0; 70 | 71 | // if specified to use bad num_disp_buffers set num_loops 72 | // to something reasonable 73 | if (num_disp_buffers <= 0) 74 | num_loops = 10; 75 | else 76 | num_loops = num_disp_buffers*10; 77 | 78 | for (j = 0; j < num_loops; j++) { 79 | for (i = MY_MIN; i < MY_MAX; i+=INCR) 80 | a_known_value++; 81 | for (i = MY_MAX; i >= MY_MIN; i-=INCR) 82 | b_known_value++; 83 | } 84 | 85 | for(i = 0; i < REPETITIONS; i++) { 86 | if(!test_kmp_set_disp_num_buffers()) { 87 | num_failed++; 88 | } 89 | } 90 | return num_failed; 91 | } 92 | -------------------------------------------------------------------------------- /runtime/src/kmp_environment.h: -------------------------------------------------------------------------------- 1 | /* 2 | * kmp_environment.h -- Handle environment varoiables OS-independently. 3 | */ 4 | 5 | //===----------------------------------------------------------------------===// 6 | // 7 | // The LLVM Compiler Infrastructure 8 | // 9 | // This file is dual licensed under the MIT and the University of Illinois Open 10 | // Source Licenses. See LICENSE.txt for details. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #ifndef KMP_ENVIRONMENT_H 15 | #define KMP_ENVIRONMENT_H 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | // Return a copy of the value of environment variable or NULL if the variable 22 | // does not exist. 23 | // *Note*: Returned pointed *must* be freed after use with __kmp_env_free(). 24 | char *__kmp_env_get(char const *name); 25 | void __kmp_env_free(char const **value); 26 | 27 | // Return 1 if the environment variable exists or 0 if does not exist. 28 | int __kmp_env_exists(char const *name); 29 | 30 | // Set the environment variable. 31 | void __kmp_env_set(char const *name, char const *value, int overwrite); 32 | 33 | // Unset (remove) environment variable. 34 | void __kmp_env_unset(char const *name); 35 | 36 | // ----------------------------------------------------------------------------- 37 | // Working with environment blocks. 38 | 39 | /* kmp_env_blk_t is read-only collection of environment variables (or 40 | environment-like). Usage: 41 | 42 | kmp_env_blk_t block; 43 | __kmp_env_blk_init( & block, NULL ); // Initialize block from process 44 | // environment. 45 | // or 46 | __kmp_env_blk_init( & block, "KMP_WARNING=1|KMP_AFFINITY=none" ); // from string 47 | __kmp_env_blk_sort( & block ); // Optionally, sort list. 48 | for ( i = 0; i < block.count; ++ i ) { 49 | // Process block.vars[ i ].name and block.vars[ i ].value... 50 | } 51 | __kmp_env_block_free( & block ); 52 | */ 53 | 54 | struct __kmp_env_var { 55 | char *name; 56 | char *value; 57 | }; 58 | typedef struct __kmp_env_var kmp_env_var_t; 59 | 60 | struct __kmp_env_blk { 61 | char *bulk; 62 | kmp_env_var_t *vars; 63 | int count; 64 | }; 65 | typedef struct __kmp_env_blk kmp_env_blk_t; 66 | 67 | void __kmp_env_blk_init(kmp_env_blk_t *block, char const *bulk); 68 | void __kmp_env_blk_free(kmp_env_blk_t *block); 69 | void __kmp_env_blk_sort(kmp_env_blk_t *block); 70 | char const *__kmp_env_blk_var(kmp_env_blk_t *block, char const *name); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif // KMP_ENVIRONMENT_H 77 | 78 | // end of file // 79 | -------------------------------------------------------------------------------- /libomptarget/deviceRTLs/nvptx/src/option.h: -------------------------------------------------------------------------------- 1 | //===------------ option.h - NVPTX OpenMP GPU options ------------ CUDA -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.txt for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // GPU default options 11 | // 12 | //===----------------------------------------------------------------------===// 13 | #ifndef _OPTION_H_ 14 | #define _OPTION_H_ 15 | 16 | //////////////////////////////////////////////////////////////////////////////// 17 | // Kernel options 18 | //////////////////////////////////////////////////////////////////////////////// 19 | 20 | //////////////////////////////////////////////////////////////////////////////// 21 | // The following def must match the absolute limit hardwired in the host RTL 22 | // max number of threads per team 23 | #define MAX_THREADS_PER_TEAM 1024 24 | 25 | #define WARPSIZE 32 26 | 27 | // The named barrier for active parallel threads of a team in an L1 parallel 28 | // region to synchronize with each other. 29 | #define L1_BARRIER (1) 30 | 31 | // Maximum number of preallocated arguments to an outlined parallel/simd function. 32 | // Anything more requires dynamic memory allocation. 33 | #define MAX_SHARED_ARGS 20 34 | 35 | // Maximum number of omp state objects per SM allocated statically in global 36 | // memory. 37 | #if __CUDA_ARCH__ >= 600 38 | #define OMP_STATE_COUNT 32 39 | #define MAX_SM 56 40 | #else 41 | #define OMP_STATE_COUNT 16 42 | #define MAX_SM 16 43 | #endif 44 | 45 | //////////////////////////////////////////////////////////////////////////////// 46 | // algo options 47 | //////////////////////////////////////////////////////////////////////////////// 48 | 49 | //////////////////////////////////////////////////////////////////////////////// 50 | // data options 51 | //////////////////////////////////////////////////////////////////////////////// 52 | 53 | // decide if counters are 32 or 64 bit 54 | #define Counter unsigned long long 55 | 56 | //////////////////////////////////////////////////////////////////////////////// 57 | // misc options (by def everythig here is device) 58 | //////////////////////////////////////////////////////////////////////////////// 59 | 60 | #define EXTERN extern "C" __device__ 61 | #define INLINE __inline__ __device__ 62 | #define NOINLINE __noinline__ __device__ 63 | #ifndef TRUE 64 | #define TRUE 1 65 | #endif 66 | #ifndef FALSE 67 | #define FALSE 0 68 | #endif 69 | 70 | #endif 71 | --------------------------------------------------------------------------------