Commit 81d989de85124a3031e13bb78e557ed19ad89674

Authored by Jürgen Knödlseder
1 parent 60aa959e

More testing of critical OpenMP zone

Showing 1 changed file with 149 additions and 141 deletions
src/support/ctool.cpp
... ... @@ -589,98 +589,95 @@ GEbounds ctool::create_ebounds(void)
589 589 // Initialise exception message string
590 590 std::string msg;
591 591  
592   - // If no extension name was provided then use default extension names
593   - if (!ebinfile.has_extname()) {
594   -
595   - // Make loading of energy boundaries OpenMP thread save
596   - #pragma omp critical(ctool_create_ebounds1)
597   - //{
  592 + // Make loading of energy boundaries OpenMP thread save. The critical
  593 + // region is put into an exception block to prevent throwing exceptions
  594 + // within the critical block
  595 + #pragma omp critical(ctool_create_ebounds)
  596 + {
598 597 try {
599 598  
600   - // Open energy boundary file using the EBOUNDS or ENERGYBINS
601   - // extension or energy values using the ENERGIES extension.
602   - // If opening fails then set exception message. The
603   - // exception is thrown later outside the critical OpenMP
604   - // block.
605   - GFits file(ebinfile.url());
606   - if (file.contains(gammalib::extname_ebounds)) {
607   - file.close();
608   - ebounds.load(ebinfile);
609   - }
610   - else if (file.contains("ENERGYBINS")) {
611   - file.close();
612   - ebinfile = ebinfile.url() + "[ENERGYBINS]";
613   - ebounds.load(ebinfile);
614   - }
615   - else if (file.contains(gammalib::extname_energies)) {
616   - file.close();
617   - ebounds.set(GEnergies(ebinfile));
618   - }
619   - else {
620   - file.close();
621   - msg = "No extension with name \""+
622   - gammalib::extname_ebounds+"\", "
623   - "\"ENERGYBINS\" or \""+
624   - gammalib::extname_energies+"\" found in FITS "
625   - "file \""+ebinfile+"\". Please specify a "
626   - "valid energy binning file.";
627   - }
628   - }
629   - catch (const std::exception& e) {
630   - msg = e.what();
631   - }
632   - //} // end: omp critical section
  599 + // If no extension name was provided then use default extension
  600 + // names
  601 + if (!ebinfile.has_extname()) {
  602 +
  603 + // Open energy boundary file using the EBOUNDS or ENERGYBINS
  604 + // extension or energy values using the ENERGIES extension.
  605 + // If opening fails then set exception message. The
  606 + // exception is thrown later outside the critical OpenMP
  607 + // block.
  608 + GFits file(ebinfile.url());
  609 + if (file.contains(gammalib::extname_ebounds)) {
  610 + file.close();
  611 + ebounds.load(ebinfile);
  612 + }
  613 + else if (file.contains("ENERGYBINS")) {
  614 + file.close();
  615 + ebinfile = ebinfile.url() + "[ENERGYBINS]";
  616 + ebounds.load(ebinfile);
  617 + }
  618 + else if (file.contains(gammalib::extname_energies)) {
  619 + file.close();
  620 + ebounds.set(GEnergies(ebinfile));
  621 + }
  622 + else {
  623 + file.close();
  624 + msg = "No extension with name \""+
  625 + gammalib::extname_ebounds+"\", "
  626 + "\"ENERGYBINS\" or \""+
  627 + gammalib::extname_energies+"\" found in FITS "
  628 + "file \""+ebinfile+"\". Please specify a "
  629 + "valid energy binning file.";
  630 + }
633 631  
634   - } // endif: no extension name specified
  632 + } // endif: no extension name specified
635 633  
636   - // ... otherwise load energy boundaries from filename including
637   - // extension
638   - else {
  634 + // ... otherwise load energy boundaries from filename including
  635 + // extension
  636 + else {
639 637  
640   - // Make loading of energy boundaries OpenMP thread save
641   - #pragma omp critical(ctool_create_ebounds2)
642   - //{
643   - try {
  638 + // Open energy boundary file
  639 + GFits file(ebinfile.url());
  640 +
  641 + // If FITS file does not contain requested extension then
  642 + // set exception message. The exception is thrown later
  643 + // outside the critical OpenMP zone
  644 + if (!file.contains(ebinfile.extname())) {
  645 + msg = "No extension \""+ebinfile.extname()+"\" "
  646 + "found in energy binning file \""+
  647 + ebinfile.url()+"\". Please provide a valid "
  648 + "extension name.";
  649 + }
644 650  
645   - // Open energy boundary file
646   - GFits file(ebinfile.url());
  651 + // ... otherwise load energy boundaries
  652 + else {
647 653  
648   - // If FITS file does not contain requested extension then set
649   - // exception message. The exception is thrown later outside the
650   - // critical OpenMP
651   - if (!file.contains(ebinfile.extname())) {
652   - msg = "No extension \""+ebinfile.extname()+"\" "
653   - "found in energy binning file \""+
654   - ebinfile.url()+"\". Please provide a valid "
655   - "extension name.";
656   - }
  654 + // Get table extension
  655 + GFitsTable& table = *file.table(ebinfile.extname());
657 656  
658   - // ... otherwise load energy boundaries
659   - else {
  657 + // If table contains one column then load energies,
  658 + // otherwise load energy boundaries.
  659 + if (table.ncols() == 1) {
  660 + file.close();
  661 + ebounds.set(GEnergies(ebinfile));
  662 + }
  663 + else {
  664 + file.close();
  665 + ebounds.load(ebinfile);
  666 + }
660 667  
661   - // Get table extension
662   - GFitsTable& table = *file.table(ebinfile.extname());
  668 + } // endelse: extension name was present in FITS file
663 669  
664   - // If table contains one column then load energies, otherwise load
665   - // energy boundaries.
666   - if (table.ncols() == 1) {
667   - file.close();
668   - ebounds.set(GEnergies(ebinfile));
669   - }
670   - else {
671   - file.close();
672   - ebounds.load(ebinfile);
673   - }
  670 + } // endelse: loaded energy boundaries from table extension
674 671  
675   - } // endelse: extension name was present in FITS file
  672 + } // endtry
676 673  
677   - }
  674 + // Catch any exceptions that occured in OpenMP critical block
  675 + // and recover the error message
678 676 catch (const std::exception& e) {
679 677 msg = e.what();
680 678 }
681   - //} // end: omp critical section
682 679  
683   - } // endelse: loaded energy boundaries from table extension
  680 + } // end critical OpenMP block
