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
 
188
 
189
     void EMEarth1D::CalculateWireAntennaFields(bool progressbar) {
189
     void EMEarth1D::CalculateWireAntennaFields(bool progressbar) {
190
 
190
 
191
-        ProgressBar *mdisp;
192
-
193
         if (Earth == nullptr) {
191
         if (Earth == nullptr) {
194
             throw NullEarth();
192
             throw NullEarth();
195
         }
193
         }
229
             if ( Antenna->IsHorizontallyPlanar() && ( HankelType == ANDERSON801 || HankelType == FHTKEY201  || HankelType==FHTKEY101 ||
227
             if ( Antenna->IsHorizontallyPlanar() && ( HankelType == ANDERSON801 || HankelType == FHTKEY201  || HankelType==FHTKEY101 ||
230
                                                       HankelType == FHTKEY51    || HankelType == FHTKONG61  || HankelType == FHTKONG121 ||
228
                                                       HankelType == FHTKEY51    || HankelType == FHTKONG61  || HankelType == FHTKONG121 ||
231
                                                       HankelType == FHTKONG241  || HankelType == IRONS )) {
229
                                                       HankelType == FHTKONG241  || HankelType == IRONS )) {
230
+                std::unique_ptr<ProgressBar> mdisp;
232
                 if (progressbar) {
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
                 for (int ifreq=0; ifreq<Antenna->GetNumberOfFrequencies();++ifreq) {
235
                 for (int ifreq=0; ifreq<Antenna->GetNumberOfFrequencies();++ifreq) {
247
                     for (int irec=0; irec<Receivers->GetNumberOfPoints(); ++irec) {
246
                     for (int irec=0; irec<Receivers->GetNumberOfPoints(); ++irec) {
248
                         SolveLaggedTxRxPair(irec, Hankel.get(), wavef, ifreq, AntCopy.get());
247
                         SolveLaggedTxRxPair(irec, Hankel.get(), wavef, ifreq, AntCopy.get());
249
                         if (progressbar) {
248
                         if (progressbar) {
250
-                            ++(*mdisp);
249
+                            ++ *mdisp;
251
                         }
250
                         }
252
                     }
251
                     }
253
-                    #pragma omp barrier
254
                     #ifdef LEMMAUSEOMP
252
                     #ifdef LEMMAUSEOMP
253
+                    #pragma omp barrier
255
                     }
254
                     }
256
                     #endif
255
                     #endif
257
                 }
256
                 }
257
+
258
+
258
             } else if (Receivers->GetNumberOfPoints() > Antenna->GetNumberOfFrequencies()) {
259
             } else if (Receivers->GetNumberOfPoints() > Antenna->GetNumberOfFrequencies()) {
259
 
260
 
260
-                //std::cout << "freq parallel #1" << std::endl;
261
                 //** Progress display bar for long calculations */
261
                 //** Progress display bar for long calculations */
262
+                std::unique_ptr<ProgressBar> mdisp;
262
                 if (progressbar) {
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
                 // parallelise across receivers
267
                 // parallelise across receivers
272
                     // thread.
273
                     // thread.
273
                     auto AntCopy = static_cast<PolygonalWireAntenna*>(Antenna.get())->ClonePA();
274
                     auto AntCopy = static_cast<PolygonalWireAntenna*>(Antenna.get())->ClonePA();
274
                     auto Hankel = HankelTransformFactory::NewSP( HankelType );
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
                     #ifdef LEMMAUSEOMP
277
                     #ifdef LEMMAUSEOMP
310
                     #pragma omp for schedule(static, 1) //nowait
278
                     #pragma omp for schedule(static, 1) //nowait
311
                     #endif
279
                     #endif
330
                         //std::cout << Receivers->GetHfield(0, irec) << std::endl;
298
                         //std::cout << Receivers->GetHfield(0, irec) << std::endl;
331
                         //if (irec == 1) exit(0);
299
                         //if (irec == 1) exit(0);
332
                         if (progressbar) {
300
                         if (progressbar) {
333
-                            ++(*mdisp);
301
+                            ++ *mdisp;
334
                         }
302
                         }
335
                     } // receiver loop
303
                     } // receiver loop
336
                 } // OMP_PARALLEL BLOCK
304
                 } // OMP_PARALLEL BLOCK
345
                         #endif
313
                         #endif
346
                         { // OpenMP Parallel Block
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
                             #ifdef LEMMAUSEOMP
317
                             #ifdef LEMMAUSEOMP
373
                             #pragma omp for schedule(static, 1)
318
                             #pragma omp for schedule(static, 1)
374
                             #endif
319
                             #endif
387
                     //    ++ mdisp;
332
                     //    ++ mdisp;
388
                     //}
333
                     //}
389
                 } // receiver loop
334
                 } // receiver loop
390
-                //std::cout << "End freq parallel " << std::endl;
391
             } // Frequency Parallel
335
             } // Frequency Parallel
392
               else {
336
               else {
393
-                //std::cout << "parallel across #3 " << std::endl;
337
+                //std::cout << "parallel across transmitter dipoles " << std::endl;
394
                 for (int irec=0; irec<Receivers->GetNumberOfPoints(); ++irec) {
338
                 for (int irec=0; irec<Receivers->GetNumberOfPoints(); ++irec) {
395
                     if (!Receivers->GetMask(irec)) {
339
                     if (!Receivers->GetMask(irec)) {
396
-
397
                         static_cast<PolygonalWireAntenna*>(Antenna.get())->ApproximateWithElectricDipoles(Receivers->GetLocation(irec));
340
                         static_cast<PolygonalWireAntenna*>(Antenna.get())->ApproximateWithElectricDipoles(Receivers->GetLocation(irec));
398
 //                         std::cout << "Not Masked " << std::endl;
341
 //                         std::cout << "Not Masked " << std::endl;
399
 //                         std::cout << "n Freqs " << Antenna->GetNumberOfFrequencies() << std::endl;
342
 //                         std::cout << "n Freqs " << Antenna->GetNumberOfFrequencies() << std::endl;
402
 //                             std::cout << "NO DIPOLES!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
345
 //                             std::cout << "NO DIPOLES!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
403
 // //                            std::cout << "rec location " << Receivers->GetLocation(irec) << std::endl;
346
 // //                            std::cout << "rec location " << Receivers->GetLocation(irec) << std::endl;
404
 // //                        }
347
 // //                        }
405
-
406
                         #ifdef LEMMAUSEOMP
348
                         #ifdef LEMMAUSEOMP
407
                         #pragma omp parallel
349
                         #pragma omp parallel
408
                         #endif
350
                         #endif
409
                         { // OpenMP Parallel Block
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
                             for (int ifreq=0; ifreq<Antenna->GetNumberOfFrequencies(); ++ifreq) {
353
                             for (int ifreq=0; ifreq<Antenna->GetNumberOfFrequencies(); ++ifreq) {
435
                                 #ifdef LEMMAUSEOMP
354
                                 #ifdef LEMMAUSEOMP
436
                                 #pragma omp for schedule(static, 1)
355
                                 #pragma omp for schedule(static, 1)
468
             this->Dipole = nullptr;
387
             this->Dipole = nullptr;
469
         }
388
         }
470
 
389
 
471
-        if (progressbar) {
472
-            delete mdisp;
473
-        }
474
-
475
     }
390
     }
476
 
391
 
477
     #ifdef KIHALEE_EM1D
392
     #ifdef KIHALEE_EM1D

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

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

Loading…
Cancel
Save