From 3d6794f4d8bfdf0f0a38b704a1e2a2c17026e824 Mon Sep 17 00:00:00 2001 From: Magnus Lundborg Date: Tue, 28 May 2013 16:04:15 +0200 Subject: Allocate enough memory in Ptngc_pack_array_xtc3 When simulating with very few particles too little memory was allocated. Add a minimum value to allocate. Removed earlier debugging outputs. diff --git a/src/compression/tng_compress.c b/src/compression/tng_compress.c index cccab04..31818ee 100644 --- a/src/compression/tng_compress.c +++ b/src/compression/tng_compress.c @@ -63,16 +63,6 @@ static int verify_input_data_float(float *x, int natoms, int nframes, float prec #if 1 for (iframe=0; iframe=MAX_FVAL) printf("ERROR. Too large value: %d %d %d: %g %g %g\n",iframe,i,j,x[iframe*natoms*3+i*3+j],precision,x[iframe*natoms*3+i*3+j]/precision/MAX_FVAL); @@ -116,7 +106,7 @@ static void quant_inter_differences(int *quant, int natoms, int nframes, for (iframe=1; iframe=2) { current_coding=TNG_COMPRESS_ALGO_POS_XTC3; @@ -931,7 +921,7 @@ static void determine_best_vel_initial_coding(int *quant, int natoms, int speed, best_code_size=current_code_size; } Ptngc_coder_deinit(coder); - + /* Determine best parameter for triplet one-to-one. */ current_coding=TNG_COMPRESS_ALGO_VEL_TRIPLET_ONETOONE; coder=Ptngc_coder_init(); @@ -1020,7 +1010,7 @@ static void determine_best_vel_coding(int *quant, int *quant_inter, int natoms, best_coding=current_coding; best_code_size=current_code_size; best_coding_parameter=current_coding_parameter; - + /* Test triplet interframe */ current_coding=TNG_COMPRESS_ALGO_VEL_TRIPLET_INTER; current_code_size=natoms*3*(nframes-1); @@ -1033,7 +1023,7 @@ static void determine_best_vel_coding(int *quant, int *quant_inter, int natoms, { best_coding=current_coding; best_code_size=current_code_size; - best_coding_parameter=current_coding_parameter; + best_coding_parameter=current_coding_parameter; } } Ptngc_coder_deinit(coder); @@ -1050,11 +1040,11 @@ static void determine_best_vel_coding(int *quant, int *quant_inter, int natoms, { best_coding=current_coding; best_code_size=current_code_size; - best_coding_parameter=current_coding_parameter; + best_coding_parameter=current_coding_parameter; } } Ptngc_coder_deinit(coder); - + /* Test stopbit interframe */ current_coding=TNG_COMPRESS_ALGO_VEL_STOPBIT_INTER; current_code_size=natoms*3*(nframes-1); @@ -1067,11 +1057,11 @@ static void determine_best_vel_coding(int *quant, int *quant_inter, int natoms, { best_coding=current_coding; best_code_size=current_code_size; - best_coding_parameter=current_coding_parameter; - } + best_coding_parameter=current_coding_parameter; + } } Ptngc_coder_deinit(coder); - + if (speed>=4) { /* Test BWLZH inter */ @@ -1086,7 +1076,7 @@ static void determine_best_vel_coding(int *quant, int *quant_inter, int natoms, { best_coding=current_coding; best_code_size=current_code_size; - best_coding_parameter=current_coding_parameter; + best_coding_parameter=current_coding_parameter; } /* Test BWLZH one-to-one */ @@ -1101,7 +1091,7 @@ static void determine_best_vel_coding(int *quant, int *quant_inter, int natoms, { best_coding=current_coding; best_code_size=current_code_size; - best_coding_parameter=current_coding_parameter; + best_coding_parameter=current_coding_parameter; } } *coding=best_coding; @@ -1201,7 +1191,7 @@ char DECLSPECDLLEXPORT *tng_compress_pos_int(int *pos, int natoms, int nframes, { coding_parameter=-1; determine_best_pos_coding(quant,quant_inter,quant_intra,natoms,nframes,speed,prec_hi,prec_lo, - &coding,&coding_parameter); + &coding,&coding_parameter); } else if (coding_parameter==-1) { @@ -1228,7 +1218,7 @@ char DECLSPECDLLEXPORT *tng_compress_pos_int(int *pos, int natoms, int nframes, } char DECLSPECDLLEXPORT *tng_compress_pos(double *pos, int natoms, int nframes, - double desired_precision, + double desired_precision, int speed,int *algo, int *nitems) { @@ -1246,7 +1236,7 @@ char DECLSPECDLLEXPORT *tng_compress_pos(double *pos, int natoms, int nframes, } char DECLSPECDLLEXPORT *tng_compress_pos_float(float *pos, int natoms, int nframes, - float desired_precision, + float desired_precision, int speed,int *algo, int *nitems) { @@ -1352,20 +1342,20 @@ char DECLSPECDLLEXPORT *tng_compress_vel_int(int *vel, int natoms, int nframes, determine_best_vel_initial_coding(quant,natoms,speed,prec_hi,prec_lo, &initial_coding,&initial_coding_parameter); } - + if (nframes==1) { coding=0; coding_parameter=0; } - + if (nframes>1) { if (coding==-1) { coding_parameter=-1; determine_best_vel_coding(quant,quant_inter,natoms,nframes,speed,prec_hi,prec_lo, - &coding,&coding_parameter); + &coding,&coding_parameter); } else if (coding_parameter==-1) { @@ -1562,7 +1552,7 @@ static int tng_compress_uncompress_pos_gen(char *data,double *posd,float *posf,i coder=Ptngc_coder_init(); rval=Ptngc_unpack_array(coder,(unsigned char*)data+bufloc,quant,natoms*3, initial_coding,initial_coding_parameter,natoms); - Ptngc_coder_deinit(coder); + Ptngc_coder_deinit(coder); if (rval) goto error; /* Skip past the actual data block. */ @@ -1711,7 +1701,7 @@ static int tng_compress_uncompress_vel_gen(char *data,double *veld,float *velf,i coder=Ptngc_coder_init(); rval=Ptngc_unpack_array(coder,(unsigned char*)data+bufloc,quant,natoms*3, initial_coding,initial_coding_parameter,natoms); - Ptngc_coder_deinit(coder); + Ptngc_coder_deinit(coder); if (rval) goto error; /* Skip past the actual data block. */ diff --git a/src/compression/xtc3.c b/src/compression/xtc3.c index 8c742a2..c26d7aa 100644 --- a/src/compression/xtc3.c +++ b/src/compression/xtc3.c @@ -10,9 +10,9 @@ * of the License, or (at your option) any later version. */ -/* This code is heavily influenced by +/* This code is heavily influenced by http://hpcv100.rc.rug.nl/xdrf.html - Based on coordinate compression (c) by Frans van Hoesel. + Based on coordinate compression (c) by Frans van Hoesel. and GROMACS xtc files (http://www.gromacs.org) (c) Copyright (c) Erik Lindahl, David van der Spoel */ @@ -101,9 +101,9 @@ static int unpositive_int(int val) struct xtc3_context { unsigned int *instructions; - int ninstr, ninstr_alloc; + int ninstr, ninstr_alloc; unsigned int *rle; - int nrle, nrle_alloc; + int nrle, nrle_alloc; unsigned int *large_direct; int nlargedir, nlargedir_alloc; unsigned int *large_intra_delta; @@ -117,17 +117,17 @@ struct xtc3_context int has_large_ints[MAX_LARGE_RLE*3]; /* Large cache. */ int has_large_type[MAX_LARGE_RLE]; /* What kind of type this large int is. */ - int current_large_type; + int current_large_type; }; static void init_xtc3_context(struct xtc3_context *xtc3_context) { xtc3_context->instructions=NULL; xtc3_context->ninstr=0; - xtc3_context->ninstr_alloc=0; + xtc3_context->ninstr_alloc=0; xtc3_context->rle=NULL; xtc3_context->nrle=0; - xtc3_context->nrle_alloc=0; + xtc3_context->nrle_alloc=0; xtc3_context->large_direct=NULL; xtc3_context->nlargedir=0; xtc3_context->nlargedir_alloc=0; @@ -208,7 +208,7 @@ static void insert_value_in_array(unsigned int **ptr, int *nele, int *nele_alloc allocate_enough_memory(ptr,nele,nele_alloc); #ifdef SHOWIT fprintf(stderr,"Inserting value %u into array %s @ %d\n",value,arrayname,(*nele)-1); -#endif +#endif (*ptr)[(*nele)-1]=value; } @@ -228,7 +228,7 @@ static void swapdecide(struct xtc3_context *xtc3_context, int *input,int *swapat */ #ifdef SHOWIT fprintf(stderr,"Trying Flip: %g %g\n",(double)swapped/normal, (double)normal/swapped); -#endif +#endif if (((swapped>(ibyte*8))&(0xFFU)); #ifdef SHOWIT fprintf(stderr,"%02x",(unsigned int)output[nwrittenout-1]); -#endif +#endif } #ifdef SHOWIT fprintf(stderr,"\n"); -#endif +#endif nvals=0; for (j=0; j>(ibyte*8))&(0xFFU)); - } + } } } *outlen=nwrittenout; @@ -750,7 +750,7 @@ static void base_decompress(unsigned char *input, int len, unsigned int *output) largeint[j]=0U; #ifdef SHOWIT fprintf(stderr,"Reading largeint: "); -#endif +#endif for (j=0; j=%g?\n",change,isum,(double)Ptngc_magic(small_index+change)*(double)Ptngc_magic(small_index+change)); -#endif +#endif if (isum>(double)Ptngc_magic(small_index+change)*(double)Ptngc_magic(small_index+change)) { #ifdef SHOWIT fprintf(stderr,"Rejected decrease %d of index due to length of vector: %g>=%g\n",change,isum,(double)Ptngc_magic(small_index+change)*(double)Ptngc_magic(small_index+change)); -#endif +#endif rejected=1; change++; } @@ -1308,7 +1311,7 @@ unsigned char *Ptngc_pack_array_xtc3(int *input, int *length, int natoms, int sp } #ifdef SHOWIT fprintf(stderr,"Current small index: %d Base=%d\n",small_index,Ptngc_magic(small_index)); -#endif +#endif } /* If we have a large previous integer we can combine it with a sequence of small ints. */ if (xtc3_context.has_large) @@ -1336,14 +1339,14 @@ unsigned char *Ptngc_pack_array_xtc3(int *input, int *length, int natoms, int sp } else { - + #ifdef SHOWIT fprintf(stderr,"Sequence of one large and small integers (good compression).\n"); #endif /* Flush all large atoms but one! */ if (xtc3_context.has_large>1) flush_large(&xtc3_context,xtc3_context.has_large-1); - + /* Here we must check if we should emit a large type change instruction. */ large_instruction_change(&xtc3_context,0); @@ -1352,7 +1355,7 @@ unsigned char *Ptngc_pack_array_xtc3(int *input, int *length, int natoms, int sp &xtc3_context.ninstr, &xtc3_context.ninstr_alloc, INSTR_DEFAULT,"instr"); - + write_three_large(&xtc3_context,0); xtc3_context.has_large=0; } @@ -1396,7 +1399,7 @@ unsigned char *Ptngc_pack_array_xtc3(int *input, int *length, int natoms, int sp fprintf(stderr,"Prevcoord in packing: %d %d %d\n", prevcoord[0],prevcoord[1],prevcoord[2]); #endif - + inpdata+=3*runlength; ntriplets_left-=runlength; #if 1 @@ -1408,13 +1411,13 @@ unsigned char *Ptngc_pack_array_xtc3(int *input, int *length, int natoms, int sp #ifdef SHOWIT fprintf(stderr,"Refused value: %d old is %d max is %d\n",new_small_index,small_index,max_large_index); fflush(stderr); -#endif +#endif refused=1; } } #ifdef SHOWIT fprintf(stderr,"Number of triplets left is %d\n",ntriplets_left); -#endif +#endif } /* If we have large previous integers we must flush them now. */ @@ -1726,7 +1729,7 @@ static void unpack_one_large(struct xtc3_context *xtc3_context, fprintf(stderr,"Unpack one large: %d %d %d\n",prevcoord[0],prevcoord[1],prevcoord[2]); #endif } - + int Ptngc_unpack_array_xtc3(unsigned char *packed,int *output, int length, int natoms) { @@ -1812,7 +1815,7 @@ int Ptngc_unpack_array_xtc3(unsigned char *packed,int *output, int length, int n else decompress_base_block(&ptr,xtc3_context.nlargeinter,&xtc3_context.large_inter_delta); } - + xtc3_context.nsmallintra=(int)(((unsigned int)ptr[0]) | (((unsigned int)ptr[1])<<8) | (((unsigned int)ptr[2])<<16) | -- cgit v0.10.1