Skip to content

Commit e6996e2

Browse files
committed
Further work to improve handling of string literals throughout the code (continuation of r 1105). A few string functions in param.c were changed accordingly. Filenames, etc. now do not require additional storage but just point to respective parts of 'argv'.
Automatic directory name was slightly changed, e.g., from '...g16m1_5[id...]' to '...g16_m1.5[_id...]'. Line in the beginning of stdout with a lot of "meaningless" numbers was removed (it was especially annoying in MPI mode). Now it is only produced in FULLDEBUG. Instead, box dimensions were added to stdout. Fixed minor bug in saving DDSCAT 7 format, introduced by original implementation of r1100. Minor changes in Stop() (comm.c) in parallel mode.
1 parent c880a25 commit e6996e2

File tree

9 files changed

+95
-81
lines changed

9 files changed

+95
-81
lines changed

src/GenerateB.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
// defined and initialized in param.c
4444
extern const int beam_Npars;
4545
extern const double beam_pars[];
46-
extern const char beam_fnameY[];
47-
extern const char beam_fnameX[];
46+
extern const char *beam_fnameY;
47+
extern const char *beam_fnameX;
4848
extern opt_index opt_beam;
4949

5050

src/calculator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Descr: all the initialization is done here before actually calculating internal fields; includes
44
* calculation of couple constants
55
*
6-
* Copyright (C) 2006-2010 ADDA contributors
6+
* Copyright (C) 2006-2010,2012 ADDA contributors
77
* This file is part of ADDA.
88
*
99
* ADDA is free software: you can redistribute it and/or modify it under the terms of the GNU
@@ -39,7 +39,7 @@ extern const Parms_1D parms[2],parms_alpha;
3939
extern const angle_set beta_int,gamma_int,theta_int,phi_int;
4040
// defined and initialized in param.c
4141
extern const int avg_inc_pol;
42-
extern const char alldir_parms[],scat_grid_parms[];
42+
extern const char *alldir_parms,*scat_grid_parms;
4343
// defined and initialized in timing.c
4444
extern TIME_TYPE Timing_Init;
4545
extern size_t TotalEval;

src/comm.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Descr: incorporates all parallelization related code, so most of it is directly involved in or
44
* closely related to interprocess communication
55
*
6-
* Copyright (C) 2006-2011 ADDA contributors
6+
* Copyright (C) 2006-2012 ADDA contributors
77
* This file is part of ADDA.
88
*
99
* ADDA is free software: you can redistribute it and/or modify it under the terms of the GNU
@@ -30,6 +30,7 @@
3030
#include "function.h"
3131
#include "parbas.h"
3232
#include "cmplx.h"
33+
#include "debug.h"
3334

3435
#ifdef ADDA_MPI
3536
MPI_Datatype mpi_dcomplex,mpi_double3,mpi_dcomplex3; // combined datatypes
@@ -294,9 +295,6 @@ void Stop(const int code)
294295
MPI_Abort(MPI_COMM_WORLD,code);
295296
}
296297
else { // regular termination
297-
// wait for all processors
298-
fflush(stdout);
299-
Synchronize();
300298
// clean MPI constructs and some memory
301299
MPI_Type_free(&mpi_dcomplex);
302300
MPI_Type_free(&mpi_double3);
@@ -305,6 +303,9 @@ void Stop(const int code)
305303
Free_general(recvcounts);
306304
Free_general(displs);
307305
}
306+
// wait for all processors
307+
fflush(stdout);
308+
Synchronize();
308309
// finalize MPI communications
309310
MPI_Finalize();
310311
}
@@ -581,7 +582,7 @@ void ParSetup(void)
581582
local_Nx=local_x1-local_x0;
582583
boxXY=boxX*(size_t)boxY; // overflow check is covered by gridYZ above
583584
local_Ndip=MultOverflow(boxXY,local_z1_coer-local_z0,ALL_POS,"local_Ndip");
584-
printf("%i : %i %i %i %zu %zu \n",ringid,local_z0,local_z1_coer,local_z1,local_Ndip,local_Nx);
585+
D("%i : %i %i %i %zu %zu \n",ringid,local_z0,local_z1_coer,local_z1,local_Ndip,local_Nx);
585586
}
586587

587588
//============================================================

src/cpp/fft_setup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
using namespace std;
7575

7676
extern void getKernelWorkDimensions(cl_fft_plan *plan, cl_fft_kernel_info *kernelInfo, cl_int *batchSize, size_t *gWorkItems, size_t *lWorkItems);
77-
extern const char coptions[];
77+
extern const char *coptions;
7878

7979
static void
8080
getBlockConfigAndKernelString(cl_fft_plan *plan)

