![]() |
kspaceFirstOrder3D-OMP 1.0
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
|
00001 00032 #include <stdio.h> 00033 #include <getopt.h> 00034 #include <string.h> 00035 #include <omp.h> 00036 00037 #include <Parameters/CommandLineParameters.h> 00038 00039 #include <Utils/ErrorMessages.h> 00040 //----------------------------------------------------------------------------// 00041 //---------------------------- Constants -------------------------------------// 00042 //----------------------------------------------------------------------------// 00043 00044 //----------------------------------------------------------------------------// 00045 //----------------------------- Public -------------------------------------// 00046 //----------------------------------------------------------------------------// 00047 00048 00049 00053 TCommandLineParameters::TCommandLineParameters() : 00054 InputFileName(""), OutputFileName (""), 00055 NumberOfThreads(omp_get_num_procs()), 00056 VerboseInterval(DefaultVerboseInterval), CompressionLevel (DefaultCompressionLevel), 00057 BenchmarkFlag (false), BenchmarkTimeStepsCount(0), 00058 PrintVersion (false), 00059 Store_p_raw(false), Store_p_rms(false), Store_p_max(false), Store_p_final(false), 00060 Store_u_raw(false), Store_u_rms(false), Store_u_max(false), Store_u_final(false), 00061 Store_I_avg(false), Store_I_max(false), 00062 StartTimeStep(0) 00063 { 00064 00065 }// end of TCommandLineParameters 00066 //------------------------------------------------------------------------------ 00067 00071 void TCommandLineParameters::PrintUsageAndExit(){ 00072 00073 00074 printf("---------------------------------- Usage ---------------------------------\n"); 00075 printf("Mandatory parameters:\n"); 00076 printf(" -i <input_file_name> : HDF5 input file\n"); 00077 printf(" -o <output_file_name> : HDF5 output file\n"); 00078 printf("\n"); 00079 printf("Optional parameters: \n"); 00080 printf(" -t <num_threads> : Number of CPU threads\n"); 00081 printf(" (default = %d)\n",omp_get_num_procs()); 00082 printf(" -r <interval_in_%%> : Progress print interval\n"); 00083 printf(" (default = %d%%)\n",DefaultVerboseInterval); 00084 printf(" -c <comp_level> : Output file compression level <0,9>\n"); 00085 printf(" (default = %d)\n",DefaultCompressionLevel ); 00086 printf(" --benchmark <steps> : Run a specified number of time steps\n"); 00087 printf("\n"); 00088 printf(" -h : Print help\n"); 00089 printf(" --help : Print help\n"); 00090 printf(" --version : Print version\n"); 00091 printf("\n"); 00092 printf("Output flags:\n"); 00093 printf(" -p : Store acoustic pressure \n"); 00094 printf(" (default if nothing else is on)\n"); 00095 printf(" (the same as --p_raw)\n"); 00096 printf(" --p_raw : Store raw time series of p (default)\n"); 00097 printf(" --p_rms : Store rms of p\n"); 00098 printf(" --p_max : Store max of p\n"); 00099 printf(" --p_final : Store final pressure field \n"); 00100 printf("\n"); 00101 printf(" -u : Store ux, uy, uz\n"); 00102 printf(" (the same as --u_raw)\n"); 00103 printf(" --u_raw : Store raw time series of ux, uy, uz\n"); 00104 printf(" --u_rms : Store rms of ux, uy, uz\n"); 00105 printf(" --u_max : Store max of ux, uy, uz\n"); 00106 printf(" --u_final : Store final acoustic velocity\n"); 00107 printf("\n"); 00108 printf(" -I : Store intensity\n"); 00109 printf(" (the same as --I_avg)\n"); 00110 printf(" --I_avg : Store avg of intensity\n"); 00111 printf(" --I_max : Store max of intensity\n"); 00112 printf("\n"); 00113 printf(" -s <timestep> : Time step when data collection begins\n"); 00114 printf(" (default = 1)\n"); 00115 printf("--------------------------------------------------------------------------\n"); 00116 printf("\n"); 00117 00118 00119 exit(EXIT_FAILURE); 00120 00121 }// end of PrintUsageAndExit 00122 //------------------------------------------------------------------------------ 00123 00127 void TCommandLineParameters::PrintSetup(){ 00128 00129 printf("List of enabled parameters:\n"); 00130 00131 printf(" Input file %s\n",InputFileName.c_str()); 00132 printf(" Output file %s\n",OutputFileName.c_str()); 00133 printf("\n"); 00134 printf(" Number of threads %d\n", NumberOfThreads); 00135 printf(" Verbose interval[%%] %d\n", VerboseInterval); 00136 printf(" Compression level %d\n", CompressionLevel); 00137 printf("\n"); 00138 printf(" Benchmark flag %d\n", BenchmarkFlag); 00139 printf(" Benchmark time steps %d\n", BenchmarkTimeStepsCount); 00140 printf("\n"); 00141 printf(" Store p_raw %d\n", Store_p_raw); 00142 printf(" Store p_rms %d\n", Store_p_rms); 00143 printf(" Store p_max %d\n", Store_p_max); 00144 printf(" Store p_final %d\n", Store_p_final); 00145 printf("\n"); 00146 printf(" Store u_raw %d\n", Store_u_raw); 00147 printf(" Store u_rms %d\n", Store_u_rms); 00148 printf(" Store u_max %d\n", Store_u_max); 00149 printf(" Store u_max %d\n", Store_u_final); 00150 printf("\n"); 00151 printf(" Store I_avg %d\n", Store_I_avg); 00152 printf(" Store I_max %d\n", Store_I_max); 00153 printf("\n"); 00154 printf(" Collection begins at %d\n", StartTimeStep+1); 00155 00156 00157 }// end of PrintSetup 00158 //------------------------------------------------------------------------------ 00159 00165 void TCommandLineParameters::ParseCommandLine(int argc, char** argv){ 00166 00167 char c; 00168 int longIndex; 00169 const char * shortOpts = "i:o:v:c:t:puIhs:"; 00170 00171 const struct option longOpts[] = { 00172 { "benchmark", required_argument , NULL, 0}, 00173 { "help", no_argument, NULL, 'h' }, 00174 { "version", no_argument, NULL, 0 }, 00175 00176 { "p_raw", no_argument, NULL, 'p' }, 00177 { "p_rms", no_argument, NULL, 0 }, 00178 { "p_max", no_argument, NULL, 0 }, 00179 { "p_final", no_argument, NULL, 0 }, 00180 00181 { "u_raw", no_argument, NULL, 'u' }, 00182 { "u_rms", no_argument, NULL, 0 }, 00183 { "u_max", no_argument, NULL, 0 }, 00184 { "u_final", no_argument, NULL, 0 }, 00185 00186 { "I_avg", no_argument, NULL, 'I' }, 00187 { "I_max", no_argument, NULL, 0 }, 00188 { NULL, no_argument, NULL, 0 } 00189 }; 00190 00191 00192 // Short parameters // 00193 while ((c = getopt_long (argc, argv, shortOpts, longOpts, &longIndex )) != -1){ 00194 switch (c){ 00195 00196 case 'i':{ 00197 InputFileName = optarg; 00198 break; 00199 } 00200 case 'o':{ 00201 OutputFileName = optarg; 00202 break; 00203 } 00204 00205 case 'v': { 00206 if ((optarg == NULL) || (atoi(optarg) <= 0)) { 00207 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoVerboseIntreval); 00208 PrintUsageAndExit(); 00209 }else { 00210 VerboseInterval = atoi(optarg); 00211 } 00212 00213 break; 00214 } 00215 00216 case 't':{ 00217 if ((optarg == NULL) || (atoi(optarg) <= 0)) { 00218 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoThreadNumbers); 00219 PrintUsageAndExit(); 00220 }else { 00221 NumberOfThreads = atoi(optarg); 00222 } 00223 00224 break; 00225 } 00226 00227 case 'c':{ 00228 if ((optarg == NULL) || (atoi(optarg) < 0) || atoi(optarg) > 9) { 00229 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoCompressionLevel); 00230 PrintUsageAndExit(); 00231 } else { 00232 CompressionLevel = atoi(optarg); 00233 } 00234 00235 break; 00236 } 00237 00238 case 'p':{ 00239 Store_p_raw = true; 00240 break; 00241 } 00242 00243 case 'u':{ 00244 Store_u_raw = true; 00245 break; 00246 } 00247 00248 case 'I':{ 00249 Store_I_avg = true; 00250 break; 00251 } 00252 00253 case 'h':{ 00254 00255 PrintUsageAndExit(); 00256 break; 00257 } 00258 00259 case 's':{ 00260 if ((optarg == NULL) || (atoi(optarg) < 1)) { 00261 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoStartTimestep); 00262 PrintUsageAndExit(); 00263 } 00264 StartTimeStep = atoi(optarg) - 1; 00265 00266 break; 00267 } 00268 00269 00270 case 0:{ /* long option without a short arg */ 00271 if( strcmp( "benchmark", longOpts[longIndex].name ) == 0 ) { 00272 BenchmarkFlag = true; 00273 if ((optarg == NULL) || (atoi(optarg) <= 0)) { 00274 fprintf(stderr,"%s", CommandlineParameters_ERR_FMT_NoBenchmarkTimeStepCount); 00275 PrintUsageAndExit(); 00276 }else { 00277 BenchmarkTimeStepsCount = atoi(optarg); 00278 } 00279 00280 }else 00281 00282 if( strcmp( "version", longOpts[longIndex].name ) == 0 ) { 00283 PrintVersion = true; 00284 return; 00285 } else 00286 00287 if( strcmp( "p_rms", longOpts[longIndex].name ) == 0 ) { 00288 Store_p_rms = true; 00289 } else 00290 if( strcmp( "p_max", longOpts[longIndex].name ) == 0 ) { 00291 Store_p_max = true; 00292 } else 00293 if( strcmp( "p_final", longOpts[longIndex].name ) == 0 ) { 00294 Store_p_final = true; 00295 } else 00296 00297 if( strcmp( "u_rms", longOpts[longIndex].name ) == 0 ) { 00298 Store_u_rms = true; 00299 } else 00300 if( strcmp( "u_max", longOpts[longIndex].name ) == 0 ) { 00301 Store_u_max = true; 00302 } else 00303 if( strcmp( "u_final", longOpts[longIndex].name ) == 0 ) { 00304 Store_u_final = true; 00305 } else 00306 00307 if( strcmp( "I_max", longOpts[longIndex].name ) == 0 ) { 00308 Store_I_max = true; 00309 } else { 00310 PrintUsageAndExit(); 00311 } 00312 00313 00314 break; 00315 } 00316 default:{ 00317 PrintUsageAndExit(); 00318 } 00319 } 00320 } 00321 00322 00323 //-- Post checks --// 00324 00325 00326 if (InputFileName == "") { 00327 fprintf(stderr,"%s",CommandlineParameters_ERR_FMT_NoInputFile); 00328 PrintUsageAndExit(); 00329 } 00330 00331 00332 if (OutputFileName == "") { 00333 fprintf(stderr,"%s",CommandlineParameters_ERR_FMT_NoOutputFile); 00334 PrintUsageAndExit(); 00335 } 00336 00337 00338 if (!(Store_p_raw || Store_p_rms || Store_p_max || Store_p_final || 00339 Store_u_raw || Store_u_rms || Store_u_max || Store_u_final || 00340 Store_I_avg || Store_I_max )){ 00341 Store_p_raw = true; 00342 } 00343 00344 00345 }// end of ParseCommandLine 00346 //------------------------------------------------------------------------------