0

I have written the following code and trying to parallelize it using openmp. but i am unbale to compile the program and end up with error invalid controlling predicate error

//It is also showing an error in #pragma omp atomic

int x;
    //int currentSampleCount=0; //TODO: Sahil. removed while merging projectdockwidget
    #pragma omp parallel for default(shared)
    for (int i=1;x==0;i++) {
        //  cerr <<"while loop";
        //  cerr <<xml.atEnd();

        //  #pragma omp atomic
         xml.readNext();

        if (xml.isStartElement()) {
            currentXmlElement = xml.name();


            if (xml.name() == "sample") {
                QString fname   = xml.attributes().value("filename").toString();
                QString sname   = xml.attributes().value("name").toString();
                QString setname   = xml.attributes().value("setName").toString();
                QString sampleOrder   = xml.attributes().value("sampleOrder").toString();
                QString isSelected   = xml.attributes().value("isSelected").toString();
                //_mainwindow->setStatusText(tr("Loading sample: %1").arg(sname));
                //_mainwindow->setProgressBar(tr("Loading Sample Number %1").arg(++currentSampleCount),currentSampleCount,currentSampleCount+1);

                bool checkLoaded=false;
                Q_FOREACH(mzSample* loadedFile, _mainwindow->getSamples()) {
                    if (QString(loadedFile->fileName.c_str())== fname) checkLoaded=true;
                }

                if(checkLoaded == true) continue;  // skip files that have been loaded already
                // #pragma omp critical {
                qDebug() << "Checking:" << fname;
                QFileInfo sampleFile(fname);

                if (!sampleFile.exists()) {
                    Q_FOREACH(QString path, pathlist) {
                        fname= path + QDir::separator() + sampleFile.fileName();
                        qDebug() << "Checking if exists:" << fname;
                        if (sampleFile.exists())  break;
                    }
                }

                if ( !fname.isEmpty() ) {
                    // mzFileIO* fileLoader = new mzFileIO(this);
                    // fileLoader->setMainWindow(_mainwindow);
                    // mzSample* sample = fileLoader->loadSample(fname);
                    // delete(fileLoader);

                    mzSample* sample = _mainwindow->fileLoader->loadSample(fname);
                    if (sample) {
                        _mainwindow->addSample(sample);
                        currentSample=sample;
                        if (!sname.isEmpty() )          sample->sampleName = sname.toStdString();
                        if (!setname.isEmpty() )        sample->setSetName(setname.toStdString());
                        if (!sampleOrder.isEmpty())     sample->setSampleOrder(sampleOrder.toInt());
                        if (!isSelected.isEmpty())      sample->isSelected = isSelected.toInt();
                    } else {
                        currentSample=NULL;
                    }
                }
            }

            //change sample color
            if (xml.name() == "color" && currentSample) {
                currentSample->color[0]   = xml.attributes().value("red").toString().toDouble();
                currentSample->color[1]   = xml.attributes().value("blue").toString().toDouble();
                currentSample->color[2]   = xml.attributes().value("green").toString().toDouble();
                currentSample->color[3]  = xml.attributes().value("alpha").toString().toDouble();
            }

            //polynomialAlignmentTransformation vector
            if (xml.name() == "polynomialAlignmentTransformation" && currentSample) {
                vector<double>transform;
                Q_FOREACH(QXmlStreamAttribute coef, xml.attributes() ) {
                    double coefValue =coef.value().toString().toDouble();
                    transform.push_back(coefValue);
                }
                qDebug() << "polynomialAlignmentTransformation: "; printF(transform);
                currentSample->polynomialAlignmentTransformation = transform;
                currentSample->saveOriginalRetentionTimes();
                currentSample->applyPolynomialTransform();
            }
        }
        if (xml.isCharacters() && currentXmlElement == "projectDescription") {
            projectDescription.append( xml.text() );
        }
         x =xml.atEnd();
    }
  • But its only ! operator @Hristo Iliev then give me solution for it – Girdhari Lal Nov 16 '16 at 17:42
  • I closed it prematurely by mistake, sorry. You are trying to use `parallel for` on a `while`-loop disguised as a `for`-loop and that's not going to work - loops with unknown number of iterations are not easily parallelisable. Also, `atomic` is not applicable to function calls. Perhaps, someone will be able to make their way through all that code and come up with a solution using OpenMP tasks. – Hristo Iliev Nov 16 '16 at 19:54
  • Yeah! I used {critical} at place of {atomic} and now it is working – Girdhari Lal Nov 17 '16 at 04:44

0 Answers0