Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
IsotopeWaveletParallelFor.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2013.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Rene Hussong$
32 // --------------------------------------------------------------------------
33 
34 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_ISOTOPEWAVELETPARALLELFOR_H
35 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_ISOTOPEWAVELETPARALLELFOR_H
36 
37 #include <tbb/blocked_range.h>
39 
40 #ifndef NULL
41 #define NULL 0
42 #endif
43 
44 
45 namespace OpenMS
46 {
47  template <typename PeakType, typename FeatureType>
48  class FeatureFinderAlgorithmIsotopeWavelet;
49 
51  template <typename PeakType, typename FeatureType>
53  {
54 public:
55 
58  iwts_(iwts), ff_(ff)
59  {
60  }
61 
64  void operator()(const tbb::blocked_range<size_t> & r) const
65  {
66  for (size_t t = r.begin(); t != r.end(); ++t) //this will be essentially one iteration
67  {
68  cudaSetDevice(ff_->gpu_ids_[t]);
70 
71  UInt num_gpus = ff_->gpu_ids_.size();
72  UInt block_size = (int)(ff_->map_->size() / num_gpus); UInt additional = ff_->map_->size() - num_gpus * block_size;
73  UInt from = t * block_size;
74  UInt up_to = (t >= num_gpus - 1) ? from + block_size + additional : from + block_size;
75 
76  for (UInt i = from; i < up_to; ++i)
77  {
78  const MSSpectrum<PeakType> & c_ref((*ff_->map_)[i]);
79  if (c_ref.size() <= 1) //unable to transform anything
80  {
81  //need to do this atomic
82  ff_->ff_->setProgress(ff_->progress_counter_ += 2);
83  continue;
84  }
85 
86  bool success = true;
88  if (!ff_->hr_data_) //LowRes data
89  {
90  std::cout << "Parallel for: here we are" << std::endl;
91 
92  c_trans = new typename IsotopeWaveletTransform<PeakType>::TransSpectrum(&(*ff_->map_)[i]);
93  success = c_iwt->initializeScanCuda((*ff_->map_)[i]) == Constants::CUDA_INIT_SUCCESS;
94 
95  if (success)
96  {
97  for (UInt c = 0; c < ff_->max_charge_; ++c)
98  {
99  c_iwt->getTransformCuda(*c_trans, c);
100 
101 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
102  std::stringstream stream;
103  stream << "gpu_lowres_" << ((*ff_->map_)[i]).getRT() << "_" << c + 1 << ".trans\0";
104  std::ofstream ofile(stream.str().c_str());
105  for (UInt k = 0; k < c_trans->size(); ++k)
106  {
107  ofile << c_trans->getMZ(k) << "\t" << c_trans->getTransIntensity(k) << "\t" << c_trans->getMZ(k) << "\t" << c_trans->getRefIntensity(k) << std::endl;
108  }
109  ofile.close();
110 #endif
111 
112 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
113  std::cout << "cuda transform for charge " << c + 1 << " O.K. ... "; std::cout.flush();
114 #endif
115  ff_->ff_->setProgress(++ff_->progress_counter_);
116 
117  c_iwt->identifyChargeCuda(*c_trans, i, c, ff_->intensity_threshold_, ff_->check_PPMs_);
118 
119 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
120  std::cout << "cuda charge recognition for charge " << c + 1 << " O.K." << std::endl;
121 #endif
122  ff_->ff_->setProgress(++ff_->progress_counter_);
123  }
124  c_iwt->finalizeScanCuda();
125  }
126  else
127  {
128  std::cout << "Warning/Error generated at scan " << i << " (" << ((*ff_->map_)[i]).getRT() << ")." << std::endl;
129  }
130  }
131  else //HighRes data
132  {
133  c_trans = ff_->prepareHRDataCuda(i, c_iwt);
134  for (UInt c = 0; c < ff_->max_charge_; ++c)
135  {
136  c_iwt->getTransformCuda(*c_trans, c);
137 
138 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
139  std::stringstream stream;
140  stream << "gpu_highres_" << ((*ff_->map_)[i]).getRT() << "_" << c + 1 << ".trans\0";
141  std::ofstream ofile(stream.str().c_str());
142  for (UInt k = 0; k < c_trans->size(); ++k)
143  {
144  ofile << c_trans->getMZ(k) << "\t" << c_trans->getTransIntensity(k) << "\t" << c_trans->getMZ(k) << "\t" << c_trans->getRefIntensity(k) << std::endl;
145  }
146  ofile.close();
147 #endif
148 
149 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
150  std::cout << "cuda transform for charge " << c + 1 << " O.K. ... "; std::cout.flush();
151 #endif
152  ff_->ff_->setProgress(++ff_->progress_counter_);
153 
154  c_iwt->identifyChargeCuda(*c_trans, i, c, ff_->intensity_threshold_, ff_->check_PPMs_);
155 
156 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
157  std::cout << "cuda charge recognition for charge " << c + 1 << " O.K." << std::endl;
158 #endif
159  ff_->ff_->setProgress(++ff_->progress_counter_);
160  }
161 
162  c_trans->destroy();
163  c_iwt->finalizeScanCuda();
164  }
165 
166  delete (c_trans); c_trans = NULL;
167 
168  c_iwt->updateBoxStates(*ff_->map_, i, ff_->RT_interleave_, ff_->real_RT_votes_cutoff_, from, up_to - 1);
169 #ifdef OPENMS_DEBUG_ISOTOPE_WAVELET
170  std::cout << "updated box states." << std::endl;
171 #endif
172 
173  std::cout.flush();
174  }
175 
176  c_iwt->updateBoxStates(*ff_->map_, INT_MAX, ff_->RT_interleave_, ff_->real_RT_votes_cutoff_);
177  }
178  }
179 
180 private:
181 
182  std::vector<IsotopeWaveletTransform<PeakType> *> & iwts_;
184 
185  }; //class
186 
187 
188 } //namespace
189 #endif
const int CUDA_INIT_SUCCESS
Definition: IsotopeWaveletConstants.h:92
const double k
IsotopeWaveletParallelFor(std::vector< IsotopeWaveletTransform< PeakType > * > &iwts, FeatureFinderAlgorithmIsotopeWavelet< PeakType, FeatureType > *ff)
Constructor.
Definition: IsotopeWaveletParallelFor.h:57
virtual void destroy()
Definition: IsotopeWaveletTransform.h:137
void operator()(const tbb::blocked_range< size_t > &r) const
The working horse of the class. The operator initializes the computation on the individual GPU...
Definition: IsotopeWaveletParallelFor.h:64
#define NULL
Definition: IsotopeWaveletParallelFor.h:41
const double c
Internally (only by GPUs) used data structure . It allows efficient data exchange between CPU and GPU...
Definition: IsotopeWaveletTransform.h:112
DoubleReal getMZ(const UInt i) const
Definition: IsotopeWaveletTransform.h:152
A class implementing the isotope wavelet transform. If you just want to find features using the isoto...
Definition: IsotopeWaveletTransform.h:87
Implements the isotope wavelet feature finder.
Definition: FeatureFinderAlgorithmIsotopeWavelet.h:76
std::vector< IsotopeWaveletTransform< PeakType > * > & iwts_
Definition: IsotopeWaveletParallelFor.h:182
void updateBoxStates(const MSExperiment< PeakType > &map, const Size scan_index, const UInt RT_interleave, const UInt RT_votes_cutoff, const Int front_bound=-1, const Int end_bound=-1)
A function keeping track of currently open and closed sweep line boxes. This function is used by the ...
Definition: IsotopeWaveletTransform.h:2029
DoubleReal getTransIntensity(const UInt i) const
Definition: IsotopeWaveletTransform.h:164
A class for distributing the data over several GPUs using Intel Threading Building Blocks...
Definition: IsotopeWaveletParallelFor.h:52
FeatureFinderAlgorithmIsotopeWavelet< PeakType, FeatureType > * ff_
Definition: IsotopeWaveletParallelFor.h:183
Size size() const
Definition: IsotopeWaveletTransform.h:176
DoubleReal getRefIntensity(const UInt i) const
Definition: IsotopeWaveletTransform.h:158

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:15 using doxygen 1.8.5