Skip to content

Commit

Permalink
Further work to improve handling of string literals throughout the co…
Browse files Browse the repository at this point in the history
…de (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.
  • Loading branch information
myurkin committed Feb 8, 2012
1 parent c880a25 commit e6996e2
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 81 deletions.
4 changes: 2 additions & 2 deletions src/GenerateB.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
// defined and initialized in param.c
extern const int beam_Npars;
extern const double beam_pars[];
extern const char beam_fnameY[];
extern const char beam_fnameX[];
extern const char *beam_fnameY;
extern const char *beam_fnameX;
extern opt_index opt_beam;


Expand Down
4 changes: 2 additions & 2 deletions src/calculator.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Descr: all the initialization is done here before actually calculating internal fields; includes
* calculation of couple constants
*
* Copyright (C) 2006-2010 ADDA contributors
* Copyright (C) 2006-2010,2012 ADDA contributors
* This file is part of ADDA.
*
* ADDA is free software: you can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -39,7 +39,7 @@ extern const Parms_1D parms[2],parms_alpha;
extern const angle_set beta_int,gamma_int,theta_int,phi_int;
// defined and initialized in param.c
extern const int avg_inc_pol;
extern const char alldir_parms[],scat_grid_parms[];
extern const char *alldir_parms,*scat_grid_parms;
// defined and initialized in timing.c
extern TIME_TYPE Timing_Init;
extern size_t TotalEval;
Expand Down
11 changes: 6 additions & 5 deletions src/comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Descr: incorporates all parallelization related code, so most of it is directly involved in or
* closely related to interprocess communication
*
* Copyright (C) 2006-2011 ADDA contributors
* Copyright (C) 2006-2012 ADDA contributors
* This file is part of ADDA.
*
* ADDA is free software: you can redistribute it and/or modify it under the terms of the GNU
Expand All @@ -30,6 +30,7 @@
#include "function.h"
#include "parbas.h"
#include "cmplx.h"
#include "debug.h"

#ifdef ADDA_MPI
MPI_Datatype mpi_dcomplex,mpi_double3,mpi_dcomplex3; // combined datatypes
Expand Down Expand Up @@ -294,9 +295,6 @@ void Stop(const int code)
MPI_Abort(MPI_COMM_WORLD,code);
}
else { // regular termination
// wait for all processors
fflush(stdout);
Synchronize();
// clean MPI constructs and some memory
MPI_Type_free(&mpi_dcomplex);
MPI_Type_free(&mpi_double3);
Expand All @@ -305,6 +303,9 @@ void Stop(const int code)
Free_general(recvcounts);
Free_general(displs);
}
// wait for all processors
fflush(stdout);
Synchronize();
// finalize MPI communications
MPI_Finalize();
}
Expand Down Expand Up @@ -581,7 +582,7 @@ void ParSetup(void)
local_Nx=local_x1-local_x0;
boxXY=boxX*(size_t)boxY; // overflow check is covered by gridYZ above
local_Ndip=MultOverflow(boxXY,local_z1_coer-local_z0,ALL_POS,"local_Ndip");
printf("%i : %i %i %i %zu %zu \n",ringid,local_z0,local_z1_coer,local_z1,local_Ndip,local_Nx);
D("%i : %i %i %i %zu %zu \n",ringid,local_z0,local_z1_coer,local_z1,local_Ndip,local_Nx);
}

//============================================================
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/fft_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
using namespace std;

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

static void
getBlockConfigAndKernelString(cl_fft_plan *plan)
Expand Down
3 changes: 3 additions & 0 deletions src/iterative.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ extern doublecomplex * restrict vec1,* restrict vec2,* restrict vec3,* restrict
extern const double iter_eps;
extern const enum init_field InitField;
extern const bool recalc_resid;
extern const time_t chp_time;
extern const char *chp_dir;

