Is it possible to add points, lines, curveloops, and planesurfaces in parallel?
Hi. I am using GMSH CXX API now. Can we add points, lines, curveloops, and planesurfaces in parallel?
A small example is below. I randomly generate 3D triangles in a box, and use occ
mode to generate conforming mesh. When I set the variable nproc > 1
, I get Segmentation Fault
. The reason why I want to do that is that I have a large amount of triangles, and I find it is time-consuming to add points and so on. The meshing is very fast after the points, planesurfaces and so on are added.
#include "gmsh.h"
#include <chrono>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <omp.h>
#include <random>
#include <vector>
using namespace std;
int main()
{
std::random_device rd;
std::mt19937::result_type seed = rd() ^ ((std::mt19937::result_type)
std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch())
.count() +
(std::mt19937::result_type)
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count());
std::mt19937 gen(seed);
std::uniform_int_distribution<unsigned> distrib(1, 30);
gmsh::initialize();
gmsh::model::add("t10");
gmsh::option::setNumber("General.Verbosity", 2); // default level is 5
double lc = 0.0;
int Dsize_ = 10;
int nproc = 1; // number of cores
std::vector<std::pair<int, int>> Plane_loop(Dsize_);
#pragma omp parallel for schedule(static) num_threads(nproc)
for (int i = 0; i < Dsize_; ++i)
{
gmsh::model::occ::addPoint(distrib(gen), distrib(gen), distrib(gen), lc, i * 3 + 1);
gmsh::model::occ::addPoint(distrib(gen), distrib(gen), distrib(gen), lc, i * 3 + 2);
gmsh::model::occ::addPoint(distrib(gen), distrib(gen), distrib(gen), lc, i * 3 + 3);
gmsh::model::occ::synchronize();
gmsh::model::occ::addLine(i * 3 + 1, i * 3 + 2, i * 3 + 1);
gmsh::model::occ::addLine(i * 3 + 2, i * 3 + 3, i * 3 + 2);
gmsh::model::occ::addLine(i * 3 + 3, i * 3 + 1, i * 3 + 3);
gmsh::model::occ::synchronize();
std::vector<int> curveloop = {i * 3 + 1, i * 3 + 2, i * 3 + 3};
gmsh::model::occ::addCurveLoop(curveloop, i + 1);
std::vector<int> surfaceloop = {i + 1};
gmsh::model::occ::addPlaneSurface(surfaceloop, i + 1);
gmsh::model::occ::synchronize();
Plane_loop[i].first = 2;
Plane_loop[i].second = i + 1;
}
std::vector<std::pair<int, int>> out;
std::vector<std::vector<std::pair<int, int>>> outmap;
gmsh::model::occ::fragment(Plane_loop, Plane_loop, out, outmap);
gmsh::model::occ::synchronize();
gmsh::option::setNumber("Mesh.MeshSizeMin", 2);
gmsh::option::setNumber("Mesh.MeshSizeMax", 3);
gmsh::option::setNumber("Mesh.Algorithm", 5);
gmsh::model::mesh::generate(2);
gmsh::model::occ::synchronize();
gmsh::fltk::run();
gmsh::clear();
gmsh::finalize();
return 0;
};