From 0825ad113429cf9fd46627ebb24799c211f7b680 Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Mon, 7 May 2012 22:19:12 -0400 Subject: [PATCH] Fixing more Clang warnings Change-Id: Ic2189579eaaa262d4907d912d59a3e78274bd4ed --- include/types/commrec.h | 2 +- src/contrib/random.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ src/gmxlib/bondfree.c | 2 ++ src/gmxlib/confio.c | 4 ++-- src/gmxlib/enxio.c | 2 +- src/gmxlib/futil.c | 5 +++++ src/gmxlib/gmx_random.c | 58 +------------------------------------------------ src/gmxlib/index.c | 4 +++- src/gmxlib/libxdrf.c | 2 +- src/gmxlib/main.c | 2 +- src/gmxlib/statutil.c | 3 ++- src/mdlib/pme.c | 5 +++-- 12 files changed, 79 insertions(+), 67 deletions(-) create mode 100644 src/contrib/random.c diff --git a/include/types/commrec.h b/include/types/commrec.h index 0c9d320b08..1b30788441 100644 --- a/include/types/commrec.h +++ b/include/types/commrec.h @@ -286,7 +286,7 @@ typedef struct { /* #define MASTERTHREAD(cr) ((cr)->threadid == 0) */ /* #define MASTER(cr) (MASTERNODE(cr) && MASTERTHREAD(cr)) */ #define MASTER(cr) MASTERNODE(cr) -#define SIMMASTER(cr) (MASTER(cr) && ((cr)->duty & DUTY_PP)) +#define SIMMASTER(cr) ((MASTER(cr) && ((cr)->duty & DUTY_PP)) || !PAR(cr)) #define NODEPAR(cr) ((cr)->nnodes > 1) /* #define THREADPAR(cr) ((cr)->nthreads > 1) */ /* #define PAR(cr) (NODEPAR(cr) || THREADPAR(cr)) */ diff --git a/src/contrib/random.c b/src/contrib/random.c new file mode 100644 index 0000000000..6514ba8bf5 --- /dev/null +++ b/src/contrib/random.c @@ -0,0 +1,57 @@ +/* + * Print a lookup table for Gaussian numbers with 4 entries on each + * line, formatted for inclusion in this file. Size is 2^bits. + */ + +void +print_gaussian_table(int bits) +{ + int n,nh,i,j; + double invn,fac,x,invgauss,det,dx; + real *table; + + n = 1 << bits; + table = (real *)malloc(n*sizeof(real)); + + /* Fill a table of size n such that random draws from it + * produce a Gaussian distribution. + * We integrate the Gaussian distribution G approximating: + * integral(x->x+dx) G(y) dy + * with: + * G(x) dx + G'(x) dx^2/2 = G(x) dx - G(x) x dx^2/2 + * Then we need to find dx such that the integral is 1/n. + * The last step uses dx = 1/x as the approximation is not accurate enough. + */ + invn = 1.0/n; + fac = sqrt(2*M_PI); + x = 0.5*fac*invn; + nh = n/2; + for(i=0; i 0) { + if (i < nh-1) { + invgauss = fac*exp(0.5*x*x); + /* det is larger than 0 for all x, except for the last */ + det = 1 - 2*invn*x*invgauss; + dx = (1 - sqrt(det))/x; + } else { + dx = 1/x; + } + x = x + dx; + } + table[nh-1-i] = -x; + table[nh+i] = x; + } + printf("static const real *\ngaussian_table[%d] = {\n",n); + for(i=0;i= 0) + if (bWrongPrecision) { *bWrongPrecision = FALSE; } diff --git a/src/gmxlib/futil.c b/src/gmxlib/futil.c index c5eefe531d..3834e36b35 100644 --- a/src/gmxlib/futil.c +++ b/src/gmxlib/futil.c @@ -482,6 +482,11 @@ FILE *ffopen(const char *file,const char *mode) gmx_bool bRead; int bs; + if (file == NULL) + { + return NULL; + } + if (mode[0]=='w') { make_backup(file); } diff --git a/src/gmxlib/gmx_random.c b/src/gmxlib/gmx_random.c index 0e56099806..e599cb4200 100644 --- a/src/gmxlib/gmx_random.c +++ b/src/gmxlib/gmx_random.c @@ -63,7 +63,7 @@ * have to generate new initialization data for the table in * gmx_random_gausstable.h * - * We have included the routine print_gaussian_table() in this file + * A routine print_gaussian_table() is in contrib/random.c * for convenience - use it if you need a different size of the table. */ #define GAUSS_TABLE 14 /* the size of the gauss table is 2^GAUSS_TABLE */ @@ -354,59 +354,3 @@ gmx_rng_gaussian_table(gmx_rng_t rng) } -/* - * Print a lookup table for Gaussian numbers with 4 entries on each - * line, formatted for inclusion in this file. Size is 2^bits. - */ -void -print_gaussian_table(int bits) -{ - int n,nh,i,j; - double invn,fac,x,invgauss,det,dx; - real *table; - - n = 1 << bits; - table = (real *)malloc(n*sizeof(real)); - - /* Fill a table of size n such that random draws from it - * produce a Gaussian distribution. - * We integrate the Gaussian distribution G approximating: - * integral(x->x+dx) G(y) dy - * with: - * G(x) dx + G'(x) dx^2/2 = G(x) dx - G(x) x dx^2/2 - * Then we need to find dx such that the integral is 1/n. - * The last step uses dx = 1/x as the approximation is not accurate enough. - */ - invn = 1.0/n; - fac = sqrt(2*M_PI); - x = 0.5*fac*invn; - nh = n/2; - for(i=0; i 0) { - if (i < nh-1) { - invgauss = fac*exp(0.5*x*x); - /* det is larger than 0 for all x, except for the last */ - det = 1 - 2*invn*x*invgauss; - dx = (1 - sqrt(det))/x; - } else { - dx = 1/x; - } - x = x + dx; - } - table[nh-1-i] = -x; - table[nh+i] = x; - } - printf("static const real *\ngaussian_table[%d] = {\n",n); - for(i=0;i #include +#include #include "sysstuff.h" #include "strdb.h" #include "futil.h" @@ -723,7 +724,7 @@ gmx_residuetype_get_name(gmx_residuetype_t rt, int index) void analyse(t_atoms *atoms,t_blocka *gb,char ***gn,gmx_bool bASK,gmx_bool bVerb) { - gmx_residuetype_t rt; + gmx_residuetype_t rt=NULL; char *resnm; atom_id *aid; const char ** restype; @@ -752,6 +753,7 @@ void analyse(t_atoms *atoms,t_blocka *gb,char ***gn,gmx_bool bASK,gmx_bool bVerb /* For every residue, get a pointer to the residue type name */ gmx_residuetype_init(&rt); + assert(rt); snew(restype,atoms->nres); ntypes = 0; diff --git a/src/gmxlib/libxdrf.c b/src/gmxlib/libxdrf.c index f279deb517..00b4a7efec 100644 --- a/src/gmxlib/libxdrf.c +++ b/src/gmxlib/libxdrf.c @@ -746,7 +746,7 @@ static void receiveints(int buf[], const int num_of_ints, int num_of_bits, int bytes[32]; int i, j, num_of_bytes, p, num; - bytes[1] = bytes[2] = bytes[3] = 0; + bytes[0] = bytes[1] = bytes[2] = bytes[3] = 0; num_of_bytes = 0; while (num_of_bits > 8) { bytes[num_of_bytes++] = receivebits(buf, 8); diff --git a/src/gmxlib/main.c b/src/gmxlib/main.c index b151c9f865..52c8da84eb 100644 --- a/src/gmxlib/main.c +++ b/src/gmxlib/main.c @@ -379,7 +379,7 @@ static void comm_args(const t_commrec *cr,int *argc,char ***argv) { int i,len; - if ((cr) && PAR(cr)) + if (PAR(cr)) gmx_bcast(sizeof(*argc),argc,cr); if (!MASTER(cr)) diff --git a/src/gmxlib/statutil.c b/src/gmxlib/statutil.c index 0144ba9696..2b005fdf66 100644 --- a/src/gmxlib/statutil.c +++ b/src/gmxlib/statutil.c @@ -268,7 +268,8 @@ static void set_default_time_unit(const char *time_list[], gmx_bool bCanTime) } } } - if (!bCanTime || select == NULL || strcmp(time_list[i], select) != 0) + if (!bCanTime || select == NULL || + time_list[i]==NULL || strcmp(time_list[i], select) != 0) { /* Set it to the default: ps */ i = 1; diff --git a/src/mdlib/pme.c b/src/mdlib/pme.c index 02cea6e459..ea26092ee8 100644 --- a/src/mdlib/pme.c +++ b/src/mdlib/pme.c @@ -3721,6 +3721,7 @@ static void spread_on_grid(gmx_pme_t pme, #endif nthread = pme->nthread; + assert(nthread>0); #ifdef PME_TIME_THREADS c1 = omp_cyc_start(); @@ -4040,8 +4041,8 @@ int gmx_pme_do(gmx_pme_t pme, real * fftgrid; t_complex * cfftgrid; int thread; - gmx_bool bCalcEnerVir = flags & GMX_PME_CALC_ENER_VIR; - gmx_bool bCalcF = flags & GMX_PME_CALC_F; + const gmx_bool bCalcEnerVir = flags & GMX_PME_CALC_ENER_VIR; + const gmx_bool bCalcF = flags & GMX_PME_CALC_F; assert(pme->nnodes > 0); assert(pme->nnodes == 1 || pme->ndecompdim > 0); -- 2.11.4.GIT