684 681  
685 682 // If we have an exception message then throw an exception now. We
686 683 // have to do this since we should not throw exceptions inside OpenMP
... ... @@ -758,84 +755,95 @@ GEnergies ctool::create_energies(void)
758 755 // Initialise exception message string
759 756 std::string msg;
760 757  
761   - // If no extension name was provided then use default extension names
762   - if (!ebinfile.has_extname()) {
763   -
764   - // Make loading of energies OpenMP thread save
765   - #pragma omp critical(ctool_create_energies1)
766   - {
767   -
768   - // Open energy boundary file using the EBOUNDS or ENERGYBINS
769   - // extension or energy values using the ENERGIES extension.
770   - // If opening fails then set exception message. The
771   - // exception is thrown later outside the critical OpenMP
772   - // block.
773   - GFits file(ebinfile.url());
774   - if (file.contains(gammalib::extname_energies)) {
775   - file.close();
776   - energies.load(ebinfile);
777   - }
778   - else if (file.contains(gammalib::extname_ebounds)) {
779   - file.close();
780   - energies.set(GEbounds(ebinfile));
781   - }
782   - else if (file.contains("ENERGYBINS")) {
783   - file.close();
784   - ebinfile = ebinfile.url() + "[ENERGYBINS]";
785   - energies.set(GEbounds(ebinfile));
786   - }
787   - else {
788   - file.close();
789   - msg = "No extension with name \""+
790   - gammalib::extname_energies+"\", "
791   - "\"ENERGYBINS\" or \""+
792   - gammalib::extname_ebounds+"\" found in FITS "
793   - "file \""+ebinfile+"\". Please specify a "
794   - "valid energy binning file.";
795   - }
796   -
797   - } // end: omp critical section
  758 + // Make loading of energies OpenMP thread save. The critical region is
  759 + // put into an exception block to prevent throwing exceptions within
  760 + // the critical block
  761 + #pragma omp critical(ctool_create_energies)
  762 + {
  763 + try {
798 764  
799   - }
  765 + // If no extension name was provided then use default extension
  766 + // names
  767 + if (!ebinfile.has_extname()) {
  768 +
  769 + // Open energy boundary file using the EBOUNDS or ENERGYBINS
  770 + // extension or energy values using the ENERGIES extension.
  771 + // If opening fails then set exception message. The
  772 + // exception is thrown later outside the critical OpenMP
  773 + // block.
  774 + GFits file(ebinfile.url());
  775 + if (file.contains(gammalib::extname_energies)) {
  776 + file.close();
  777 + energies.load(ebinfile);
  778 + }
  779 + else if (file.contains(gammalib::extname_ebounds)) {
  780 + file.close();
  781 + energies.set(GEbounds(ebinfile));
  782 + }
  783 + else if (file.contains("ENERGYBINS")) {
  784 + file.close();
  785 + ebinfile = ebinfile.url() + "[ENERGYBINS]";
  786 + energies.set(GEbounds(ebinfile));
  787 + }
  788 + else {
  789 + file.close();
  790 + msg = "No extension with name \""+
  791 + gammalib::extname_energies+"\", "
  792 + "\"ENERGYBINS\" or \""+
  793 + gammalib::extname_ebounds+"\" found in FITS "
  794 + "file \""+ebinfile+"\". Please specify a "
  795 + "valid energy binning file.";
  796 + }
800 797  
801   - // ... otherwise load energy boundaries from filename including
802   - // extension
803   - else {
  798 + }
804 799  
805   - // Make loading of energies OpenMP thread save
806   - #pragma omp critical(ctool_create_energies2)
807   - {
  800 + // ... otherwise load energy boundaries from filename including
  801 + // extension
  802 + else {
808 803  
809   - // Open energy boundary file
810   - GFits file(ebinfile.url());
  804 + // Open energy boundary file
  805 + GFits file(ebinfile.url());
811 806  
812   - // If FITS file does not contain requested extension then set
813   - // exception message. The exception is thrown later outside the
814   - // critical OpenMP
815   - if (!file.contains(ebinfile.extname())) {
  807 + // If FITS file does not contain requested extension then
  808 + // set exception message. The exception is thrown later
  809 + // outside the critical OpenMP zone
  810 + if (!file.contains(ebinfile.extname())) {
816 811 msg = "No extension \""+ebinfile.extname()+"\" "
817 812 "found in energy node file \""+
818 813 ebinfile.url()+"\". Please provide a valid "
819 814 "extension name.";
820   - }
  815 + }
821 816  
822   - // Get table extension
823   - GFitsTable& table = *file.table(ebinfile.extname());
  817 + // ... otherwise load energies
  818 + else {
824 819  
825   - // If table contains one column then load energies, otherwise
826   - // load energy boundaries.
827   - if (table.ncols() == 1) {
828   - file.close();
829   - energies.load(ebinfile);
830   - }
831   - else {
832   - file.close();
833   - energies.set(GEbounds(ebinfile));
834   - }
  820 + // Get table extension
  821 + GFitsTable& table = *file.table(ebinfile.extname());
835 822  
836   - } // end: omp critical section
  823 + // If table contains one column then load energies,
  824 + // otherwise load energy boundaries.
  825 + if (table.ncols() == 1) {
  826 + file.close();
  827 + energies.load(ebinfile);
  828 + }
  829 + else {
  830 + file.close();
  831 + energies.set(GEbounds(ebinfile));
  832 + }
  833 +
  834 + } // endelse: extension name was present in FITS file
  835 +
  836 + } // endelse: loaded energies from table extension
  837 +
  838 + } // endtry
  839 +
  840 + // Catch any exceptions that occured in OpenMP critical block
  841 + // and recover the error message
  842 + catch (const std::exception& e) {
  843 + msg = e.what();
  844 + }
837 845  
838   - } // endelse: loaded energy boundaries from table extension
  846 + } // end critical OpenMP block
839 847  
840 848 // If we have an exception message then throw an exception now. We
841 849 // have to do this since we should not throw exceptions inside OpenMP
... ...