// defined and initialized in timing.c
extern TIME_TYPE Timing_OneIter,Timing_OneIterComm,Timing_InitIter,Timing_InitIterComm,
Timing_IntFieldOneComm;
Expand Down
35 changes: 22 additions & 13 deletions src/make_particle.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ extern const enum sym sym_type;
extern const double lambda;
extern double sizeX,dpl,a_eq;
extern const int jagged;
extern const char shape_fname[];
extern char shapename[];
extern char save_geom_fname[];
extern const char *shape_fname;
extern const char *shapename;
extern const char *save_geom_fname;
extern const bool volcor,save_geom;
extern opt_index opt_sh;
extern const double gr_vf;
Expand Down Expand Up @@ -154,12 +154,16 @@ static void SaveGeometry(void)

// create save_geom_fname if not specified, by adding extension to the shapename
if (save_geom_fname[0]==0) {
if (sg_format==SF_TEXT || sg_format==SF_TEXT_EXT)
sprintf(save_geom_fname,"%s.geom",shapename);
else if (sg_format==SF_DDSCAT6 || sg_format==SF_DDSCAT7)
sprintf(save_geom_fname,"%s.dat",shapename);
const char *ext;
char *buf; // actual storage for save_geom_fname
// choose extension
if (sg_format==SF_TEXT || sg_format==SF_TEXT_EXT) ext="geom";
else if (sg_format==SF_DDSCAT6 || sg_format==SF_DDSCAT7) ext="dat";
else LogError(ONE_POS,"Unknown format for saved geometry file (%d)",sg_format);
MALLOC_VECTOR(buf,char,strlen(shapename)+strlen(ext)+2,ALL);
sprintf(buf,"%s.%s",shapename,ext);
save_geom_fname=buf;
}

// automatically change format if needed
if (sg_format==SF_TEXT && Nmat>1) sg_format=SF_TEXT_EXT;
// choose filename
Expand All @@ -179,16 +183,18 @@ static void SaveGeometry(void)
"#box size: %dx%dx%d\n",shapename,boxX,boxY,boxZ);
if (sg_format==SF_TEXT_EXT) fprintf(geom,"Nmat=%d\n",Nmat);
}
else if (sg_format==SF_DDSCAT6 || sg_format==SF_DDSCAT7)
else if (sg_format==SF_DDSCAT6 || sg_format==SF_DDSCAT7) {
fprintf(geom,"shape: '%s'; box size: %dx%dx%d; generated by ADDA v."ADDA_VERSION"\n"
"%zu = NAT\n"
"1 0 0 = A_1 vector\n"
"0 1 0 = A_2 vector\n"
"1 1 1 = lattice spacings (d_x,d_y,d_z)/d\n"
"JA IX IY IZ ICOMP(x,y,z)\n",shapename,boxX,boxY,boxZ,nvoid_Ndip);
"1 1 1 = lattice spacings (d_x,d_y,d_z)/d\n",
shapename,boxX,boxY,boxZ,nvoid_Ndip);
if (sg_format==SF_DDSCAT7) fprintf(geom,
"%g %g %g = coordinates (x0,y0,z0)/d of the zero dipole (IX=IY=IZ=0)\n",
(1-boxX)/2.0,(1-boxY)/2.0,(1-boxZ)/2.0);
fprintf(geom,"JA IX IY IZ ICOMP(x,y,z)\n");
}
#ifdef PARALLEL
} // end of if
#endif
Expand Down Expand Up @@ -397,7 +403,6 @@ static void InitDipFile(const char * restrict fname,int *bX,int *bY,int *bZ,int
*/
fseek(dipfile,0,SEEK_SET);
SkipNLines(dipfile,skiplines);

}

//===========================================================
Expand Down Expand Up @@ -1769,7 +1774,11 @@ void InitShape(void)
PrintError("Specified domain number to be granulated (%d) is larger than total number "
"of domains (%d) for the given shape (%s)",gr_mat+1,Nmat_need,shapename);
else Nmat_need++;
strcat(shapename,"_gran");
// update shapename; use new storage
char *buf;
MALLOC_VECTOR(buf,char,strlen(shapename)+6,ALL);
sprintf(buf,"%s_gran",shapename);
shapename=buf;
}
// check if enough refractive indices or extra
if (Nmat<Nmat_need) {
Expand Down
Loading

0 comments on commit e6996e2

Please sign in to comment.