src/iterative.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ extern doublecomplex * restrict vec1,* restrict vec2,* restrict vec3,* restrict
5050
extern const double iter_eps;
5151
extern const enum init_field InitField;
5252
extern const bool recalc_resid;
53+
extern const time_t chp_time;
54+
extern const char *chp_dir;
55+
5356
// defined and initialized in timing.c
5457
extern TIME_TYPE Timing_OneIter,Timing_OneIterComm,Timing_InitIter,Timing_InitIterComm,
5558
Timing_IntFieldOneComm;

src/make_particle.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ extern const enum sym sym_type;
4747
extern const double lambda;
4848
extern double sizeX,dpl,a_eq;
4949
extern const int jagged;
50-
extern const char shape_fname[];
51-
extern char shapename[];
52-
extern char save_geom_fname[];
50+
extern const char *shape_fname;
51+
extern const char *shapename;
52+
extern const char *save_geom_fname;
5353
extern const bool volcor,save_geom;
5454
extern opt_index opt_sh;
5555
extern const double gr_vf;
@@ -154,12 +154,16 @@ static void SaveGeometry(void)
154154

155155
// create save_geom_fname if not specified, by adding extension to the shapename
156156
if (save_geom_fname[0]==0) {
157-
if (sg_format==SF_TEXT || sg_format==SF_TEXT_EXT)
158-
sprintf(save_geom_fname,"%s.geom",shapename);
159-
else if (sg_format==SF_DDSCAT6 || sg_format==SF_DDSCAT7)
160-
sprintf(save_geom_fname,"%s.dat",shapename);
157+
const char *ext;
158+
char *buf; // actual storage for save_geom_fname
159+
// choose extension
160+
if (sg_format==SF_TEXT || sg_format==SF_TEXT_EXT) ext="geom";
161+
else if (sg_format==SF_DDSCAT6 || sg_format==SF_DDSCAT7) ext="dat";
162+
else LogError(ONE_POS,"Unknown format for saved geometry file (%d)",sg_format);
163+
MALLOC_VECTOR(buf,char,strlen(shapename)+strlen(ext)+2,ALL);
164+
sprintf(buf,"%s.%s",shapename,ext);
165+
save_geom_fname=buf;
161166
}
162-
163167
// automatically change format if needed
164168
if (sg_format==SF_TEXT && Nmat>1) sg_format=SF_TEXT_EXT;
165169
// choose filename
@@ -179,16 +183,18 @@ static void SaveGeometry(void)
179183
"#box size: %dx%dx%d\n",shapename,boxX,boxY,boxZ);
180184
if (sg_format==SF_TEXT_EXT) fprintf(geom,"Nmat=%d\n",Nmat);
181185
}
182-
else if (sg_format==SF_DDSCAT6 || sg_format==SF_DDSCAT7)
186+
else if (sg_format==SF_DDSCAT6 || sg_format==SF_DDSCAT7) {
183187
fprintf(geom,"shape: '%s'; box size: %dx%dx%d; generated by ADDA v."ADDA_VERSION"\n"
184188
"%zu = NAT\n"
185189
"1 0 0 = A_1 vector\n"
186190
"0 1 0 = A_2 vector\n"
187-
"1 1 1 = lattice spacings (d_x,d_y,d_z)/d\n"
188-
"JA IX IY IZ ICOMP(x,y,z)\n",shapename,boxX,boxY,boxZ,nvoid_Ndip);
191+
"1 1 1 = lattice spacings (d_x,d_y,d_z)/d\n",
192+
shapename,boxX,boxY,boxZ,nvoid_Ndip);
189193
if (sg_format==SF_DDSCAT7) fprintf(geom,
190194
"%g %g %g = coordinates (x0,y0,z0)/d of the zero dipole (IX=IY=IZ=0)\n",
191195
(1-boxX)/2.0,(1-boxY)/2.0,(1-boxZ)/2.0);
196+
fprintf(geom,"JA IX IY IZ ICOMP(x,y,z)\n");
197+
}
192198
#ifdef PARALLEL
193199
} // end of if
194200
#endif
@@ -397,7 +403,6 @@ static void InitDipFile(const char * restrict fname,int *bX,int *bY,int *bZ,int
397403
*/
398404
fseek(dipfile,0,SEEK_SET);
399405
SkipNLines(dipfile,skiplines);
400-
401406
}
402407

403408
//===========================================================
@@ -1769,7 +1774,11 @@ void InitShape(void)
17691774
PrintError("Specified domain number to be granulated (%d) is larger than total number "
17701775
"of domains (%d) for the given shape (%s)",gr_mat+1,Nmat_need,shapename);
17711776
else Nmat_need++;
1772-
strcat(shapename,"_gran");
1777+
// update shapename; use new storage
1778+
char *buf;
1779+
MALLOC_VECTOR(buf,char,strlen(shapename)+6,ALL);
1780+
sprintf(buf,"%s_gran",shapename);
1781+
shapename=buf;
17731782
}
17741783
// check if enough refractive indices or extra
17751784
if (Nmat<Nmat_need) {

0 commit comments

Comments
 (0)