示例#1
0
文件: device.cpp 项目: AI42/minerva
void ThreadedDevice::Execute(Task* task, int thrid) {
  PreExecute();
#ifndef NDEBUG
  WallTimer memory_timer;
  memory_timer.Start();
#endif
  DataList input_shards;
  for (auto& i : task->inputs) {
    auto& input_data = i.physical_data;
    if (input_data.device_id == device_id_) {  // Input is local
      DLOG(INFO) << Name() << " input task data #" << i.id << " is local";
      CHECK_EQ(local_data_.Count(input_data.data_id), 1);
    } else {
      lock_guard<mutex> lck(copy_locks_[input_data.data_id]);
      if (!remote_data_.Count(input_data.data_id)) {  // Input is remote and not copied
        DLOG(INFO) << Name() << " input task data #" << i.id << " is remote and not copied";
        size_t size = input_data.size.Prod() * sizeof(float);
        auto ptr = data_store_->CreateData(input_data.data_id, size);
        DoCopyRemoteData(ptr, MinervaSystem::Instance().GetPtr(input_data.device_id, input_data.data_id).second, size, thrid);
        CHECK(remote_data_.Insert(input_data.data_id));
      }
    }
    input_shards.emplace_back(data_store_->GetData(input_data.data_id), input_data.size);
  }
  DataList output_shards;
  for (auto& i : task->outputs) {
    size_t size = i.physical_data.size.Prod() * sizeof(float);
    DLOG(INFO) << Name() << " create output for task data #" << i.id;
    auto ptr = data_store_->CreateData(i.physical_data.data_id, size);
    CHECK(local_data_.Insert(i.physical_data.data_id));
    output_shards.emplace_back(ptr, i.physical_data.size);
  }
  auto& op = task->op;
  CHECK(op.compute_fn);
  if(!FLAGS_no_execute) {
#ifndef NDEBUG
    Barrier(thrid);
    memory_timer.Stop();
    MinervaSystem::Instance().profiler().RecordTime(TimerType::kMemory, op.compute_fn->Name(), memory_timer);
    WallTimer calculate_timer;
    calculate_timer.Start();
#endif
    DLOG(INFO) << Name() << " execute task #" << task->id << ": " << op.compute_fn->Name();
    DoExecute(input_shards, output_shards, op, thrid);
    DLOG(INFO) << Name() << " finished execute task #" << task->id << ": " << op.compute_fn->Name();
#ifndef NDEBUG
    calculate_timer.Stop();
    MinervaSystem::Instance().profiler().RecordTime(TimerType::kCalculation, op.compute_fn->Name(), calculate_timer);
#endif
  }
  listener_->OnOperationComplete(task);
}
void
avtDatasetQuery::PerformQuery(QueryAttributes *qA)
{
    queryAtts = *qA;

    Init(); 

    UpdateProgress(0, 0);
    //
    // Allow derived types to apply any necessary filters.
    //
    avtDataObject_p dob = ApplyFilters(GetInput());

    //
    // Reset the input so that we have access to the data tree. 
    //
    SetTypedInput(dob);

    avtDataTree_p tree = GetInputDataTree();
    int validInputTree = 0;
    
    if (*tree != NULL && !tree->IsEmpty())
    {
        validInputTree = 1;
        totalNodes = tree->GetNumberOfLeaves();
    }
    else 
    {
        validInputTree |= 0;
        totalNodes = 0;
        debug4 << "Query encountered EMPTY InputDataTree after ApplyFilters.  "
               << "This may be a valid state if running parallel and there "
               << "are more processors than domains." << endl;
    }

    bool hadError = false;
    PreExecute();
    TRY
    {
        Execute(tree);
    }
    CATCH2(VisItException, e)
    {
        debug1 << "Exception occurred in " << GetType() << endl;
        debug1 << "Going to keep going to prevent a parallel hang." << endl;
        queryAtts.SetResultsMessage(e.Message());
        hadError = true;
    }