Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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)
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)
00080 {
00081
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_)
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
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 };
00186
00187
00188 }
00189 #endif