ECC-604: Pass file to test. Fix memory leaks

This commit is contained in:
Shahram Najm 2018-05-01 14:24:42 +01:00
parent 91efbc51b9
commit 238924e427
2 changed files with 39 additions and 34 deletions

View File

@ -7,43 +7,35 @@
#include "grib_api.h"
#define NUM_THREADS 8
#define FILES_PER_ITERATION 300
#define TEMPLATE "../../share/eccodes/samples/gg_sfc_grib2.tmpl"
#define FILES_PER_ITERATION 200
static char* INPUT_FILE = NULL;
static int encode_file(char *template_file, char *output_file)
{
FILE *in = NULL;
FILE *out = NULL;
FILE *in, *out;
grib_handle *source_handle = NULL;
const void *buffer = NULL;
size_t size = 0;
int err = 0;
double *values;
in = fopen(template_file,"r"); assert(in);
out = fopen(output_file,"w"); assert(out);
/* loop over the messages in the source GRIB and clone them */
while ((source_handle = grib_handle_new_from_file(0, in, &err))!=NULL)
{
grib_handle *clone_handle = grib_handle_clone(source_handle);
if (clone_handle == NULL) {
perror("ERROR: could not clone field");
return 1;
}
//GRIB_CHECK(grib_set_long(clone_handle, "centre", 250),0);
size_t values_len= 0;
GRIB_CHECK(grib_get_size(clone_handle, "values", &values_len),0);
while ((source_handle = grib_handle_new_from_file(0, in, &err))!=NULL) {
int i;
double *values = NULL;
values = (double*)malloc(values_len*sizeof(double));
long count;
double d,e;
size_t values_len= 0;
grib_handle *clone_handle = grib_handle_clone(source_handle);
assert(clone_handle);
/*GRIB_CHECK(grib_set_long(clone_handle, "centre", 250),0);*/
GRIB_CHECK(grib_get_size(clone_handle, "values", &values_len),0);
values = (double*)malloc(values_len*sizeof(double));
d=10e-8;
e=d;
count=1;
@ -67,6 +59,7 @@ static int encode_file(char *template_file, char *output_file)
}
grib_handle_delete(clone_handle);
grib_handle_delete(source_handle);
free(values);
}
fclose(out);
@ -89,8 +82,14 @@ int main(int argc, char **argv)
{
int i;
int thread_counter = 0;
int parallel = !(argc>1 && strcmp(argv[1],"seq")==0);
int parallel = 1;
if (argc<2) {
return 1;
}
INPUT_FILE= argv[1];
if (argc>2 && strcmp(argv[2],"seq")==0) {
parallel = 0;
}
if (parallel) {
printf("Running parallel in %d threads.\n", NUM_THREADS);
} else {
@ -101,7 +100,6 @@ int main(int argc, char **argv)
/* We have to create M * N worker threads */
for (i = 0; i < NUM_THREADS; i++) {
struct v *data = (struct v *) malloc(sizeof(struct v));
data->number = i;
data->data = NULL;
@ -116,10 +114,8 @@ int main(int argc, char **argv)
}
}
/* Waiting for threads to complete */
if (parallel) {
for (i = 0; i < NUM_THREADS; i++)
{
for (i = 0; i < NUM_THREADS; i++) {
pthread_join(workers[i], NULL);
}
}
@ -142,7 +138,7 @@ void do_stuff(void *ptr)
for (int i=0; i<FILES_PER_ITERATION;i++) {
sprintf(output_file,"output/output_file_%d-%d.grib",data->number,i);
encode_file(TEMPLATE,output_file);
encode_file(INPUT_FILE,output_file);
}
time_t ltime;
@ -151,8 +147,8 @@ void do_stuff(void *ptr)
ltime = time(NULL);
localtime_r(&ltime, &result);
strftime(stime, 32, "%H:%M:%S", &result); // Try to get milliseconds here too
// asctime_r(&result, stime);
strftime(stime, 32, "%H:%M:%S", &result); /* Try to get milliseconds here too*/
/* asctime_r(&result, stime); */
printf("%s: Worker %d finished.\n", stime,data->number);
}

View File

@ -19,8 +19,17 @@ cd $temp_dir
OUTPUT=output
mkdir -p $OUTPUT
time ${test_dir}/grib_ecc-604
input=$ECCODES_SAMPLES_PATH/gg_sfc_grib2.tmpl
time ${test_dir}/grib_ecc-604 $input
# Run with forge
# -----------------
# module swap forge/18.0.1
# map ${test_dir}/grib_ecc-604 $input &
#
# Validate results
# -----------------
#num=0
#for ofile in $OUTPUT/output_file_*grib; do
# ${tools_dir}/grib_compare -H $ECCODES_SAMPLES_PATH/gg_sfc_grib2.tmpl $ofile