1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
/*
COPYRIGHT
The following is a notice of limited availability of the code, and disclaimer
which must be included in the prologue of the code and in all source listings
of the code.
(C) COPYRIGHT 2008 University of Chicago
Permission is hereby granted to use, reproduce, prepare derivative works, and
to redistribute to others. This software was authored by:
D. Levine
Mathematics and Computer Science Division
Argonne National Laboratory Group
with programming assistance of participants in Argonne National
Laboratory's SERS program.
GOVERNMENT LICENSE
Portions of this material resulted from work developed under a
U.S. Government Contract and are subject to the following license: the
Government is granted for itself and others acting on its behalf a paid-up,
nonexclusive, irrevocable worldwide license in this computer software to
reproduce, prepare derivative works, and perform publicly and display
publicly.
DISCLAIMER
This computer code material was prepared, in part, as an account of work
sponsored by an agency of the United States Government. Neither the United
States, nor the University of Chicago, nor any of their employees, makes any
warranty express or implied, or assumes any legal liability or responsibility
for the accuracy, completeness, or usefulness of any information, apparatus,
product, or process disclosed, or represents that its use would not infringe
privately owned rights.
*/
/*****************************************************************************
* FILE: system.c: This file contains systme routines such as errors and
* exits
*
* Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle,
* Brian P. Walenz
*****************************************************************************/
#include "pgapack.h"
char PGAProgram[100]; /* Holds argv[0] for PGAUsage() call */
/*U****************************************************************************
PGAError - reports error messages. Prints out the message supplied, and
the value of a piece of data. Terminates if PGA_FATAL.
Category: System
Inputs:
ctx - context variable
msg - the error message to print
level - PGA_WARNING or PGA_FATAL to indicate the error's severity
datatype - the data type of the following argument
data - the address of the data to be written out, cast as a void
pointer
Outputs:
None
Example:
PGAContext *ctx;
int val;
:
PGAError(ctx, "Some Non Fatal Error: val = ", PGA_WARNING, PGA_INT,
(void *) &val);
:
PGAError(ctx, "A Fatal Error!", PGA_FATAL, PGA_VOID, NULL);
****************************************************************************U*/
void PGAError( PGAContext *ctx, char *msg,
int level, int datatype, void *data )
{
PGADebugEntered("PGAError");
switch (datatype) {
case PGA_INT:
fprintf(stderr, "%s %d\n", msg, *(int *) data);
break;
case PGA_DOUBLE:
fprintf(stderr, "%s %f\n", msg, *(double *) data);
break;
case PGA_CHAR:
fprintf(stderr, "%s %s\n", msg, (char *) data);
break;
case PGA_VOID:
fprintf(stderr, "%s\n", msg);
break;
}
if ( level == PGA_FATAL ) {
fprintf(stderr, "PGAError: Fatal\n");
PGADestroy(ctx);
exit(-1);
}
PGADebugExited("PGAError");
}
/*U****************************************************************************
PGADestroy - deallocate memory for this instance of PGAPack, if this context
initialized MPI, finalize MPI as well.
Category: Generation
Inputs:
ctx - context variable
Outputs:
None
Example:
PGAContext *ctx;
:
PGADestroy(ctx);
****************************************************************************U*/
void PGADestroy (PGAContext *ctx)
{
int i;
PGADebugEntered("PGADestroy");
/* These are allocated by PGASetUp. Free then only if PGASetUp
* was called.
*/
if (ctx->sys.SetUpCalled == PGA_TRUE) {
/* Free the population...fly little birdies! You're FREE!!! */
for ( i = 0; i < ctx->ga.PopSize + 2; i++ ) {
free ( ctx->ga.oldpop[i].chrom );
free ( ctx->ga.newpop[i].chrom );
}
free ( ctx->ga.oldpop );
free ( ctx->ga.newpop );
/* Free the scratch space. */
free ( ctx->scratch.intscratch );
free ( ctx->scratch.dblscratch );
free ( ctx->ga.selected );
free ( ctx->ga.sorted );
}
/* These are allocated by PGACreate */
if (ctx->ga.datatype == PGA_DATATYPE_REAL)
{
free ( ctx->init.RealMax );
free ( ctx->init.RealMin );
}
else if (ctx->ga.datatype == PGA_DATATYPE_INTEGER)
{
free ( ctx->init.IntegerMax );
free ( ctx->init.IntegerMin );
}
/* We want to finalize MPI only if it was not started for us (as
* fortran would do) AND it is actually running. It would not be
* running if, for example, -pgahelp is specified on the command
* line.
*/
MPI_Initialized(&i);
if ((ctx->par.MPIAlreadyInit == PGA_FALSE) && i)
MPI_Finalize();
/* We really should perform a PGADebugPrint here, but we can't;
* we've already deallocated most of the stuff we need!!
*/
free ( ctx );
}
/*U***************************************************************************
PGAGetMaxMachineIntValue - returns the largest integer of the current
machine
Category: System
Inputs:
ctx - context variable
Outputs:
The largest integer of the given machine
Example:
PGAContext *ctx;
int intmax;
:
intmax = PGAGetMaxMachineIntValue(ctx);
***************************************************************************U*/
int PGAGetMaxMachineIntValue (PGAContext *ctx)
{
PGADebugEntered("PGAGetMaxMachineIntValue");
PGADebugExited("PGAGetMaxMachineIntValue");
return(ctx->sys.PGAMaxInt);
}
/*U***************************************************************************
PGAGetMaxMachineIntValue - returns the smallest integer of the current
machine
Category: System
Inputs:
ctx - context variable
Outputs:
The smallest integer of the given machine
Example:
PGAContext *ctx;
int intmin;
:
intmin = PGAGetMinMachineIntValue(ctx);
***************************************************************************U*/
int PGAGetMinMachineIntValue (PGAContext *ctx)
{
PGADebugEntered("PGAGetMinMachineIntValue");
PGADebugExited("PGAGetMinMachineIntValue");
return(ctx->sys.PGAMinInt);
}
/*U***************************************************************************
PGAGetMaxMachineDoubleValue - returns the largest double of the current
machine
Category: System
Inputs:
ctx - context variable
Outputs:
The largest double of the given machine
Example:
PGAContext *ctx;
double big;
:
big = PGAGetMaxMachineDoubleValue(ctx);
***************************************************************************U*/
double PGAGetMaxMachineDoubleValue (PGAContext *ctx)
{
PGADebugEntered("PGAGetMaxMachineDoubleValue");
PGADebugExited("PGAGetMaxMachineDoubleValue");
return(ctx->sys.PGAMaxDouble);
}
/*U***************************************************************************
PGAGetMaxMachineDoubleValue - returns the smallest double of the current
machine
Category: System
Inputs:
ctx - context variable
Outputs:
The smallest double of the given machine
Example:
PGAContext *ctx;
double small;
:
small = PGAGetMinMachineDoubleValue(ctx);
***************************************************************************U*/
double PGAGetMinMachineDoubleValue (PGAContext *ctx)
{
PGADebugEntered("PGAGetMinMachineDoubleValue");
PGADebugExited("PGAGetMinMachineDoubleValue");
return(ctx->sys.PGAMinDouble);
}
/*U****************************************************************************
PGAUsage - print list of available parameters and quit
Inputs:
ctx - context variable
Outputs:
list of available parametersNone
Example:
PGAContext ctx;
:
PGAUsage(ctx);
****************************************************************************U*/
void PGAUsage( PGAContext *ctx )
{
/* Print the usage info out if MPI isn't running (thus, only one process
* is probably running), or if we actually are the master.
*/
if (!ctx->par.MPIAlreadyInit || (PGAGetRank(ctx, MPI_COMM_WORLD) == 0)) {
PGAPrintVersionNumber( ctx );
printf("PGAPack usage: %s [pga options]\n", PGAProgram);
printf("Valid PGAPack options:\n");
printf("\t-pgahelp \tget this message\n");
printf("\t-pgahelp debug \tlist of debug options\n");
printf("\t-pgadbg <option> \tset debug option\n");
printf("\t-pgadebug <option>\tset debug option\n");
printf("\t-pgaversion \tprint current PGAPack version number\n");
printf("\n");
}
PGADestroy(ctx);
exit(-1);
}
/*U****************************************************************************
PGAPrintVersionNumber - print PGAPack version number
Inputs:
ctx - context variable
Outputs:
PGAPack version number
Example:
PGAContext ctx;
:
PGAPrintVersionNumber(ctx);
****************************************************************************U*/
void PGAPrintVersionNumber( PGAContext *ctx )
{
if (!ctx->par.MPIAlreadyInit || (PGAGetRank(ctx, MPI_COMM_WORLD) == 0)) {
#ifdef FAKE_MPI
#define PRINT1 "Sequential"
#else
#define PRINT1 "Parallel"
#endif
printf("\nPGAPack version 1.0: (%s, %s)\n\n",
(OPTIMIZE) ? "Optimized" : "Debug",
PRINT1 );
}
}
|