Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

IsotopeWaveletParallelFor.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Rene Hussong$
00032 // --------------------------------------------------------------------------
00033 
00034 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_ISOTOPEWAVELETPARALLELFOR_H
00035 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_ISOTOPEWAVELETPARALLELFOR_H
00036 
00037 #include <tbb/blocked_range.h>
00038 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeatureFinderAlgorithmIsotopeWavelet.h>
00039 
00040 #ifndef NULL
00041 #define NULL 0
00042 #endif
00043 
00044 
00045 namespace OpenMS
00046 {
00047   template <typename PeakType, typename FeatureType>
00048   class FeatureFinderAlgorithmIsotopeWavelet;
00049 
00051   template <typename PeakType, typename FeatureType>
00052   class IsotopeWaveletParallelFor
00053   {
00054 public:
00055 
00057     IsotopeWaveletParallelFor(std::vector<IsotopeWaveletTransform<PeakType> *> & iwts, FeatureFinderAlgorithmIsotopeWavelet<PeakType, FeatureType> * ff) :
00058       iwts_(iwts), ff_(ff)
00059     {
00060     }
00061 
00064     void operator()(const tbb::blocked_range<size_t> & r) const
00065     {
00066       for (size_t t = r.begin(); t != r.end(); ++t)       //this will be essentially one iteration
00067       {
00068         cudaSetDevice(ff_->gpu_ids_[t]);
00069         IsotopeWaveletTransform<PeakType> * c_iwt = iwts_[t];
00070 
00071         UInt num_gpus = ff_->gpu_ids_.size();
00072         UInt block_size = (int)(ff_->map_->size() / num_gpus); UInt additional = ff_->map_->size() - num_gpus * block_size;
00073         UInt from = t * block_size;
00074         UInt up_to = (t >= num_gpus - 1) ? from + block_size + additional : from + block_size;
00075 
00076         for (UInt i = from; i < up_to; ++i)
00077         {
00078           const MSSpectrum<PeakType> & c_ref((*ff_->map_)[i]);
00079           if (c_ref.size() <= 1)               //unable to transform anything
00080           {
00081             //need to do this atomic
00082             ff_->ff_->setProgress(ff_->progress_counter_ += 2);
00083             continue;
00084           }
00085 
00086           bool success = true;
00087           typename IsotopeWaveletTransform<PeakType>::TransSpectrum * c_trans(NULL);
00088           if (!ff_->hr_data_)               //LowRes data
00089           {
00090             std::cout << "Parallel for: here we are" << std::endl;
00091 
00092             c_trans = new typename IsotopeWaveletTransform<PeakType>::TransSpectrum(&(*ff_->map_)[i]);
00093             success = c_iwt->initializeScanCuda((*ff_->map_)[i]) == Constants::CUDA_INIT_SUCCESS;
00094 
00095             if (success)
00096             {
00097               for (UInt c = 0; c < ff_->max_charge_; ++c)
00098               {
00099                 c_iwt->getTransformCuda(*c_trans, c);
00100 
00101 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
00102                 std::stringstream stream;
00103                 stream << "gpu_lowres_" << ((*ff_->map_)[i]).getRT() << "_" << c + 1 << ".trans\0";
00104                 std::ofstream ofile(stream.str().c_str());
00105                 for (UInt k = 0; k < c_trans->size(); ++k)
00106                 {
00107                   ofile << c_trans->getMZ(k) << "\t" <<  c_trans->getTransIntensity(k) << "\t" << c_trans->getMZ(k) << "\t" << c_trans->getRefIntensity(k) << std::endl;
00108                 }
00109                 ofile.close();
00110 #endif
00111 
00112 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
00113                 std::cout << "cuda transform for charge " << c + 1 << "  O.K. ... "; std::cout.flush();
00114 #endif
00115                 ff_->ff_->setProgress(++ff_->progress_counter_);
00116 
00117                 c_iwt->identifyChargeCuda(*c_trans, i, c, ff_->intensity_threshold_, ff_->check_PPMs_);
00118 
00119 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
00120                 std::cout << "cuda charge recognition for charge " << c + 1 << " O.K." << std::endl;
00121 #endif
00122                 ff_->ff_->setProgress(++ff_->progress_counter_);
00123               }
00124               c_iwt->finalizeScanCuda();
00125             }
00126             else
00127             {
00128               std::cout << "Warning/Error generated at scan " << i << " (" << ((*ff_->map_)[i]).getRT() << ")." << std::endl;
00129             }
00130           }
00131           else               //HighRes data
00132           {
00133             c_trans = ff_->prepareHRDataCuda(i, c_iwt);
00134             for (UInt c = 0; c < ff_->max_charge_; ++c)
00135             {
00136               c_iwt->getTransformCuda(*c_trans, c);
00137 
00138 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
00139               std::stringstream stream;
00140               stream << "gpu_highres_" << ((*ff_->map_)[i]).getRT() << "_" << c + 1 << ".trans\0";
00141               std::ofstream ofile(stream.str().c_str());
00142               for (UInt k = 0; k < c_trans->size(); ++k)
00143               {
00144                 ofile << c_trans->getMZ(k) << "\t" <<  c_trans->getTransIntensity(k) << "\t" << c_trans->getMZ(k) << "\t" << c_trans->getRefIntensity(k) << std::endl;
00145               }
00146               ofile.close();
00147 #endif
00148 
00149 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
00150               std::cout << "cuda transform for charge " << c + 1 << "  O.K. ... "; std::cout.flush();
00151 #endif
00152               ff_->ff_->setProgress(++ff_->progress_counter_);
00153 
00154               c_iwt->identifyChargeCuda(*c_trans, i, c, ff_->intensity_threshold_, ff_->check_PPMs_);
00155 
00156 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
00157               std::cout << "cuda charge recognition for charge " << c + 1 << " O.K." << std::endl;
00158 #endif
00159               ff_->ff_->setProgress(++ff_->progress_counter_);
00160             }
00161 
00162             c_trans->destroy();
00163             c_iwt->finalizeScanCuda();
00164           }
00165 
00166           delete (c_trans); c_trans = NULL;
00167 
00168           c_iwt->updateBoxStates(*ff_->map_, i, ff_->RT_interleave_, ff_->real_RT_votes_cutoff_, from, up_to - 1);
00169 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
00170           std::cout << "updated box states." << std::endl;
00171 #endif
00172 
00173           std::cout.flush();
00174         }
00175 
00176         c_iwt->updateBoxStates(*ff_->map_, INT_MAX, ff_->RT_interleave_, ff_->real_RT_votes_cutoff_);
00177       }
00178     }
00179 
00180 private:
00181 
00182     std::vector<IsotopeWaveletTransform<PeakType> *> & iwts_;
00183     FeatureFinderAlgorithmIsotopeWavelet<PeakType, FeatureType> * ff_;
00184 
00185   };   //class
00186 
00187 
00188 } //namespace
00189 #endif

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:40 using doxygen 1.7.1