Browse Source

Cleanup of new progressbar

master
Trevor Irons 5 years ago
parent
commit
9463a482a2
2 changed files with 18 additions and 98 deletions
  1. 13
    98
      Modules/FDEM1D/src/EMEarth1D.cpp
  2. 5
    0
      Modules/LemmaCore/src/ProgressBar.cpp

+ 13
- 98
Modules/FDEM1D/src/EMEarth1D.cpp View File

@@ -188,8 +188,6 @@ namespace Lemma {
188 188
 
189 189
     void EMEarth1D::CalculateWireAntennaFields(bool progressbar) {
190 190
 
191
-        ProgressBar *mdisp;
192
-
193 191
         if (Earth == nullptr) {
194 192
             throw NullEarth();
195 193
         }
@@ -229,8 +227,9 @@ namespace Lemma {
229 227
             if ( Antenna->IsHorizontallyPlanar() && ( HankelType == ANDERSON801 || HankelType == FHTKEY201  || HankelType==FHTKEY101 ||
230 228
                                                       HankelType == FHTKEY51    || HankelType == FHTKONG61  || HankelType == FHTKONG121 ||
231 229
                                                       HankelType == FHTKONG241  || HankelType == IRONS )) {
230
+                std::unique_ptr<ProgressBar> mdisp;
232 231
                 if (progressbar) {
233
-                    mdisp = new ProgressBar( Receivers->GetNumberOfPoints()*Antenna->GetNumberOfFrequencies(), "Progress");
232
+                    mdisp = std::make_unique< ProgressBar >( Receivers->GetNumberOfPoints()*Antenna->GetNumberOfFrequencies() );
234 233
                 }
235 234
 
236 235
                 for (int ifreq=0; ifreq<Antenna->GetNumberOfFrequencies();++ifreq) {
@@ -247,20 +246,22 @@ namespace Lemma {
247 246
                     for (int irec=0; irec<Receivers->GetNumberOfPoints(); ++irec) {
248 247
                         SolveLaggedTxRxPair(irec, Hankel.get(), wavef, ifreq, AntCopy.get());
249 248
                         if (progressbar) {
250
-                            ++(*mdisp);
249
+                            ++ *mdisp;
251 250
                         }
252 251
                     }
253
-                    #pragma omp barrier
254 252
                     #ifdef LEMMAUSEOMP
253
+                    #pragma omp barrier
255 254
                     }
256 255
                     #endif
257 256
                 }
257
+
258
+
258 259
             } else if (Receivers->GetNumberOfPoints() > Antenna->GetNumberOfFrequencies()) {
259 260
 
260
-                //std::cout << "freq parallel #1" << std::endl;
261 261
                 //** Progress display bar for long calculations */
262
+                std::unique_ptr<ProgressBar> mdisp;
262 263
                 if (progressbar) {
263
-                    mdisp = new ProgressBar( Receivers->GetNumberOfPoints()*Antenna->GetNumberOfFrequencies() );
264
+                    mdisp = std::make_unique< ProgressBar > ( Receivers->GetNumberOfPoints()*Antenna->GetNumberOfFrequencies() );
264 265
                 }
265 266
 
266 267
                 // parallelise across receivers
@@ -272,40 +273,7 @@ namespace Lemma {
272 273
                     // thread.
273 274
                     auto AntCopy = static_cast<PolygonalWireAntenna*>(Antenna.get())->ClonePA();
274 275
                     auto Hankel = HankelTransformFactory::NewSP( HankelType );
275
-/*
276
-                    std::shared_ptr<HankelTransform> Hankel;
277
-                    switch (HankelType) {
278
-                        case ANDERSON801:
279
-                            Hankel = FHTAnderson801::NewSP();
280
-                            break;
281
-                        case CHAVE:
282
-                            Hankel = GQChave::NewSP();
283
-                            break;
284
-                        case FHTKEY201:
285
-                            Hankel = FHTKey201::NewSP();
286
-                            break;
287
-                        case FHTKEY101:
288
-                            Hankel = FHTKey101::NewSP();
289
-                            break;
290
-                        case FHTKEY51:
291
-                            Hankel = FHTKey51::NewSP();
292
-                            break;
293
-                        case FHTKONG61:
294
-                            Hankel = FHT<FHTKONG61>::NewSP();
295
-                            break;
296
-                        case FHTKONG121:
297
-                            Hankel = FHT<FHTKONG121>::NewSP();
298
-                            break;
299
-                        case QWEKEY:
300
-                            std::cout << "QWEKEY" << std::endl;
301
-                            Hankel = QWEKey::NewSP();
302
-                            break;
303
-                        default:
304
-                            std::cerr << "Hankel transform cannot be created\n";
305
-                            exit(EXIT_FAILURE);
306
-                    }
307
-*/
308
-                    //for (int irec=tid; irec<Receivers->GetNumberOfPoints(); irec+=nthreads) {
276
+
309 277
                     #ifdef LEMMAUSEOMP
310 278
                     #pragma omp for schedule(static, 1) //nowait
311 279
                     #endif
@@ -330,7 +298,7 @@ namespace Lemma {
330 298
                         //std::cout << Receivers->GetHfield(0, irec) << std::endl;
331 299
                         //if (irec == 1) exit(0);
332 300
                         if (progressbar) {
333
-                            ++(*mdisp);
301
+                            ++ *mdisp;
334 302
                         }
335 303
                     } // receiver loop
336 304
                 } // OMP_PARALLEL BLOCK
@@ -345,30 +313,7 @@ namespace Lemma {
345 313
                         #endif
346 314
                         { // OpenMP Parallel Block
347 315
 
348
-                            std::shared_ptr<HankelTransform> Hankel;
349
-                            switch (HankelType) {
350
-                                case ANDERSON801:
351
-                                    Hankel = FHTAnderson801::NewSP();
352
-                                    break;
353
-                                case CHAVE:
354
-                                    Hankel = GQChave::NewSP();
355
-                                    break;
356
-                                case FHTKEY201:
357
-                                    Hankel = FHTKey201::NewSP();
358
-                                    break;
359
-                                case FHTKEY101:
360
-                                    Hankel = FHTKey101::NewSP();
361
-                                    break;
362
-                                case FHTKEY51:
363
-                                    Hankel = FHTKey51::NewSP();
364
-                                    break;
365
-                                case QWEKEY:
366
-                                    Hankel = QWEKey::NewSP();
367
-                                    break;
368
-                                default:
369
-                                    std::cerr << "Hankel transform cannot be created\n";
370
-                                    exit(EXIT_FAILURE);
371
-                            }
316
+                            auto Hankel = HankelTransformFactory::NewSP( HankelType );
372 317
                             #ifdef LEMMAUSEOMP
373 318
                             #pragma omp for schedule(static, 1)
374 319
                             #endif
@@ -387,13 +332,11 @@ namespace Lemma {
387 332
                     //    ++ mdisp;
388 333
                     //}
389 334
                 } // receiver loop
390
-                //std::cout << "End freq parallel " << std::endl;
391 335
             } // Frequency Parallel
392 336
               else {
393
-                //std::cout << "parallel across #3 " << std::endl;
337
+                //std::cout << "parallel across transmitter dipoles " << std::endl;
394 338
                 for (int irec=0; irec<Receivers->GetNumberOfPoints(); ++irec) {
395 339
                     if (!Receivers->GetMask(irec)) {
396
-
397 340
                         static_cast<PolygonalWireAntenna*>(Antenna.get())->ApproximateWithElectricDipoles(Receivers->GetLocation(irec));
398 341
 //                         std::cout << "Not Masked " << std::endl;
399 342
 //                         std::cout << "n Freqs " << Antenna->GetNumberOfFrequencies() << std::endl;
@@ -402,35 +345,11 @@ namespace Lemma {
402 345
 //                             std::cout << "NO DIPOLES!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
403 346
 // //                            std::cout << "rec location " << Receivers->GetLocation(irec) << std::endl;
404 347
 // //                        }
405
-
406 348
                         #ifdef LEMMAUSEOMP
407 349
                         #pragma omp parallel
408 350
                         #endif
409 351
                         { // OpenMP Parallel Block
410
-                            std::shared_ptr<HankelTransform> Hankel;
411
-                            switch (HankelType) {
412
-                                case ANDERSON801:
413
-                                    Hankel = FHTAnderson801::NewSP();
414
-                                    break;
415
-                                case CHAVE:
416
-                                    Hankel = GQChave::NewSP();
417
-                                    break;
418
-                                case FHTKEY201:
419
-                                    Hankel = FHTKey201::NewSP();
420
-                                    break;
421
-                                case FHTKEY101:
422
-                                    Hankel = FHTKey101::NewSP();
423
-                                    break;
424
-                                case FHTKEY51:
425
-                                    Hankel = FHTKey51::NewSP();
426
-                                    break;
427
-                                case QWEKEY:
428
-                                    Hankel = QWEKey::NewSP();
429
-                                    break;
430
-                                default:
431
-                                    std::cerr << "Hankel transform cannot be created\n";
432
-                                    exit(EXIT_FAILURE);
433
-                            }
352
+                            auto Hankel = HankelTransformFactory::NewSP( HankelType );
434 353
                             for (int ifreq=0; ifreq<Antenna->GetNumberOfFrequencies(); ++ifreq) {
435 354
                                 #ifdef LEMMAUSEOMP
436 355
                                 #pragma omp for schedule(static, 1)
@@ -468,10 +387,6 @@ namespace Lemma {
468 387
             this->Dipole = nullptr;
469 388
         }
470 389
 
471
-        if (progressbar) {
472
-            delete mdisp;
473
-        }
474
-
475 390
     }
476 391
 
477 392
     #ifdef KIHALEE_EM1D

+ 5
- 0
Modules/LemmaCore/src/ProgressBar.cpp View File

@@ -44,6 +44,7 @@ ProgressBar::~ProgressBar()
44 44
 
45 45
 void ProgressBar::operator++()
46 46
 {
47
+
47 48
     if (mEnded)
48 49
     {
49 50
         throw std::runtime_error(
@@ -54,7 +55,11 @@ void ProgressBar::operator++()
54 55
     const unsigned int percentage = static_cast<unsigned int>(
55 56
             mNumberOfTicks*100.0/mTotalIterations);
56 57
 
58
+    #ifdef LEMMAUSEOMP
59
+    #pragma omp critical
60
+    #endif
57 61
     std::cout << generateProgressBar(percentage) << "\r" << std::flush;
62
+
58 63
 }
59 64
 
60 65
 void ProgressBar::printNewMessage(const std::string& message)

Loading…
Cancel
Save