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

This commit is contained in:
Patrick Vogler 2024-02-15 11:55:03 +01:00
parent e6abc9fd81
commit e9617107aa
Signed by: Patrick Vogler
GPG key ID: 5536B08CE82E8509
9 changed files with 11 additions and 135 deletions

View file

@ -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) !
! -------------- !

View file

@ -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;
/*----------------------------------------------------------------------------------------------------------*\

View file

@ -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

View file

@ -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, &

View file

@ -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

View file

@ -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

View file

@ -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. !

View file

@ -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

View file

@ -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