From e9617107aa9bc164b371a5edf31464d4b32005a8 Mon Sep 17 00:00:00 2001 From: Patrick Vogler Date: Thu, 15 Feb 2024 11:55:03 +0100 Subject: [PATCH] Removed the bwc_set_nThreads function in favor of the OMP_NUM_THREADS environment variable/set omp_set_num_threads function to clean up the API --- include/library/private/libbwc.h | 14 ------ include/library/private/types.h | 3 -- public_header.py | 8 +-- src/interfaces/fortran/bwc.F90 | 19 +------- src/interfaces/python/bwc.py | 7 --- src/library/dwt.c | 4 +- src/library/libbwc.c | 83 -------------------------------- src/library/tier1.c | 4 +- src/tools/bwccmdl.c | 4 +- 9 files changed, 11 insertions(+), 135 deletions(-) diff --git a/include/library/private/libbwc.h b/include/library/private/libbwc.h index 9a0cfe6..eca0717 100755 --- a/include/library/private/libbwc.h +++ b/include/library/private/libbwc.h @@ -320,20 +320,6 @@ void bwc_set_tiles(bwc_field *const field, uint64 tilesX, uint64 tilesY, uint64 tilesZ, uint16 tilesTS, bwc_tile_instr instr); - /*----------------------------------------------------------------------------------------------------------*\ - ! FUNCTION NAME: void bwc_set_nThreads(bwc_field *const field, uint16 nThreads) ! - ! ! - ! DESCRIPTION: ! - ! ------------ ! - ! This function is used to indicate the maximum number of threads used during ! - ! (de)compression. ! - ! ! - \*----------------------------------------------------------------------------------------------------------*/ - #if defined(_OPENMP) - void - bwc_set_nThreads(bwc_field *const field, uint8 nThreads); - #endif - /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: void bwc_create_compression(bwc_field *field, char *rate_control) ! ! -------------- ! diff --git a/include/library/private/types.h b/include/library/private/types.h index 2946984..a12744d 100755 --- a/include/library/private/types.h +++ b/include/library/private/types.h @@ -1718,9 +1718,6 @@ bwc_packed_stream header; bwc_prog_ord progression; bwc_quant_st quantization_style; - #ifdef _OPENMP - uint8 nThreads; - #endif } bwc_gl_ctrl; /*----------------------------------------------------------------------------------------------------------*\ diff --git a/public_header.py b/public_header.py index f14028d..3ee4c8d 100644 --- a/public_header.py +++ b/public_header.py @@ -282,9 +282,9 @@ public_header.write("\n" + ubox + tab + "||" + lspaces * " " + "___ _ _ ___ _ tab + "||" + lspaces * " " + "| |__| |__] |___ | |___ | |__| | \| |___ | | |__| | \| ___]" + rspaces * " " + "||\n" + tab + "||" + (116 - len(tab)) * " " + "||\n" + lbox) -public_header.write("\n" + tab + "#ifdef __cplusplus\n" + - tab + "extern \"C\" {\n" + - tab + "#endif\n\n") +public_header.write(tab + "#ifdef __cplusplus\n" + + tab + "extern \"C\" {\n" + + tab + "#endif\n\n") files = os.listdir("include/library/private") printFlg = False @@ -334,7 +334,7 @@ for file in files: public_header.write("\n" + tab + "#ifdef __cplusplus\n" + tab + "}\n" + - tab + "#endif\n\n") + tab + "#endif\n") public_header.write("#endif") public_header.close \ No newline at end of file diff --git a/src/interfaces/fortran/bwc.F90 b/src/interfaces/fortran/bwc.F90 index ee93b1e..b71e98a 100644 --- a/src/interfaces/fortran/bwc.F90 +++ b/src/interfaces/fortran/bwc.F90 @@ -312,22 +312,6 @@ module bwc INTEGER(KIND=C_INT), VALUE :: instr end subroutine set_tiles_f !*============================================================================================*! - #ifdef _OPENMP - subroutine set_nThreads_f(field, nThreads) & - BIND(C, NAME="bwc_set_nThreads") - IMPORT - !*-----------------------*! - ! DEFINE POINTERS: ! - !*-----------------------*! - TYPE(C_PTR), VALUE :: field - - !*-----------------------*! - ! DEFINE INT VARIABLES: ! - !*-----------------------*! - INTEGER(KIND=C_INT8_T), VALUE :: nThreads - end subroutine set_nThreads_f - #endif - !*============================================================================================*! function create_compression_f(field, rate_control) result(error_flag) & BIND(C, NAME="bwc_create_compression") IMPORT @@ -428,8 +412,7 @@ module bwc bwc_set_precincts, & bwc_set_codeblocks, & bwc_set_qm, & - bwc_set_tiles, & - bwc_set_nThreads + bwc_set_tiles, public :: bwc_create_compression, & bwc_compress, & diff --git a/src/interfaces/python/bwc.py b/src/interfaces/python/bwc.py index 474dc87..8b3fd5c 100644 --- a/src/interfaces/python/bwc.py +++ b/src/interfaces/python/bwc.py @@ -31,7 +31,6 @@ #| - bwc_set_quantization_style |# #| - bwc_set_qm |# #| - bwc_set_quantization_step_size |# -#| - bwc_set_nThreads |# #| - bwc_set_memory_limit |# #| - bwc_compress |# #| - bwc_decompress |# @@ -160,12 +159,6 @@ def initialize_field(data): fun.argtypes = [ctypes.c_void_p] return ctypes.c_void_p(fun(data)) #=======================================================================================================================# -def set_nThreads(field, nThreads): - fun = libbwc.bwc_set_nThreads - fun.restype = None - fun.argtypes = [ctypes.c_void_p, ctypes.c_int8] - fun(field, nThreads) -#=======================================================================================================================# def set_codeblocks(field, cbX, cbY, cbZ, cbTS): fun = libbwc.bwc_set_codeblocks fun.restype = None diff --git a/src/library/dwt.c b/src/library/dwt.c index de9a7c1..837241a 100755 --- a/src/library/dwt.c +++ b/src/library/dwt.c @@ -1735,7 +1735,7 @@ forward_discrete_wavelet_transform(bwc_field *const field, bwc_parameter *const ! eter. ! \*--------------------------------------------------------*/ #if defined (_OPENMP) - nThreads = control->nThreads; + nThreads = omp_get_max_threads(); #else nThreads = 1; #endif @@ -2272,7 +2272,7 @@ inverse_discrete_wavelet_transform(bwc_field *const field, bwc_parameter *const ! eter. ! \*--------------------------------------------------------*/ #if defined (_OPENMP) - nThreads = control->nThreads; + nThreads = omp_get_max_threads(); #else nThreads = 1; #endif diff --git a/src/library/libbwc.c b/src/library/libbwc.c index 07b8b49..54d2626 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -2588,17 +2588,6 @@ bwc_initialize_field(bwc_data *const data) \*--------------------------------------------------------*/ info->precision = PREC_BYTE; - /*--------------------------------------------------------*\ - ! Initialize the number of threads used for the current ! - ! run. ! - \*--------------------------------------------------------*/ - #ifdef _OPENMP - #pragma omp parallel - { - control->nThreads = omp_get_num_threads(); - } - #endif - /*--------------------------------------------------------*\ ! Calculate the possible decomposition levels for all ! ! spatial and temporal dimensions. ! @@ -3723,64 +3712,6 @@ bwc_set_tiles(bwc_field *const field, uint64 tilesX, uint64 tilesY, uint64 tiles control->CSsgc |= (0x01 << 9); } -/*----------------------------------------------------------------------------------------------------------*\ -! FUNCTION NAME: void bwc_set_nThreads(bwc_field *const field, uint16 nThreads) ! -! ! -! DESCRIPTION: ! -! ------------ ! -! This function is used to indicate the maximum number of threads used during ! -! (de)compression. ! -! ! -! PARAMETERS: ! -! ----------- ! -! Variable Type Description ! -! -------- ---- ----------- ! -! field bwc_field* - Structure defining the compression/ ! -! decompression stage. ! -! ! -! nThreads unsigned int(8 bit) - Number of OpenMP threads. ! -! ! -! RETURN VALUE: ! -! ------------- ! -! Type Description ! -! ---- ----------- ! -! - - ! -! ! -! DEVELOPMENT HISTORY: ! -! -------------------- ! -! ! -! Date Author Change Id Release Description Of Change ! -! ---- ------ --------- ------- --------------------- ! -! 07.08.2018 Patrick Vogler B87D120 V 0.1.0 function created ! -! ! -\*----------------------------------------------------------------------------------------------------------*/ -#if defined(_OPENMP) - void - bwc_set_nThreads(bwc_field *const field, uint8 nThreads) - { - /*-----------------------*\ - ! DEFINE STRUCTS: ! - \*-----------------------*/ - bwc_gl_ctrl *control; - - /*-----------------------*\ - ! DEFINE ASSERTIONS: ! - \*-----------------------*/ - assert(field); - - /*--------------------------------------------------------*\ - ! Save the global control and to a temporary variable to ! - ! make the code more readable. ! - \*--------------------------------------------------------*/ - control = &field->control; - - /*--------------------------------------------------------*\ - ! Amend the number of OMP threads the bwc_field structure. ! - \*--------------------------------------------------------*/ - control->nThreads = nThreads; - } -#endif - /*----------------------------------------------------------------------------------------------------------*\ ! FUNCTION NAME: void bwc_create_compression(bwc_field *field, char *rate_control) ! ! -------------- ! @@ -4051,13 +3982,6 @@ bwc_compress(bwc_field *const field, bwc_data *const data) return 1; } - /*--------------------------------------------------------*\ - ! Set the number of Open MP threads for the current run. ! - \*--------------------------------------------------------*/ - #if defined (_OPENMP) - omp_set_num_threads(control->nThreads); - #endif - /*--------------------------------------------------------*\ ! Evaluate the working buffer size and allocate it accord- ! ! ingly. ! @@ -4391,13 +4315,6 @@ bwc_decompress(bwc_field *const field, bwc_data *const data) control = &field->control; info = field->info; - /*--------------------------------------------------------*\ - ! Set the number of Open MP threads for the current run. ! - \*--------------------------------------------------------*/ - #if defined (_OPENMP) - omp_set_num_threads(control->nThreads); - #endif - /*--------------------------------------------------------*\ ! Calculate the field size after subsampling and allocate ! ! the field memory blocks. ! diff --git a/src/library/tier1.c b/src/library/tier1.c index 3c47bdb..30c7618 100755 --- a/src/library/tier1.c +++ b/src/library/tier1.c @@ -2904,7 +2904,7 @@ t1_encode(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const par ! pression run. ! \*--------------------------------------------------------*/ #if defined (_OPENMP) - nThreads = control->nThreads; + nThreads = omp_get_max_threads(); #else nThreads = 1; #endif @@ -3197,7 +3197,7 @@ t1_decode(bwc_field *const field, bwc_tile *const tile, bwc_parameter *const par ! compression run. ! \*--------------------------------------------------------*/ #if defined (_OPENMP) - nThreads = control->nThreads; + nThreads = omp_get_max_threads(); #else nThreads = 1; #endif diff --git a/src/tools/bwccmdl.c b/src/tools/bwccmdl.c index bcaa591..b758c99 100644 --- a/src/tools/bwccmdl.c +++ b/src/tools/bwccmdl.c @@ -2893,7 +2893,7 @@ main(int argc, temp = retrieve_arg(args, "number_of_threads"); if((temp != NULL) && (temp->count == 1)) { - bwc_set_nThreads(field, (uint8_t)temp->num_opt[0]); + omp_set_num_threads((uint8_t)temp->num_opt[0]); } #endif @@ -3134,7 +3134,7 @@ main(int argc, temp = retrieve_arg(args, "number_of_threads"); if((temp != NULL) && (temp->count == 1)) { - bwc_set_nThreads(field, (uint8_t)temp->num_opt[0]); + omp_set_num_threads((uint8_t)temp->num_opt[0]); } #endif