From 90c393a0c2f806f6b55cf914b04d8a7188740715 Mon Sep 17 00:00:00 2001 From: shahramn Date: Fri, 23 Aug 2024 13:44:35 +0100 Subject: [PATCH] Testing: Encoding in parallel from samples --- definitions/grib1/local/ecmf/3.table | 4 ++-- tests/grib_threads_ecc-604-encode.cc | 30 +++++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/definitions/grib1/local/ecmf/3.table b/definitions/grib1/local/ecmf/3.table index fb5b07081..8589b462e 100644 --- a/definitions/grib1/local/ecmf/3.table +++ b/definitions/grib1/local/ecmf/3.table @@ -42,12 +42,12 @@ 141 141 Layer between two isobaric surfaces (mixed precision) pressure of top, in kPa 1100hPa minus pressure of bottom, in hPa # 142-159 Reserved 160 dp Depth below sea level meters (2 octets) -# 161-199Reserved +# 161-199 Reserved 200 sfc Entire atmosphere considered as a single layer 0 (2 octets) 201 201 Entire ocean considered as a single layer 0 (2 octets) 202 al Abstract Single Level 203 al Abstract Multiple Level -# 202-209 Reserved +# 204-209 Reserved 210 pl Isobaric surface (Pa) (ECMWF extension) # 211-254 Reserved for local use 211 wv Ocean wave level (ECMWF extension) diff --git a/tests/grib_threads_ecc-604-encode.cc b/tests/grib_threads_ecc-604-encode.cc index 0f2e37560..33a767206 100644 --- a/tests/grib_threads_ecc-604-encode.cc +++ b/tests/grib_threads_ecc-604-encode.cc @@ -26,19 +26,24 @@ int opt_write = 0; /* If 1 write handle to file */ static int encode_values(grib_handle* h, char* output_file) { - double* values; - const size_t DIM = 1000; - size_t size = DIM * DIM; - size_t i = 0; - values = (double*)malloc(size * sizeof(double)); - for (i = 0; i < size; ++i) { + double* values = NULL; + long numberOfDataPoints = 0; + GRIB_CHECK(grib_get_long(h, "numberOfDataPoints", &numberOfDataPoints), 0); + size_t size = numberOfDataPoints; + + values = (double*)malloc(size * sizeof(double)); + for (size_t i = 0; i < size; ++i) { double v = i; - if (i % DIM == 0) v = 0; + if (i % size == 0) v = 0; values[i] = v; } GRIB_CHECK(grib_set_long(h, "bitsPerValue", 16), 0); GRIB_CHECK(grib_set_double_array(h, "values", values, size), 0); free(values); + if (opt_dump) { + FILE* devnull = fopen("/dev/null", "w"); + grib_dump_content(h, devnull, "wmo", 0, NULL); + } return GRIB_SUCCESS; } @@ -62,6 +67,7 @@ int main(int argc, char** argv) char* mode; if (argc < 5 || argc > 7) { fprintf(stderr, "Usage:\n\t%s [options] seq sample numRuns numIter\nOr\n\t%s [options] par sample numThreads numIter\n", prog, prog); + fprintf(stderr, "Options:\n\t-d: do a dump\n\t-c: clone\n"); return 1; } @@ -144,7 +150,12 @@ void do_encode(void* ptr) hs = grib_handle_new_from_samples(0, INPUT_FILE); for (i = 0; i < FILES_PER_ITERATION; i++) { - grib_handle* h = grib_handle_clone(hs); + grib_handle* h = NULL; + if (opt_clone) { + h = grib_handle_clone(hs); + } else { + h = hs; + } if (opt_write) { snprintf(output_file, 50, "output/output_file_%zu-%zu.grib", data->number, i); encode_values(h, output_file); @@ -152,7 +163,8 @@ void do_encode(void* ptr) else { encode_values(h, NULL); } - grib_handle_delete(h); + if (opt_clone) + grib_handle_delete(h); } ltime = time(NULL);