Commit 2798ed59 authored by Christophe Geuzaine's avatar Christophe Geuzaine

fill vertex arrays in parallel (ok 3x speedup on quadcore for 120M tet mesh)

parent 2cb901b6
Pipeline #3020 passed with stage
in 56 minutes and 46 seconds
......@@ -109,7 +109,7 @@ void smooth_data::add_scale(double x, double y, double z, double scale_val)
}
}
bool smooth_data::get(double x, double y, double z, int n, double *vals)
bool smooth_data::get(double x, double y, double z, int n, double *vals) const
{
std::set<xyzv, lessthanxyzv>::const_iterator it = c.find(xyzv(x, y, z));
if(it == c.end()) return false;
......@@ -118,7 +118,7 @@ bool smooth_data::get(double x, double y, double z, int n, double *vals)
}
// added by Trevor Strickler
bool smooth_data::get_scale(double x, double y, double z, double *scale_val)
bool smooth_data::get_scale(double x, double y, double z, double *scale_val) const
{
std::set<xyzv, lessthanxyzv>::const_iterator it = c.find(xyzv(x, y, z));
if(it == c.end()) return false;
......@@ -135,12 +135,12 @@ void smooth_data::normalize()
}
}
bool smooth_data::exportview(const std::string &filename)
bool smooth_data::exportview(const std::string &filename) const
{
FILE *fp = Fopen(filename.c_str(), "w");
if(!fp) return false;
fprintf(fp, "View \"data\" {\n");
std::set<xyzv, lessthanxyzv>::iterator it = c.begin();
std::set<xyzv, lessthanxyzv>::const_iterator it = c.begin();
while(it != c.end()) {
switch(it->nbvals) {
case 1:
......@@ -232,7 +232,7 @@ void smooth_normals::add(double x, double y, double z, double nx, double ny,
}
bool smooth_normals::get(double x, double y, double z, double &nx, double &ny,
double &nz)
double &nz) const
{
std::set<xyzn, lessthanxyzn>::const_iterator it =
c.find(xyzn((float)x, (float)y, (float)z));
......
......@@ -60,13 +60,11 @@ public:
iter end() { return c.end(); }
smooth_data() {}
void add(double x, double y, double z, int n, double *vals);
bool get(double x, double y, double z, int n, double *vals);
void add_scale(double x, double y, double z,
double scale_val); // Trevor Strickler
bool get_scale(double x, double y, double z,
double *scale_val); // Trevor Strickler
bool get(double x, double y, double z, int n, double *vals) const;
void add_scale(double x, double y, double z, double scale_val);
bool get_scale(double x, double y, double z, double *scale_val) const;
void normalize();
bool exportview(const std::string &filename);
bool exportview(const std::string &filename) const;
};
// Normal smoother with threshold (saves memory by storing normals as
......@@ -107,7 +105,7 @@ private:
public:
smooth_normals(double angle) : tol((float)angle) {}
void add(double x, double y, double z, double nx, double ny, double nz);
bool get(double x, double y, double z, double &nx, double &ny, double &nz);
bool get(double x, double y, double z, double &nx, double &ny, double &nz) const;
};
#endif
......@@ -190,6 +190,9 @@ template <class T>
static void addElementsInArrays(GEntity *e, std::vector<T *> &elements,
bool edges, bool faces)
{
#if defined(_OPENMP)
#pragma omp parallel for schedule(dynamic)
#endif
for(unsigned int i = 0; i < elements.size(); i++) {
MElement *ele = elements[i];
......@@ -222,7 +225,12 @@ static void addElementsInArrays(GEntity *e, std::vector<T *> &elements,
for(int k = 0; k < 2; k++)
e->model()->normals->get(x[k], y[k], z[k], n[k][0], n[k][1],
n[k][2]);
e->va_lines->add(x, y, z, n, col, ele, unique);
#if defined(_OPENMP)
#pragma omp critical
#endif
{
e->va_lines->add(x, y, z, n, col, ele, unique);
}
}
}
......@@ -244,7 +252,12 @@ static void addElementsInArrays(GEntity *e, std::vector<T *> &elements,
for(int k = 0; k < 3; k++)
e->model()->normals->get(x[k], y[k], z[k], n[k][0], n[k][1],
n[k][2]);
e->va_triangles->add(x, y, z, n, col, ele, unique, skin);
#if defined(_OPENMP)
#pragma omp critical
#endif
{
e->va_triangles->add(x, y, z, n, col, ele, unique, skin);
}
}
}
}
......@@ -329,8 +342,8 @@ public:
if(edg || fac) {
_curved = (areSomeElementsCurved(f->triangles) ||
areSomeElementsCurved(f->quadrangles));
f->va_lines = new VertexArray(2, edg ? _estimateNumLines(f) : 1000);
f->va_triangles = new VertexArray(3, fac ? _estimateNumTriangles(f) : 1000);
f->va_lines = new VertexArray(2, edg ? _estimateNumLines(f) : 100);
f->va_triangles = new VertexArray(3, fac ? _estimateNumTriangles(f) : 100);
if(CTX::instance()->mesh.triangles)
addElementsInArrays(f, f->triangles, edg, fac);
if(CTX::instance()->mesh.quadrangles)
......@@ -413,8 +426,8 @@ public:
areSomeElementsCurved(r->prisms) ||
areSomeElementsCurved(r->pyramids) ||
areSomeElementsCurved(r->trihedra));
r->va_lines = new VertexArray(2, edg ? _estimateNumLines(r) : 1000);
r->va_triangles = new VertexArray(3, fac ? _estimateNumTriangles(r) : 1000);
r->va_lines = new VertexArray(2, edg ? _estimateNumLines(r) : 100);
r->va_triangles = new VertexArray(3, fac ? _estimateNumTriangles(r) : 100);
if(CTX::instance()->mesh.tetrahedra)
addElementsInArrays(r, r->tetrahedra, edg, fac);
if(CTX::instance()->mesh.hexahedra)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment