예제 #1
0
void QueueManager::setupConnections()
{
  // opt connections
  connect(this, SIGNAL(needNewStructure()), m_opt, SLOT(generateNewStructure()),
          Qt::QueuedConnection);

  // re-emit connections
  connect(this, SIGNAL(structureStarted(GlobalSearch::Structure*)), this,
          SIGNAL(structureUpdated(GlobalSearch::Structure*)));
  connect(this, SIGNAL(structureSubmitted(GlobalSearch::Structure*)), this,
          SIGNAL(structureUpdated(GlobalSearch::Structure*)));
  connect(this, SIGNAL(structureKilled(GlobalSearch::Structure*)), this,
          SIGNAL(structureUpdated(GlobalSearch::Structure*)));
  connect(this, SIGNAL(structureFinished(GlobalSearch::Structure*)), this,
          SIGNAL(structureUpdated(GlobalSearch::Structure*)));

  // internal connections
  connect(this, SIGNAL(structureStarted(GlobalSearch::Structure*)), this,
          SLOT(addStructureToSubmissionQueue(GlobalSearch::Structure*)),
          Qt::QueuedConnection);

// Work around bug in Qt 4.6.3:
#if QT_VERSION == 0x040603
  connect(this, SIGNAL(newStructureQueued()), this, SLOT(unlockForNaming_()),
          Qt::QueuedConnection);
#endif // QT_VERSION == 4.6.3

  QTimer::singleShot(0, this, SLOT(checkLoop()));
}
예제 #2
0
  void ExampleSearch::startSearch()
  {
    // Add search-specific checks here
    // If something is amiss, call error("Error message") and return.

    // Are the selected queueinterface and optimizer happy?
    QString err;
    if (!m_optimizer->isReadyToSearch(&err)) {
      error(tr("Optimizer is not fully initialized:") + "\n\n" + err);
      return;
    }

    if (!m_queueInterface->isReadyToSearch(&err)) {
      error(tr("QueueInterface is not fully initialized:") + "\n\n" + err);
      return;
    }

    // Warn user if runningJobLimit is 0
    if (limitRunningJobs && runningJobLimit == 0) {
      error(tr("Warning: the number of running jobs is currently set to 0."
               "\n\nYou will need to increase this value before the search "
               "can begin (The option is on the 'Optimization Settings' tab)."));
    };

    // Initialize ssh connections
#ifdef ENABLE_SSH
    // Create the SSHManager if running remotely
    if (qobject_cast<RemoteQueueInterface*>(m_queueInterface) != 0) {
      if (!this->createSSHConnections()) {
        error(tr("Could not create ssh connections."));
        return;
      }
    }
#endif // ENABLE_SSH

    // Here we go!
    debug("Starting optimization.");

    // prepare pointers
    m_tracker->lockForWrite();
    m_tracker->deleteAllStructures();
    m_tracker->unlock();

    // Throw signal
    emit startingSession();

    ////////////////////////////////
    // Generate random structures //
    ////////////////////////////////

    // Set up progress bar
    m_dialog->startProgressUpdate(tr("Generating structures..."), 0, 0);

    // Initalize loop variables
    int progCount=0;

    // Generation loop...
    for (uint i = 0; i < runningJobLimit; i++) {
      m_dialog->updateProgressMaximum( (i == 0)
                                        ? 0
                                        : int(progCount
                                              / static_cast<double>(i))
                                       * runningJobLimit );
      m_dialog->updateProgressValue(progCount++);
      m_dialog->updateProgressLabel(tr("%1 structures generated of (%2)...")
                                    .arg(i)
                                    .arg(runningJobLimit));

      generateNewStructure();
    }

    // Wait for all structures to appear in tracker
    m_dialog->updateProgressLabel(tr("Waiting for structures to initialize..."));
    m_dialog->updateProgressMinimum(0);
    m_dialog->updateProgressMinimum(runningJobLimit);

    connect(m_tracker, SIGNAL(newStructureAdded(GlobalSearch::Structure*)),
            m_initWC, SLOT(wakeAllSlot()));

    m_initWC->prewaitLock();
    do {
      m_dialog->updateProgressValue(m_tracker->size());
      m_dialog->updateProgressLabel(tr("Waiting for structures to initialize (%1 of %2)...")
                                    .arg(m_tracker->size())
                                    .arg(runningJobLimit));
      // Don't block here forever -- there is a race condition where
      // the final newStructureAdded signal may be emitted while the
      // WC is not waiting. Since this is just trivial GUI updating
      // and we check the condition in the do-while loop, this is
      // acceptable. The following call will timeout in 250 ms.
      m_initWC->wait(250);
    }
    while (m_tracker->size() < runningJobLimit);
    m_initWC->postwaitUnlock();

    // We're done with m_initWC.
    m_initWC->disconnect();

    m_dialog->stopProgressUpdate();

    emit sessionStarted();
    m_dialog->saveSession();
  }