Example #1
0
    void _sequence_one(task_pool& tp, std::shared_ptr<std::list<std::function<void ()>>> shared_tasks, std::function<void(std::exception_ptr err)> callback)
    {
        assert(shared_tasks);
        assert(!shared_tasks->empty());

        auto task = shared_tasks->front();
        assert(task);
        try
        {
            task();
        }
        catch (...)
        {
            auto err = std::current_exception();
            tp.sync([callback, err] () {
                callback(err);
            });
            return;
        }

        shared_tasks->pop_front();
        if (shared_tasks->empty())
        {
            tp.sync([callback] () {
                callback(std::exception_ptr{});
            });
        }
        else
        {
            tp.async([&tp, shared_tasks, callback] () {
                _sequence_one(tp, shared_tasks, callback);
            });
        }
    }
/*!
*  \brief      Set the MeshContainer
*  \param[in]  MeshContainer
*  \author     Sascha Kaden
*  \date       2016-08-25
*/
void Joint::setModel(std::shared_ptr<ModelContainer> &model) {
    if (!model || model->empty()) {
        Logging::error("Emtpy model", "Joint");
        return;
    }
    m_model = model;
}
Example #3
0
// OVERRIDE 
void Hand::SortHandHighLow(std::shared_ptr<std::vector<Card>> c)
{
    if (c->empty())
    {
        printf_s("Passing a null/void vector! Cannot sort the hand high to low");
        return;
    }
    // Iterate throught the card's hand
    bool swapped;
    do
    {
        swapped = false;
        for (unsigned int i = 0; i < c->size() - 1; ++i)
        {
            if (c->at(i).GetCardValue() < c->at(i + 1).GetCardValue())
            {
                SwapCards(c, i, i + 1);
                swapped = true;
            }
            else
            {
                // Do nothing here
            }
        }
    } while (swapped);

}
Example #4
0
void Service::start()
{
  auto& device = hw::Devices::drive(0);
  disk = std::make_shared<fs::Disk> (device);

  INFO("FAT32", "Running tests for FAT32");
  CHECKSERT(disk, "Disk created");

  // which means that the disk can't be empty
  CHECKSERT(not disk->empty(), "Disk not empty");
  // verify that the size is indeed N sectors
  CHECKSERT(disk->dev().size() == SIZE / 512, "Disk size is %llu sectors", SIZE / 512);

  // auto-mount filesystem
  disk->init_fs(
  [] (fs::error_t err, auto& fs)
  {
    CHECKSERT(!err, "Filesystem auto-initializedd");

    const std::string fsname = "FAT16";
    CHECKSERT(fs.name() == fsname, "Filesystem recognized as FAT16");

    fs.ls("/",
    [] (fs::error_t err, auto ents) {
      CHECKSERT(not err, "Listing root directory");
      CHECKSERT(ents->size() == 2, "Exactly two ents in root dir");

      auto& e = ents->at(0);
      CHECKSERT(e.is_file(), "Ent is a file");
      CHECKSERT(e.name() == "banana.txt", "Ents name is 'banana.txt'");

      test2();
    });
  });
}
Example #5
0
void Output::printBinary(std::shared_ptr<std::vector<char>> data)
{
	try
	{
		if(!data || data->empty()) return;
		std::ostringstream stringstream;
		stringstream << std::hex << std::setfill('0') << std::uppercase;
		for(std::vector<char>::iterator i = data->begin(); i != data->end(); ++i)
		{
			stringstream << std::setw(2) << (int32_t)((uint8_t)(*i));
		}
		stringstream << std::dec;
		std::cout << stringstream.str() << std::endl;
	}
	catch(const std::exception& ex)
    {
    	printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(const Exception& ex)
    {
    	printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
    	printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
}
Example #6
0
bool SpectraVisDataUploader::SetCurrent(void)
{
    assert(gl_canvases);
    if(gl_canvases->empty()) return false;
    wxGLCanvas* gl_canvas = *gl_canvases->begin();
    assert(gl_canvas);
    gl_canvas->SetCurrent(*gl_context);
    return true;
}
Example #7
0
	void print()
	{
		std::cout << "ID : " << id << "\n";
		if (data->empty())
			return;
		for (auto& item : *data)
		{
			std::cout << item.first << "\t" << item.second << "\n";
		}
	}
    void LoadRTree()
    {
        BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");

        RTreeNode *tree_ptr =
            data_layout->GetBlockPtr<RTreeNode>(shared_memory, SharedDataLayout::R_SEARCH_TREE);
        m_static_rtree.reset(new TimeStampedRTreePair(
            CURRENT_TIMESTAMP,
            osrm::make_unique<SharedRTree>(
                tree_ptr, data_layout->num_entries[SharedDataLayout::R_SEARCH_TREE],
                file_index_path, m_coordinate_list)));
    }
 void display(const std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
 {
     // User's displaying/saving/other processing here
         // datum.cvOutputData: rendered frame with pose or heatmaps
         // datum.poseKeypoints: Array<float> with the estimated pose
     if (datumsPtr != nullptr && !datumsPtr->empty())
     {
         cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData);
         cv::waitKey(1); // It displays the image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image)
     }
     else
         op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
 }
Example #10
0
std::shared_ptr<RPCVariable> RPCDecoder::decodeResponse(std::shared_ptr<std::vector<char>> packet, uint32_t offset)
{
	uint32_t position = offset + 8;
	std::shared_ptr<RPCVariable> response = decodeParameter(packet, position);
	if(packet->empty()) return response; //response is Void when packet is empty.
	if(packet->at(3) == 0xFF)
	{
		response->errorStruct = true;
		if(response->structValue->find("faultCode") == response->structValue->end()) response->structValue->insert(RPC::RPCStructElement("faultCode", std::shared_ptr<RPC::RPCVariable>(new RPC::RPCVariable(-1))));
		if(response->structValue->find("faultString") == response->structValue->end()) response->structValue->insert(RPC::RPCStructElement("faultString", std::shared_ptr<RPC::RPCVariable>(new RPC::RPCVariable(std::string("undefined")))));
	}
	return response;
}
 void printKeypoints(const std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
 {
     // Example: How to use the pose keypoints
     if (datumsPtr != nullptr && !datumsPtr->empty())
     {
         op::log("\nKeypoints:");
         // Accesing each element of the keypoints
         const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints;
         op::log("Person pose keypoints:");
         for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++)
         {
             op::log("Person " + std::to_string(person) + " (x, y, score):");
             for (auto bodyPart = 0 ; bodyPart < poseKeypoints.getSize(1) ; bodyPart++)
             {
                 std::string valueToPrint;
                 for (auto xyscore = 0 ; xyscore < poseKeypoints.getSize(2) ; xyscore++)
                     valueToPrint += std::to_string(   poseKeypoints[{person, bodyPart, xyscore}]   ) + " ";
                 op::log(valueToPrint);
             }
         }
         op::log(" ");
         // Alternative: just getting std::string equivalent
         op::log("Face keypoints: " + datumsPtr->at(0).faceKeypoints.toString());
         op::log("Left hand keypoints: " + datumsPtr->at(0).handKeypoints[0].toString());
         op::log("Right hand keypoints: " + datumsPtr->at(0).handKeypoints[1].toString());
         // Heatmaps
         const auto& poseHeatMaps = datumsPtr->at(0).poseHeatMaps;
         if (!poseHeatMaps.empty())
         {
             op::log("Pose heatmaps size: [" + std::to_string(poseHeatMaps.getSize(0)) + ", "
                     + std::to_string(poseHeatMaps.getSize(1)) + ", "
                     + std::to_string(poseHeatMaps.getSize(2)) + "]");
             const auto& faceHeatMaps = datumsPtr->at(0).faceHeatMaps;
             op::log("Face heatmaps size: [" + std::to_string(faceHeatMaps.getSize(0)) + ", "
                     + std::to_string(faceHeatMaps.getSize(1)) + ", "
                     + std::to_string(faceHeatMaps.getSize(2)) + ", "
                     + std::to_string(faceHeatMaps.getSize(3)) + "]");
             const auto& handHeatMaps = datumsPtr->at(0).handHeatMaps;
             op::log("Left hand heatmaps size: [" + std::to_string(handHeatMaps[0].getSize(0)) + ", "
                     + std::to_string(handHeatMaps[0].getSize(1)) + ", "
                     + std::to_string(handHeatMaps[0].getSize(2)) + ", "
                     + std::to_string(handHeatMaps[0].getSize(3)) + "]");
             op::log("Right hand heatmaps size: [" + std::to_string(handHeatMaps[1].getSize(0)) + ", "
                     + std::to_string(handHeatMaps[1].getSize(1)) + ", "
                     + std::to_string(handHeatMaps[1].getSize(2)) + ", "
                     + std::to_string(handHeatMaps[1].getSize(3)) + "]");
         }
     }
     else
         op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
 }
Example #12
0
void ProcDecompiler::recursionGroupAnalysis(const std::shared_ptr<ProcSet> &group)
{
    /* Overall algorithm:
     *  for each proc in the group
     *          initialise
     *          earlyDecompile
     *  for each proc in the group
     *          middleDecompile
     *  mark all calls involved in cs as non-childless
     *  for each proc in cs
     *          update parameters and returns, redoing call bypass, until no change
     *  for each proc in cs
     *          remove unused statements
     *  for each proc in cs
     *          update parameters and returns, redoing call bypass, until no change
     */
    if (group->empty()) {
        return;
    }

    LOG_MSG("Performing recursion group analysis for %1 recursive procedures: ", group->size());
    for (UserProc *proc : *group) {
        LOG_MSG("    %1", proc->getName());
    }

    UserProc *entry = *group->begin();
    bool changed    = false;
    int numRepeats  = 0;

    do {
        ProcSet visited;
        changed = decompileProcInRecursionGroup(entry, visited);
    } while (changed && numRepeats++ < 2);

    // while no change
    for (int i = 0; i < 2; i++) {
        for (UserProc *proc : *group) {
            lateDecompile(proc); // Also does final parameters and arguments at present
        }
    }

    LOG_VERBOSE("=== End recursion group analysis ===");
    for (UserProc *proc : *group) {
        proc->getProg()->getProject()->alertEndDecompile(proc);
    }
}
 void work(std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
 {
     // User's post-processing (after OpenPose processing & before OpenPose outputs) here
         // datum.cvOutputData: rendered frame with pose or heatmaps
         // datum.poseKeypoints: Array<float> with the estimated pose
     try
     {
         if (datumsPtr != nullptr && !datumsPtr->empty())
             for (auto& datum : *datumsPtr)
                 cv::bitwise_not(datum.cvOutputData, datum.cvOutputData);
     }
     catch (const std::exception& e)
     {
         this->stop();
         op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Example #14
0
 void WReconstruction3D::work(std::shared_ptr<std::vector<Datum3D>>& datumsPtr)
 {
     // User's post-processing (after OpenPose processing & before OpenPose outputs) here
         // datum.cvOutputData: rendered frame with pose or heatmaps
         // datum.poseKeypoints: Array<float> with the estimated pose
     try
     {
         // Profiling speed
         const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
         if (datumsPtr != nullptr && !datumsPtr->empty())
         {
             std::vector<Array<float>> poseKeypointVector;
             std::vector<Array<float>> faceKeypointVector;
             std::vector<Array<float>> leftHandKeypointVector;
             std::vector<Array<float>> rightHandKeypointVector;
             for (auto& datumsElement : *datumsPtr)
             {
                 poseKeypointVector.emplace_back(datumsElement.poseKeypoints);
                 faceKeypointVector.emplace_back(datumsElement.faceKeypoints);
                 leftHandKeypointVector.emplace_back(datumsElement.handKeypoints[0]);
                 rightHandKeypointVector.emplace_back(datumsElement.handKeypoints[1]);
             }
             // Pose 3-D reconstruction
             reconstructArray(datumsPtr->at(0).poseKeypoints3D, poseKeypointVector);
             // Face 3-D reconstruction
             reconstructArray(datumsPtr->at(0).faceKeypoints3D, faceKeypointVector);
             // Left hand 3-D reconstruction
             reconstructArray(datumsPtr->at(0).leftHandKeypoints3D, leftHandKeypointVector);
             // Right hand 3-D reconstruction
             reconstructArray(datumsPtr->at(0).rightHandKeypoints3D, rightHandKeypointVector);
             // Profiling speed
             Profiler::timerEnd(profilerKey);
             Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
         }
     }
     catch (const std::exception& e)
     {
         log("Some kind of unexpected error happened.");
         this->stop();
         error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Example #15
0
void js_extraction_test( JSBindable *self, std::shared_ptr< std::vector<JSTrigger*> > js_scripts )
{
	JSTrigger *trig;
	if( !js_scripts || js_scripts->empty() )
		return;
	for(int i = 0;i < js_scripts->size();i++)
	{
		if (js_scripts->at(i)->isFlagged(JS::EXTRACTION))
		{
			trig = js_scripts->at(i);
			if (randomly_triggered(trig->narg))
			{
				int ret_val = JSManager::get()->execute(trig, self, 0);

				if( ret_val == 0 )
					return;
			}
		}
	}
}
 void workConsumer(const std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
 {
     try
     {
         // User's displaying/saving/other processing here
             // datum.cvOutputData: rendered frame with pose or heatmaps
             // datum.poseKeypoints: Array<float> with the estimated pose
         if (datumsPtr != nullptr && !datumsPtr->empty())
         {
             cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData);
             // It displays the image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image)
             cv::waitKey(1);
         }
     }
     catch (const std::exception& e)
     {
         op::log("Some kind of unexpected error happened.");
         this->stop();
         op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
     }
 }
Example #17
0
void sendOnSocket(std::shared_ptr<std::queue<std::pair<boost::asio::ip::udp::endpoint, std::shared_ptr<boost::asio::streambuf>>>> outgoingBufferQueue,
            std::shared_ptr<std::mutex> socketMutex, std::shared_ptr<boost::asio::ip::udp::socket> socket) {
    while(socket->is_open()) {
        try {
            if (!outgoingBufferQueue->empty()) {
                // Removes first message to be sent
                auto sendingPair = outgoingBufferQueue->front();
                outgoingBufferQueue->pop();

                // Locks to guarantee thread safety with receiving thread
                socketMutex->lock();

                // The sending call. Sends to the endpoint corresponding to the message popped off the queue.
                socket->send_to(boost::asio::buffer(sendingPair.second.get(), VEHICLE_MESSAGE_SIZE), sendingPair.first);

                // Unlocks as soon as possible
                socketMutex->unlock();
            }
        } catch (std::exception& e) {
            std::cout << e.what() << std::endl;
        }
    }
}
Example #18
0
//-----------------------------------------------------------------------------
void OpenMpAssembler::assemble_interior_facets(
  GenericTensor& A,
  const Form& a, UFC& _ufc,
  std::shared_ptr<const MeshFunction<std::size_t>> domains,
  std::shared_ptr<const MeshFunction<std::size_t>> cell_domains,
  std::vector<double>* values)
{
  warning("OpenMpAssembler::assemble_interior_facets is untested.");

  // Extract mesh
  const Mesh& mesh = a.mesh();

  // Topological dimension
  const std::size_t D = mesh.topology().dim();

  dolfin_assert(!values);

  // Skip assembly if there are no interior facet integrals
  if (!_ufc.form.has_interior_facet_integrals())
    return;

  Timer timer("Assemble interior facets");

  // Set number of OpenMP threads (from parameter systems)
  omp_set_num_threads(parameters["num_threads"]);

  // Get integral for sub domain (if any)

  bool use_domains = domains && !domains->empty();
  bool use_cell_domains = cell_domains && !cell_domains->empty();
  if (use_domains)
  {
    dolfin_error("OpenMPAssembler.cpp",
                 "perform multithreaded assembly using OpenMP assembler",
                 "Subdomains are not yet handled");
  }

  // Color mesh
  std::vector<std::size_t> coloring_type = a.coloring(D - 1);
  mesh.color(coloring_type);

  // Dummy UFC object since each thread needs to created its own UFC object
  UFC ufc(_ufc);

  // Form rank
  const std::size_t form_rank = ufc.form.rank();

  // Collect pointers to dof maps
  std::vector<const GenericDofMap*> dofmaps;
  for (std::size_t i = 0; i < form_rank; ++i)
    dofmaps.push_back(a.function_space(i)->dofmap().get());

  // Vector to hold dofs for cells
  std::vector<std::vector<dolfin::la_index>> macro_dofs(form_rank);

  // Interior facet integral
  const ufc::interior_facet_integral* integral
    = ufc.default_interior_facet_integral.get();

  // Compute facets and facet - cell connectivity if not already computed
  mesh.init(D - 1);
  mesh.init(D - 1, D);
  dolfin_assert(mesh.ordered());

  // Get coloring data
  std::map<const std::vector<std::size_t>,
           std::pair<std::vector<std::size_t>,
                     std::vector<std::vector<std::size_t>>>>::const_iterator
    mesh_coloring;
  mesh_coloring = mesh.topology().coloring.find(coloring_type);

  // Check that requested coloring has been computed
  if (mesh_coloring == mesh.topology().coloring.end())
  {
    dolfin_error("OpenMPAssembler.cpp",
                 "perform multithreaded assembly using OpenMP assembler",
                 "Requested mesh coloring has not been computed");
  }

  // Get coloring data
  const std::vector<std::vector<std::size_t>>& entities_of_color
    = mesh_coloring->second.second;

  // UFC cells and vertex coordinates
  ufc::cell ufc_cell0, ufc_cell1;
  std::vector<double> vertex_coordinates0, vertex_coordinates1;

  // Assemble over interior facets (loop over colours, then cells of same color)
  const std::size_t num_colors = entities_of_color.size();
  for (std::size_t color = 0; color < num_colors; ++color)
  {
    // Get the array of facet indices of current color
    const std::vector<std::size_t>& colored_facets = entities_of_color[color];

    // Number of facets of current color
    const int num_facets = colored_facets.size();

    // OpenMP test loop over cells of the same color
    Progress p(AssemblerBase::progress_message(A.rank(), "interior facets"),
               mesh.num_facets());
#pragma omp parallel for schedule(guided, 20) firstprivate(ufc, ufc_cell0, ufc_cell1, vertex_coordinates0, vertex_coordinates1, macro_dofs, integral)
    for (int facet_index = 0; facet_index < num_facets; ++facet_index)
    {
      // Facet index
      const std::size_t index = colored_facets[facet_index];

      // Create cell
      const Facet facet(mesh, index);

      // Only consider interior facets
      if (facet.exterior())
      {
        p++;
        continue;
      }

      // Get integral for sub domain (if any)
      if (use_domains)
        integral = ufc.get_interior_facet_integral((*domains)[facet]);

      // Skip integral if zero
      if (!integral)
        continue;

      // Get cells incident with facet (which is 0 and 1 here is arbitrary)
      dolfin_assert(facet.num_entities(D) == 2);
      std::size_t cell_index_plus = facet.entities(D)[0];
      std::size_t cell_index_minus = facet.entities(D)[1];

      if (use_cell_domains && (*cell_domains)[cell_index_plus] < (*cell_domains)[cell_index_minus])
        std::swap(cell_index_plus, cell_index_minus);

      // The convention '+' = 0, '-' = 1 is from ffc
      const Cell cell0(mesh, cell_index_plus);
      const Cell cell1(mesh, cell_index_minus);

      // Get local index of facet with respect to each cell
      const std::size_t local_facet0 = cell0.index(facet);
      const std::size_t local_facet1 = cell1.index(facet);

      // Update UFC cell
      cell0.get_vertex_coordinates(vertex_coordinates0);
      cell0.get_cell_data(ufc_cell0, local_facet0);
      cell1.get_vertex_coordinates(vertex_coordinates1);
      cell1.get_cell_data(ufc_cell1, local_facet1);

      // Update to current pair of cells
      ufc.update(cell0, vertex_coordinates0, ufc_cell0,
                 cell1, vertex_coordinates1, ufc_cell1,
                 integral->enabled_coefficients());

      // Tabulate dofs for each dimension on macro element
      for (std::size_t i = 0; i < form_rank; i++)
      {
        // Get dofs for each cell
        const ArrayView<const dolfin::la_index> cell_dofs0
          = dofmaps[i]->cell_dofs(cell0.index());
        const ArrayView<const dolfin::la_index> cell_dofs1
          = dofmaps[i]->cell_dofs(cell1.index());

        // Create space in macro dof vector
        macro_dofs[i].resize(cell_dofs0.size() + cell_dofs1.size());

        // Copy cell dofs into macro dof vector
        std::copy(cell_dofs0.begin(), cell_dofs0.end(), macro_dofs[i].begin());
        std::copy(cell_dofs1.begin(), cell_dofs1.end(),
                  macro_dofs[i].begin() + cell_dofs0.size());
      }

      // Tabulate exterior interior facet tensor on macro element
      integral->tabulate_tensor(ufc.macro_A.data(),
                                ufc.macro_w(),
                                vertex_coordinates0.data(),
                                vertex_coordinates1.data(),
                                local_facet0,
                                local_facet1,
                                ufc_cell0.orientation,
                                ufc_cell1.orientation);

      // Add entries to global tensor
      std::vector<ArrayView<const la_index>>
        macro_dofs_p(macro_dofs.size());
      for (std::size_t i = 0; i < macro_dofs.size(); ++i)
        macro_dofs_p[i].set(macro_dofs[i]);
      A.add_local(ufc.macro_A.data(), macro_dofs_p);

      p++;
    }
  }
}
    void workConsumer(const std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
    {
        try
        {
            // User's displaying/saving/other processing here
                // datum.cvOutputData: rendered frame with pose or heatmaps
                // datum.poseKeypoints: Array<float> with the estimated pose
            if (datumsPtr != nullptr && !datumsPtr->empty())
            {
                // Show in command line the resulting pose keypoints for body, face and hands
                op::log("\nKeypoints:");
                // Accesing each element of the keypoints
                const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints;
                op::log("Person pose keypoints:");
                for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++)
                {
                    op::log("Person " + std::to_string(person) + " (x, y, score):");
                    for (auto bodyPart = 0 ; bodyPart < poseKeypoints.getSize(1) ; bodyPart++)
                    {
                        std::string valueToPrint;
                        for (auto xyscore = 0 ; xyscore < poseKeypoints.getSize(2) ; xyscore++)
                        {
                            valueToPrint += std::to_string(   poseKeypoints[{person, bodyPart, xyscore}]   ) + " ";
                        }
                        op::log(valueToPrint);
                    }
                }
                op::log(" ");
                // Alternative: just getting std::string equivalent
                op::log("Face keypoints: " + datumsPtr->at(0).faceKeypoints.toString());
                op::log("Left hand keypoints: " + datumsPtr->at(0).handKeypoints[0].toString());
                op::log("Right hand keypoints: " + datumsPtr->at(0).handKeypoints[1].toString());
                // Heatmaps
                const auto& poseHeatMaps = datumsPtr->at(0).poseHeatMaps;
                if (!poseHeatMaps.empty())
                {
                    op::log("Pose heatmaps size: [" + std::to_string(poseHeatMaps.getSize(0)) + ", "
                            + std::to_string(poseHeatMaps.getSize(1)) + ", "
                            + std::to_string(poseHeatMaps.getSize(2)) + "]");
                    const auto& faceHeatMaps = datumsPtr->at(0).faceHeatMaps;
                    op::log("Face heatmaps size: [" + std::to_string(faceHeatMaps.getSize(0)) + ", "
                            + std::to_string(faceHeatMaps.getSize(1)) + ", "
                            + std::to_string(faceHeatMaps.getSize(2)) + ", "
                            + std::to_string(faceHeatMaps.getSize(3)) + "]");
                    const auto& handHeatMaps = datumsPtr->at(0).handHeatMaps;
                    op::log("Left hand heatmaps size: [" + std::to_string(handHeatMaps[0].getSize(0)) + ", "
                            + std::to_string(handHeatMaps[0].getSize(1)) + ", "
                            + std::to_string(handHeatMaps[0].getSize(2)) + ", "
                            + std::to_string(handHeatMaps[0].getSize(3)) + "]");
                    op::log("Right hand heatmaps size: [" + std::to_string(handHeatMaps[1].getSize(0)) + ", "
                            + std::to_string(handHeatMaps[1].getSize(1)) + ", "
                            + std::to_string(handHeatMaps[1].getSize(2)) + ", "
                            + std::to_string(handHeatMaps[1].getSize(3)) + "]");
                }

                // Display rendered output image
                cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData);
                // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image)
                const char key = (char)cv::waitKey(1);
                if (key == 27)
                    this->stop();
            }
        }
        catch (const std::exception& e)
        {
            this->stop();
            op::error(e.what(), __LINE__, __FUNCTION__, __FILE__);
        }
    }
Example #20
0
 bool empty() const
 {
     return m_slot_list->empty();
 }
Example #21
0
void test2()
{
  INFO("FAT32", "Remounting disk.");

  CHECKSERT(not disk->empty(), "Disk not empty");
  CHECKSERT(disk->dev().size() == SIZE / 512, "Disk size is %llu bytes", SIZE);

  disk->init_fs(disk->MBR,
  [] (fs::error_t err, auto& fs)
  {
    CHECKSERT(not err, "Filesystem mounted on VBR1");

    fs.stat(shallow_banana,
    [] (auto err, const auto& ent) {
      INFO("FAT32", "Shallow banana");

      CHECKSERT(not err, "Stat %s", shallow_banana.c_str());

      CHECKSERT(ent.is_valid(), "Stat file in root dir");
      CHECKSERT(ent.is_file(), "Entity is file");
      CHECKSERT(!ent.is_dir(), "Entity is not directory");
      CHECKSERT(ent.name() == "banana.txt", "Name is 'banana.txt'");
      is_done();
    });

    fs.read_file(shallow_banana,
    [] (fs::error_t err, fs::buffer_t buf)
    {
      INFO("FAT32", "Read file");
      if (err) {
        printf("Read error: %s\n", err.to_string().c_str());
      }
      CHECKSERT(not err, "read_file: Read %s asynchronously", shallow_banana.c_str());
      printf("%s\n", internal_banana.c_str());
      std::string banana((const char*) buf->data(), buf->size());
      CHECKSERT(banana == internal_banana, "Correct shallow banana");
      is_done();
    });

    fs.stat(deep_banana,
    [] (auto err, const auto& ent) {
      INFO("FAT32", "Deep banana");
      auto& fs = disk->fs();
      CHECKSERT(not err, "Stat %s", deep_banana.c_str());
      CHECKSERT(ent.is_valid(), "Stat file in deep dir");
      CHECKSERT(ent.is_file(), "Entity is file");
      CHECKSERT(!ent.is_dir(), "Entity is not directory");

      CHECKSERT(ent.name() == "banana.txt", "Name is 'banana.txt'");

      // asynch file reading test
      fs.read(ent, 0, ent.size(),
      [] (fs::error_t err, fs::buffer_t buf)
      {
        INFO("FAT32", "Read inside stat");
        CHECKSERT(not err, "read: Read %s asynchronously", deep_banana.c_str());

        std::string banana((const char*) buf->data(), buf->size());
        CHECKSERT(banana == internal_banana, "Correct deep fried banana");
        is_done();
      });
    });

  });
}
Example #22
0
void Service::start()
{
  INFO("FAT32", "Running tests for FAT32");
  auto& device = hw::Dev::disk<0, hw::IDE>(hw::IDE::SLAVE);
  disk = std::make_shared<FatDisk> (device);
  assert(disk);
  
  // verify that the size is indeed N sectors
  const size_t SIZE = 4194304;
  CHECK(disk->dev().size() == SIZE, "Disk size 4194304 sectors");
  assert(disk->dev().size() == SIZE);
  
  // which means that the disk can't be empty
  CHECK(!disk->empty(), "Disk not empty");
  assert(!disk->empty());
  
  // auto-mount filesystem
  disk->mount(disk->MBR,
  [] (fs::error_t err)
  {
    CHECK(!err, "Filesystem auto-mounted");
    assert(!err);
    
    auto& fs = disk->fs();
    printf("\t\t%s filesystem\n", fs.name().c_str());
    
    auto vec = fs::new_shared_vector();
    err = fs.ls("/", vec);
    CHECK(!err, "List root directory");
    assert(!err);
    
    CHECK(vec->size() == 2, "Exactly two ents in root dir");
    assert(vec->size() == 2);
    
    auto& e = vec->at(0);
    CHECK(e.is_file(), "Ent is a file");
    CHECK(e.name() == "banana.txt", "Ent is 'banana.txt'");
  });
  // re-mount on VBR1
  disk->mount(disk->VBR1,
  [] (fs::error_t err)
  {
    CHECK(!err, "Filesystem mounted on VBR1");
    assert(!err);
    
    auto& fs = disk->fs();
    auto ent = fs.stat("/banana.txt");
    CHECK(ent.is_valid(), "Stat file in root dir");
    assert(ent.is_valid());
    
    CHECK(ent.is_file(), "Entity is file");
    assert(ent.is_file());
    
    CHECK(!ent.is_dir(), "Entity is not directory");
    assert(!ent.is_dir());
    
    CHECK(ent.name() == "banana.txt", "Name is 'banana.txt'");
    assert(ent.name() == "banana.txt");
    
    ent = fs.stat("/dir1/dir2/dir3/dir4/dir5/dir6/banana.txt");
    CHECK(ent.is_valid(), "Stat file in deep dir");
    assert(ent.is_valid());
    
    CHECK(ent.is_file(), "Entity is file");
    assert(ent.is_file());
    
    CHECK(!ent.is_dir(), "Entity is not directory");
    assert(!ent.is_dir());
    
    CHECK(ent.name() == "banana.txt", "Name is 'banana.txt'");
    assert(ent.name() == "banana.txt");
    
  });
  
  INFO("FAT32", "SUCCESS");
}
Example #23
0
int32_t UdpSocket::proofwrite(const std::shared_ptr<std::vector<char>> data)
{
	if(!data || data->empty()) return 0;
	return proofwrite(*data);
}
Example #24
0
//-----------------------------------------------------------------------------
void OpenMpAssembler::assemble_cells(
  GenericTensor& A, const Form& a,
  UFC& _ufc,
  std::shared_ptr<const MeshFunction<std::size_t>> domains,
  std::vector<double>* values)
{
  // Skip assembly if there are no cell integrals
  if (!_ufc.form.has_cell_integrals())
    return;

  Timer timer("Assemble cells");

  // Set number of OpenMP threads (from parameter systems)
  const std::size_t num_threads = parameters["num_threads"];
  omp_set_num_threads(num_threads);

  // Extract mesh
  const Mesh& mesh = a.mesh();

  // FIXME: Check that UFC copy constructor is dealing with copying
  // pointers correctly
  // Dummy UFC object since each thread needs to created its own UFC object
  UFC ufc(_ufc);

  // Form rank
  const std::size_t form_rank = ufc.form.rank();

  // Cell integral
  const ufc::cell_integral* integral = ufc.default_cell_integral.get();

  // Check whether integral is domain-dependent
  bool use_domains = domains && !domains->empty();

  // Collect pointers to dof maps
  std::vector<const GenericDofMap*> dofmaps;
  for (std::size_t i = 0; i < form_rank; ++i)
    dofmaps.push_back(a.function_space(i)->dofmap().get());

  // Vector to hold dof map for a cell
  std::vector<ArrayView<const dolfin::la_index>> dofs(form_rank);

  // Color mesh
  std::vector<std::size_t> coloring_type = a.coloring(mesh.topology().dim());
  mesh.color(coloring_type);

  // Get coloring data
  std::map<const std::vector<std::size_t>,
           std::pair<std::vector<std::size_t>,
                     std::vector<std::vector<std::size_t>>>>::const_iterator
    mesh_coloring;
  mesh_coloring = mesh.topology().coloring.find(coloring_type);
  if (mesh_coloring == mesh.topology().coloring.end())
  {
    dolfin_error("OpenMPAssembler.cpp",
                 "perform multithreaded assembly using OpenMP assembler",
                 "Requested mesh coloring has not been computed");
  }

  // Get coloring data
  const std::vector<std::vector<std::size_t>>& entities_of_color
    = mesh_coloring->second.second;

  // If assembling a scalar we need to ensure each threads assemble
  // its own scalar
  std::vector<double> scalars(num_threads, 0.0);

  // Assemble over cells (loop over colours, then cells of same color)
  const std::size_t num_colors = entities_of_color.size();
  Progress p("Assembling cells (threaded)", num_colors);
  for (std::size_t color = 0; color < num_colors; ++color)
  {
    // Get the array of cell indices of current color
    const std::vector<std::size_t>& colored_cells = entities_of_color[color];

    // Number of cells of current color
    const int num_cells = colored_cells.size();

    ufc::cell ufc_cell;
    std::vector<double> vertex_coordinates;

    // OpenMP test loop over cells of the same color
#pragma omp parallel for schedule(guided, 20) firstprivate(ufc, ufc_cell, vertex_coordinates, dofs, integral)
    for (int cell_index = 0; cell_index < num_cells; ++cell_index)
    {
      // Cell index
      const std::size_t index = colored_cells[cell_index];

      // Create cell
      const Cell cell(mesh, index);

      // Get integral for sub domain (if any)
      if (use_domains)
        integral = ufc.get_cell_integral((*domains)[cell]);

      // Skip integral if zero
      if (!integral)
        continue;

      // Update to current cell
      cell.get_cell_data(ufc_cell);
      cell.get_vertex_coordinates(vertex_coordinates);
      ufc.update(cell, vertex_coordinates, ufc_cell,
                 integral->enabled_coefficients());

      // Get local-to-global dof maps for cell
      for (std::size_t i = 0; i < form_rank; ++i)
        dofs[i] = dofmaps[i]->cell_dofs(index);

      // Tabulate cell tensor
      integral->tabulate_tensor(ufc.A.data(),
                                ufc.w(),
                                vertex_coordinates.data(),
                                ufc_cell.orientation);

      // Add entries to global tensor
      if (values && form_rank == 0)
        (*values)[cell_index] = ufc.A[0];
      else if (form_rank == 0)
        scalars[omp_get_thread_num()] += ufc.A[0];
      else
        A.add_local(ufc.A.data(), dofs);
    }
    p++;
  }

  // If we assemble a scalar we need to sum the contributions from each thread
  if (form_rank == 0)
  {
    const double scalar_sum = std::accumulate(scalars.begin(), scalars.end(),
                                              0.0);
    A.add_local(&scalar_sum, dofs);
  }
}
Example #25
0
//-----------------------------------------------------------------------------
void Assembler::assemble_vertices(
  GenericTensor& A,
  const Form& a,
  UFC& ufc,
  std::shared_ptr<const MeshFunction<std::size_t>> domains)
{
  // Skip assembly if there are no point integrals
  if (!ufc.form.has_vertex_integrals())
    return;

  // Set timer
  Timer timer("Assemble vertices");

  // Extract mesh
  const Mesh& mesh = a.mesh();

  // Compute cell and vertex - cell connectivity if not already
  // computed
  const std::size_t D = mesh.topology().dim();
  mesh.init(0);
  mesh.init(0, D);
  dolfin_assert(mesh.ordered());

  // Logics for shared vertices
  const bool has_shared_vertices = mesh.topology().have_shared_entities(0);
  const std::map<unsigned int, std::set<unsigned int>>&
    shared_vertices = mesh.topology().shared_entities(0);

  // Form rank
  const std::size_t form_rank = ufc.form.rank();

  // Collect pointers to dof maps
  std::vector<const GenericDofMap*> dofmaps(form_rank);

  // Create a vector for storying local to local map for vertex entity
  // dofs
  std::vector<std::vector<std::size_t>> local_to_local_dofs(form_rank);

  // Create a values vector to be used to fan out local tabulated
  // values to the global tensor
  std::vector<double> local_values(1);

  // Vector to hold local dof map for a vertex
  std::vector<std::vector<dolfin::la_index>> global_dofs(form_rank);
  std::vector<ArrayView<const dolfin::la_index>> global_dofs_p(form_rank);
  std::vector<dolfin::la_index> local_dof_size(form_rank);
  for (std::size_t i = 0; i < form_rank; ++i)
  {
    dofmaps[i] = a.function_space(i)->dofmap().get();

    // Check that the test and trial space as dofs on the vertices
    if (dofmaps[i]->num_entity_dofs(0) == 0)
    {
      dolfin_error("Assembler.cpp",
                   "assemble form over vertices",
                   "Expecting test and trial spaces to have dofs on "\
                   "vertices for point integrals");
    }

    // Check that the test and trial spaces do not have dofs other
    // than on vertices
    for (std::size_t j = 1; j <= D; j++)
    {
      if (dofmaps[i]->num_entity_dofs(j)!=0)
      {
        dolfin_error("Assembler.cpp",
                     "assemble form over vertices",
                     "Expecting test and trial spaces to only have dofs on " \
                     "vertices for point integrals");
      }
    }

    // Resize local values so it can hold dofs on one vertex
    local_values.resize(local_values.size()*dofmaps[i]->num_entity_dofs(0));

    // Resize local to local map according to the number of vertex
    // entities dofs
    local_to_local_dofs[i].resize(dofmaps[i]->num_entity_dofs(0));

    // Resize local dof map vector
    global_dofs[i].resize(dofmaps[i]->num_entity_dofs(0));

    // Get size of local dofs
    local_dof_size[i] = dofmaps[i]->ownership_range().second
      - dofmaps[i]->ownership_range().first;

    // Get pointer to global dofs
    global_dofs_p[i].set(global_dofs[i]);
  }

  // Vector to hold dof map for a cell
  std::vector<ArrayView<const dolfin::la_index>> dofs(form_rank);

  // Exterior point integral
  const ufc::vertex_integral* integral
    = ufc.default_vertex_integral.get();

  // Check whether integral is domain-dependent
  bool use_domains = domains && !domains->empty();

  // MPI rank
  const unsigned int my_mpi_rank = MPI::rank(mesh.mpi_comm());

  // Assemble over vertices
  ufc::cell ufc_cell;
  std::vector<double> coordinate_dofs;
  Progress p(AssemblerBase::progress_message(A.rank(), "vertices"),
             mesh.num_vertices());
  for (VertexIterator vert(mesh); !vert.end(); ++vert)
  {
    // Get integral for sub domain (if any)
    if (use_domains)
      integral = ufc.get_vertex_integral((*domains)[*vert]);

    // Skip integral if zero
    if (!integral)
      continue;

    // Check if assembling a scalar and a vertex is shared
    if (form_rank == 0 && has_shared_vertices)
    {
      // Find shared processes for this global vertex
      std::map<unsigned int, std::set<unsigned int>>::const_iterator e;
      e = shared_vertices.find(vert->index());

      // If vertex is shared and this rank is not the lowest do not
      // include the contribution from this vertex to scalar sum
      if (e != shared_vertices.end())
      {
        bool skip_vertex = false;
        std::set<unsigned int>::const_iterator it;
        for (it = e->second.begin(); it != e->second.end(); it++)
        {
          // Check if a shared vertex has a lower process rank
          if (*it < my_mpi_rank)
          {
            skip_vertex = true;
            break;
          }
        }

        if (skip_vertex)
          continue;
      }
    }

    // Get mesh cell to which mesh vertex belongs (pick first)
    Cell mesh_cell(mesh, vert->entities(D)[0]);

    // Check that cell is not a ghost
    dolfin_assert(!mesh_cell.is_ghost());

    // Get local index of vertex with respect to the cell
    const std::size_t local_vertex = mesh_cell.index(*vert);

    // Update UFC cell
    mesh_cell.get_cell_data(ufc_cell);
    mesh_cell.get_coordinate_dofs(coordinate_dofs);

    // Update UFC object
    ufc.update(mesh_cell, coordinate_dofs, ufc_cell,
               integral->enabled_coefficients());

    // Tabulate vertex tensor
    integral->tabulate_tensor(ufc.A.data(),
                              ufc.w(),
                              coordinate_dofs.data(),
                              local_vertex,
                              ufc_cell.orientation);

    // For rank 1 and 2 tensors we need to check if tabulated dofs for
    // the test space is within the local range
    bool owns_all_dofs = true;
    for (std::size_t i = 0; i < form_rank; ++i)
    {
      // Get local-to-global dof maps for cell
      dofs[i] = dofmaps[i]->cell_dofs(mesh_cell.index());

      // Get local dofs of the local vertex
      dofmaps[i]->tabulate_entity_dofs(local_to_local_dofs[i], 0, local_vertex);

      // Copy cell dofs to local dofs and check owner ship range
      for (std::size_t j = 0; j < local_to_local_dofs[i].size(); ++j)
      {
        global_dofs[i][j] = dofs[i][local_to_local_dofs[i][j]];

        // It is the dofs for the test space that determines if a dof
        // is owned by a process, therefore i==0
        if (i == 0 && global_dofs[i][j] >= local_dof_size[i])
        {
          owns_all_dofs = false;
          break;
        }
      }
    }

    // If not owning all dofs
    if (!owns_all_dofs)
      continue;

    // Scalar
    if (form_rank == 0)
    {
      // Add entries to global tensor
      A.add_local(ufc.A.data(), dofs);
    }
    else if (form_rank == 1)
    {
      // Copy tabulated tensor to local value vector
      for (std::size_t i = 0; i < local_to_local_dofs[0].size(); ++i)
        local_values[i] = ufc.A[local_to_local_dofs[0][i]];

      // Add local entries to global tensor
      A.add_local(local_values.data(), global_dofs_p);
    }
    else
    {
      // Copy tabulated tensor to local value vector
      const std::size_t num_cols = dofs[1].size();
      for (std::size_t i = 0; i < local_to_local_dofs[0].size(); ++i)
      {
        for (std::size_t j = 0; j < local_to_local_dofs[1].size(); ++j)
        {
          local_values[i*local_to_local_dofs[1].size() + j]
            = ufc.A[local_to_local_dofs[0][i]*num_cols
                    + local_to_local_dofs[1][j]];
        }
      }

      // Add local entries to global tensor
      A.add_local(local_values.data(), global_dofs_p);
    }

    p++;
  }
}
Example #26
0
//-----------------------------------------------------------------------------
void Assembler::assemble_interior_facets(
  GenericTensor& A,
  const Form& a,
  UFC& ufc,
  std::shared_ptr<const MeshFunction<std::size_t>> domains,
  std::shared_ptr<const MeshFunction<std::size_t>> cell_domains,
  std::vector<double>* values)
{
  // Skip assembly if there are no interior facet integrals
  if (!ufc.form.has_interior_facet_integrals())
    return;

  // Set timer
  Timer timer("Assemble interior facets");

  // Extract mesh and coefficients
  const Mesh& mesh = a.mesh();

  // MPI rank
  const int my_mpi_rank = MPI::rank(mesh.mpi_comm());

  // Form rank
  const std::size_t form_rank = ufc.form.rank();

  // Collect pointers to dof maps
  std::vector<const GenericDofMap*> dofmaps;
  for (std::size_t i = 0; i < form_rank; ++i)
    dofmaps.push_back(a.function_space(i)->dofmap().get());

  // Vector to hold dofs for cells, and a vector holding pointers to same
  std::vector<std::vector<dolfin::la_index>> macro_dofs(form_rank);
  std::vector<ArrayView<const dolfin::la_index>> macro_dof_ptrs(form_rank);

  // Interior facet integral
  const ufc::interior_facet_integral* integral
    = ufc.default_interior_facet_integral.get();

  // Check whether integral is domain-dependent
  bool use_domains = domains && !domains->empty();
  bool use_cell_domains = cell_domains && !cell_domains->empty();

  // Compute facets and facet - cell connectivity if not already computed
  const std::size_t D = mesh.topology().dim();
  mesh.init(D - 1);
  mesh.init(D - 1, D);
  dolfin_assert(mesh.ordered());

  // Assemble over interior facets (the facets of the mesh)
  ufc::cell ufc_cell[2];
  std::vector<double> coordinate_dofs[2];
  Progress p(AssemblerBase::progress_message(A.rank(), "interior facets"),
             mesh.num_facets());
  for (FacetIterator facet(mesh); !facet.end(); ++facet)
  {
    if (facet->num_entities(D) == 1)
      continue;

    // Check that facet is not a ghost
    dolfin_assert(!facet->is_ghost());

    // Get integral for sub domain (if any)
    if (use_domains)
      integral = ufc.get_interior_facet_integral((*domains)[*facet]);

    // Skip integral if zero
    if (!integral)
      continue;

    // Get cells incident with facet (which is 0 and 1 here is arbitrary)
    dolfin_assert(facet->num_entities(D) == 2);
    std::size_t cell_index_plus = facet->entities(D)[0];
    std::size_t cell_index_minus = facet->entities(D)[1];

    if (use_cell_domains && (*cell_domains)[cell_index_plus]
        < (*cell_domains)[cell_index_minus])
    {
      std::swap(cell_index_plus, cell_index_minus);
    }

    // The convention '+' = 0, '-' = 1 is from ffc
    const Cell cell0(mesh, cell_index_plus);
    const Cell cell1(mesh, cell_index_minus);

    // Get local index of facet with respect to each cell
    std::size_t local_facet0 = cell0.index(*facet);
    std::size_t local_facet1 = cell1.index(*facet);

    // Update to current pair of cells
    cell0.get_cell_data(ufc_cell[0], local_facet0);
    cell0.get_coordinate_dofs(coordinate_dofs[0]);
    cell1.get_cell_data(ufc_cell[1], local_facet1);
    cell1.get_coordinate_dofs(coordinate_dofs[1]);

    ufc.update(cell0, coordinate_dofs[0], ufc_cell[0],
               cell1, coordinate_dofs[1], ufc_cell[1],
               integral->enabled_coefficients());

    // Tabulate dofs for each dimension on macro element
    for (std::size_t i = 0; i < form_rank; i++)
    {
      // Get dofs for each cell
      const ArrayView<const dolfin::la_index> cell_dofs0
        = dofmaps[i]->cell_dofs(cell0.index());
      const ArrayView<const dolfin::la_index> cell_dofs1
        = dofmaps[i]->cell_dofs(cell1.index());

      // Create space in macro dof vector
      macro_dofs[i].resize(cell_dofs0.size() + cell_dofs1.size());

      // Copy cell dofs into macro dof vector
      std::copy(cell_dofs0.data(), cell_dofs0.data() + cell_dofs0.size(),
                macro_dofs[i].begin());
      std::copy(cell_dofs1.data(), cell_dofs1.data() + cell_dofs1.size(),
                macro_dofs[i].begin() + cell_dofs0.size());
      macro_dof_ptrs[i].set(macro_dofs[i]);
    }

    // Tabulate interior facet tensor on macro element
    integral->tabulate_tensor(ufc.macro_A.data(),
                              ufc.macro_w(),
                              coordinate_dofs[0].data(),
                              coordinate_dofs[1].data(),
                              local_facet0,
                              local_facet1,
                              ufc_cell[0].orientation,
                              ufc_cell[1].orientation);

    if (cell0.is_ghost() != cell1.is_ghost())
    {
      int ghost_rank = -1;
      if (cell0.is_ghost())
        ghost_rank = cell0.owner();
      else
        ghost_rank = cell1.owner();

      dolfin_assert(my_mpi_rank != ghost_rank);
      dolfin_assert(ghost_rank != -1);
      if (ghost_rank < my_mpi_rank)
        continue;
    }

    // Add entries to global tensor
    A.add_local(ufc.macro_A.data(), macro_dof_ptrs);

    p++;
  }
}
Example #27
0
//-----------------------------------------------------------------------------
void Assembler::assemble_exterior_facets(
  GenericTensor& A,
  const Form& a,
  UFC& ufc,
  std::shared_ptr<const MeshFunction<std::size_t>> domains,
  std::vector<double>* values)
{
  // Skip assembly if there are no exterior facet integrals
  if (!ufc.form.has_exterior_facet_integrals())
    return;

  // Set timer
  Timer timer("Assemble exterior facets");

  // Extract mesh
  const Mesh& mesh = a.mesh();

  // Form rank
  const std::size_t form_rank = ufc.form.rank();

  // Collect pointers to dof maps
  std::vector<const GenericDofMap*> dofmaps;
  for (std::size_t i = 0; i < form_rank; ++i)
    dofmaps.push_back(a.function_space(i)->dofmap().get());

  // Vector to hold dof map for a cell
  std::vector<ArrayView<const dolfin::la_index>> dofs(form_rank);

  // Exterior facet integral
  const ufc::exterior_facet_integral* integral
    = ufc.default_exterior_facet_integral.get();

  // Check whether integral is domain-dependent
  bool use_domains = domains && !domains->empty();

  // Compute facets and facet - cell connectivity if not already computed
  const std::size_t D = mesh.topology().dim();
  mesh.init(D - 1);
  mesh.init(D - 1, D);
  dolfin_assert(mesh.ordered());

  // Assemble over exterior facets (the cells of the boundary)
  ufc::cell ufc_cell;
  std::vector<double> coordinate_dofs;
  Progress p(AssemblerBase::progress_message(A.rank(), "exterior facets"),
             mesh.num_facets());
  for (FacetIterator facet(mesh); !facet.end(); ++facet)
  {
    // Only consider exterior facets
    if (!facet->exterior())
    {
      p++;
      continue;
    }

    // Get integral for sub domain (if any)
    if (use_domains)
      integral = ufc.get_exterior_facet_integral((*domains)[*facet]);

    // Skip integral if zero
    if (!integral)
      continue;

    // Get mesh cell to which mesh facet belongs (pick first, there is
    // only one)
    dolfin_assert(facet->num_entities(D) == 1);
    Cell mesh_cell(mesh, facet->entities(D)[0]);

    // Check that cell is not a ghost
    dolfin_assert(!mesh_cell.is_ghost());

    // Get local index of facet with respect to the cell
    const std::size_t local_facet = mesh_cell.index(*facet);

    // Update UFC cell
    mesh_cell.get_cell_data(ufc_cell, local_facet);
    mesh_cell.get_coordinate_dofs(coordinate_dofs);

    // Update UFC object
    ufc.update(mesh_cell, coordinate_dofs, ufc_cell,
               integral->enabled_coefficients());

    // Get local-to-global dof maps for cell
    for (std::size_t i = 0; i < form_rank; ++i)
      dofs[i] = dofmaps[i]->cell_dofs(mesh_cell.index());

    // Tabulate exterior facet tensor
    integral->tabulate_tensor(ufc.A.data(),
                              ufc.w(),
                              coordinate_dofs.data(),
                              local_facet,
                              ufc_cell.orientation);

    // Add entries to global tensor
    A.add_local(ufc.A.data(), dofs);

    p++;
  }
}
Example #28
0
//-----------------------------------------------------------------------------
void Assembler::assemble_cells(
  GenericTensor& A,
  const Form& a,
  UFC& ufc,
  std::shared_ptr<const MeshFunction<std::size_t>> domains,
  std::vector<double>* values)
{
  // Skip assembly if there are no cell integrals
  if (!ufc.form.has_cell_integrals())
    return;

  // Set timer
  Timer timer("Assemble cells");

  // Extract mesh
  const Mesh& mesh = a.mesh();

  // Form rank
  const std::size_t form_rank = ufc.form.rank();

  // Check if form is a functional
  const bool is_cell_functional = (values && form_rank == 0) ? true : false;

  // Collect pointers to dof maps
  std::vector<const GenericDofMap*> dofmaps;
  for (std::size_t i = 0; i < form_rank; ++i)
    dofmaps.push_back(a.function_space(i)->dofmap().get());

  // Vector to hold dof map for a cell
  std::vector<ArrayView<const dolfin::la_index>> dofs(form_rank);

  // Cell integral
  ufc::cell_integral* integral = ufc.default_cell_integral.get();

  // Check whether integral is domain-dependent
  bool use_domains = domains && !domains->empty();

  // Assemble over cells
  ufc::cell ufc_cell;
  std::vector<double> coordinate_dofs;
  Progress p(AssemblerBase::progress_message(A.rank(), "cells"),
             mesh.num_cells());
  for (CellIterator cell(mesh); !cell.end(); ++cell)
  {
    // Get integral for sub domain (if any)
    if (use_domains)
      integral = ufc.get_cell_integral((*domains)[*cell]);

    // Skip if no integral on current domain
    if (!integral)
      continue;

    // Check that cell is not a ghost
    dolfin_assert(!cell->is_ghost());

    // Update to current cell
    cell->get_cell_data(ufc_cell);
    cell->get_coordinate_dofs(coordinate_dofs);
    ufc.update(*cell, coordinate_dofs, ufc_cell,
               integral->enabled_coefficients());

    // Get local-to-global dof maps for cell
    bool empty_dofmap = false;
    for (std::size_t i = 0; i < form_rank; ++i)
    {
      dofs[i] = dofmaps[i]->cell_dofs(cell->index());
      empty_dofmap = empty_dofmap || dofs[i].size() == 0;
    }

    // Skip if at least one dofmap is empty
    if (empty_dofmap)
      continue;

    // Tabulate cell tensor
    integral->tabulate_tensor(ufc.A.data(), ufc.w(),
                              coordinate_dofs.data(),
                              ufc_cell.orientation);

    // Add entries to global tensor. Either store values cell-by-cell
    // (currently only available for functionals)
    if (is_cell_functional)
      (*values)[cell->index()] = ufc.A[0];
    else
      A.add_local(ufc.A.data(), dofs);

    p++;
  }
}
Example #29
0
//-----------------------------------------------------------------------------
void OpenMpAssembler::assemble_cells_and_exterior_facets(
  GenericTensor& A,
  const Form& a, UFC& _ufc,
  std::shared_ptr<const MeshFunction<std::size_t>> cell_domains,
  std::shared_ptr<const MeshFunction<std::size_t>> exterior_facet_domains,
  std::vector<double>* values)
{
  Timer timer("Assemble cells and exterior facets");

  // Set number of OpenMP threads (from parameter systems)
  const int num_threads = parameters["num_threads"];
  omp_set_num_threads(num_threads);

  // Extract mesh
  const Mesh& mesh = a.mesh();

  // Compute facets and facet - cell connectivity if not already computed
  const std::size_t D = mesh.topology().dim();
  mesh.init(D - 1);
  mesh.init(D - 1, D);
  dolfin_assert(mesh.ordered());

  // Get connectivity
  const MeshConnectivity& connectivity = mesh.topology()(D, D - 1);
  dolfin_assert(!connectivity.empty());

  // Dummy UFC object since each thread needs to created its own UFC object
  UFC ufc(_ufc);

  // Form rank
  const std::size_t form_rank = ufc.form.rank();

  // Cell and facet integrals
  ufc::cell_integral* cell_integral = ufc.default_cell_integral.get();
  ufc::exterior_facet_integral* facet_integral
    = ufc.default_exterior_facet_integral.get();

  // Check whether integrals are domain-dependent
  bool use_cell_domains = cell_domains && !cell_domains->empty();
  bool use_exterior_facet_domains
    = exterior_facet_domains && !exterior_facet_domains->empty();

  // Collect pointers to dof maps
  std::vector<const GenericDofMap*> dofmaps;
  for (std::size_t i = 0; i < form_rank; ++i)
    dofmaps.push_back(a.function_space(i)->dofmap().get());

  // Vector to hold dof maps for a cell
  std::vector<ArrayView<const dolfin::la_index>> dofs(form_rank);

  // FIXME: Pass or determine coloring type
  // Define graph type
  std::vector<std::size_t> coloring_type = a.coloring(mesh.topology().dim());
  mesh.color(coloring_type);

  // Get coloring data
  std::map<const std::vector<std::size_t>,
           std::pair<std::vector<std::size_t>,
                     std::vector<std::vector<std::size_t>>>>::const_iterator
    mesh_coloring;
  mesh_coloring = mesh.topology().coloring.find(coloring_type);
  if (mesh_coloring == mesh.topology().coloring.end())
  {
    dolfin_error("OpenMPAssembler.cpp",
                 "perform multithreaded assembly using OpenMP assembler",
                 "Requested mesh coloring has not been computed");
  }

  // Get coloring data
  const std::vector<std::vector<std::size_t>>& entities_of_color
  = mesh_coloring->second.second;

  // If assembling a scalar we need to ensure each threads assemble
  // its own scalar
  std::vector<double> scalars(num_threads, 0.0);

  // UFC cell and vertex coordinates
  ufc::cell ufc_cell;
  std::vector<double> vertex_coordinates;

  // Assemble over cells (loop over colors, then cells of same color)
  const std::size_t num_colors = entities_of_color.size();
  for (std::size_t color = 0; color < num_colors; ++color)
  {
    // Get the array of cell indices of current color
    const std::vector<std::size_t>& colored_cells = entities_of_color[color];

    // Number of cells of current color
    const int num_cell_in_color = colored_cells.size();

    // OpenMP test loop over cells of the same color
    Progress p(AssemblerBase::progress_message(A.rank(), "cells"), num_colors);
#pragma omp parallel for schedule(guided, 20) firstprivate(ufc, ufc_cell, vertex_coordinates, dofs, cell_integral, facet_integral)
    for (int index = 0; index < num_cell_in_color; ++index)
    {
      // Cell index
      const std::size_t cell_index = colored_cells[index];

      // Create cell
      const Cell cell(mesh, cell_index);

      // Get integral for sub domain (if any)
      if (use_cell_domains)
        cell_integral = ufc.get_cell_integral((*cell_domains)[cell_index]);

      // Update to current cell
      cell.get_cell_data(ufc_cell);
      cell.get_vertex_coordinates(vertex_coordinates);

      // Get local-to-global dof maps for cell
      for (std::size_t i = 0; i < form_rank; ++i)
        dofs[i] = dofmaps[i]->cell_dofs(cell_index);

      // Get number of entries in cell tensor
      std::size_t dim = 1;
      for (std::size_t i = 0; i < form_rank; ++i)
        dim *= dofs[i].size();

      // Tabulate cell tensor if we have a cell_integral
      if (cell_integral)
      {
        ufc.update(cell, vertex_coordinates, ufc_cell,
                   cell_integral->enabled_coefficients());
        cell_integral->tabulate_tensor(ufc.A.data(),
                                       ufc.w(),
                                       vertex_coordinates.data(),
                                       ufc_cell.orientation);
      }
      else
        std::fill(ufc.A.begin(), ufc.A.end(), 0.0);

      // Assemble over external facet
      for (FacetIterator facet(cell); !facet.end(); ++facet)
      {
        // Only consider exterior facets
        if (!facet->exterior())
        {
          p++;
          continue;
        }

        // Get local facet index
        const std::size_t local_facet = cell.index(*facet);

        // Get integral for sub domain (if any)
        if (use_exterior_facet_domains)
        {
          // Get global facet index
          const std::size_t facet_index = connectivity(cell_index)[local_facet];
          facet_integral = ufc.get_exterior_facet_integral((*exterior_facet_domains)[facet_index]);
        }

        // Skip integral if zero
        if (!facet_integral)
          continue;

        // FIXME: Do we really need an update version with the local
        //        facet index?
        // Update UFC object
        ufc_cell.local_facet = local_facet;
        ufc.update(cell, vertex_coordinates, ufc_cell,
                  facet_integral->enabled_coefficients());

        // Tabulate tensor
        facet_integral->tabulate_tensor(ufc.A_facet.data(),
                                        ufc.w(),
                                        vertex_coordinates.data(),
                                        local_facet,
                                        ufc_cell.orientation);

        // Add facet contribution
        for (std::size_t i = 0; i < dim; ++i)
          ufc.A[i] += ufc.A_facet[i];
      }

      // Add entries to global tensor
      if (values && form_rank == 0)
        (*values)[cell_index] = ufc.A[0];
      else if (form_rank == 0)
        scalars[omp_get_thread_num()] += ufc.A[0];
      else
        A.add_local(&ufc.A[0], dofs);
    }

    p++;
  }

  // If we assemble a scalar we need to sum the contributions from each thread
  if (form_rank == 0)
  {
    const double scalar_sum = std::accumulate(scalars.begin(),
                                              scalars.end(), 0.0);
    A.add_local(&scalar_sum, dofs);
  }
}
Example #30
0
  void FAT::traverse(std::shared_ptr<Path> path, cluster_func callback)
  {
    // parse this path into a stack of memes
    typedef std::function<void(uint32_t)> next_func_t;

    // asynch stack traversal
    auto next = std::make_shared<next_func_t> ();
    auto weak_next = std::weak_ptr<next_func_t>(next);
    *next =
    [this, path, weak_next, callback] (uint32_t cluster) {

      if (path->empty()) {
        // attempt to read directory
        uint32_t S = this->cl_to_sector(cluster);

        // result allocated on heap
        auto dirents = std::make_shared<std::vector<Dirent>> ();

        int_ls(S, dirents,
        [callback] (error_t error, dirvec_t ents) {
          callback(error, ents);
        });
        return;
      }

      // retrieve next name
      std::string name = path->front();
      path->pop_front();

      uint32_t S = this->cl_to_sector(cluster);
      debug("Current target: %s on cluster %u (sector %u)\n", name.c_str(), cluster, S);

      // result allocated on heap
      auto dirents = std::make_shared<std::vector<Dirent>> ();

      auto next = weak_next.lock();
      // list directory contents
      int_ls(S, dirents,
      [name, dirents, next, callback] (error_t err, dirvec_t ents) {

        if (unlikely(err)) {
          debug("Could not find: %s\n", name.c_str());
          callback(err, dirents);
          return;
        }

        // look for name in directory
        for (auto& e : *ents) {
          if (unlikely(e.name() == name)) {
            // go to this directory, unless its the last name
            debug("Found match for %s", name.c_str());
            // enter the matching directory
            debug("\t\t cluster: %llu\n", e.block);
            // only follow directories
            if (e.type() == DIR)
              (*next)(e.block);
            else
              callback({ error_t::E_NOTDIR, e.name() }, dirents);
            return;
          }
        } // for (ents)

        debug("NO MATCH for %s\n", name.c_str());
        callback({ error_t::E_NOENT, name }, dirents);
      });

    };
    // start by reading root directory
    (*next)(0);
  }