<div dir="ltr"><div>Dear Christoph,</div><div><br></div><div>to be honest, a remark deeply hidden somewhere in the documentation wouldn't have helped me.</div><div>That's because my approach typically is not to read the documentation like a book (i.e. from front to back) but rather to skip forwards to the paragraphs I currently need for the implementation.</div><div>I believe most users work in a similar way.<br></div><div>My personal suggestion would be that you "detect" in your backwards-compatible gmsh parser the event where -something-like- more than 1000 CAD-to-topology synchronizations
(or whatever you call it)
are implicitly done. And if this happens, just _FAIL_. This slightly breaks your compatibility, but only in corner cases where performance is too bad for practical purposes anyway. A user may want to override this behavior using a special command line option like "-cad-sync-limit infinity" - in case he thinks otherwise.<br></div><div><br></div><div>Best regards</div><div>A. S.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Do., 31. Jan. 2019 um 15:39 Uhr schrieb Christophe Geuzaine <<a href="mailto:cgeuzaine@uliege.be">cgeuzaine@uliege.be</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
> On 31 Jan 2019, at 15:19, Al Sc <<a href="mailto:al.sc.gmsh@gmail.com" target="_blank">al.sc.gmsh@gmail.com</a>> wrote:<br>
> <br>
> Dear Christophe,<br>
> <br>
> I tried out your gmsh-file with "Point{100+1:100+N} In Volume{1};" and it's indeed much faster!<br>
> That indeed seems to be the solution I needed -- thanks a lot!<br>
> <br>
> As I don't really know much about the internal functionality of gmsh, it would have been almost impossible for me to come up with that solution on my own.<br>
> From your documentation it is clear that the input to gmsh is more than just a geometry specification, and it's rather kind of a script which generates the geometry.<br>
> However, given only the documentation, a naive user like me will conclude that you do not *need* any advanced scripting functionality to generate a basic model. E.g. that you can restrict yourself to "just using the geometry-specification subset of the language" without any performance penalty. Hence, a naive user concludes that:<br>
> " Point{100+1:100+N} In Volume{1};"<br>
> and<br>
> " Point{100} In Volume{1}; ...<br>
> ... Point{10100} In Volume{1};"<br>
> are, in fact, equivalent (not only in semantics, but also in "parser performance").<br>
<br>
They are equivalent. The difference is *when* you call them.<br>
<br>
> <br>
> I'd suggest that you try to implement the model parsing in a way that the "topology structure" is not immediately re-computed, but only invalidated.<br>
> Because, in my opinion, the observed performance-drop of gmsh with repeated "Point In Volume" statements is still highly counter-intuitive, even to users more advanced than me.<br>
> <br>
<br>
Indeed. This is all made clear when you use the API, where the distinction between CAD operations and topological model operations is made explicit. <br>
<br>
For example, if using the Python API you try to do<br>
<br>
for i in range(N):<br>
gmsh.model.occ.addPoint(...)<br>
gmsh.model.mesh.embed(...)<br>
<br>
you will get an error, stating that the point does not exist in the model - since no call to gmsh.model.occ.synchronize() has been made after the point was added to the CAD. To make it work you would then do<br>
<br>
for i in range(N):<br>
gmsh.model.occ.addPoint(...)<br>
gmsh.model.occ.synchronize(...)<br>
gmsh.model.mesh.embed(...)<br>
<br>
When N is large you would rapidly conclude that calling "synchronize" that many times will kill your performance (the API doc makes this explicit).<br>
<br>
The .geo parser strives to be automatic and backward compatible with very old versions of Gmsh. So each "Point ... In ..." command thus checks if the CAD has been modified - and if it has, triggers a synchronization automatically. We could add a note in the documentation about this, by stating explicitly which operations will trigger a sync. I'm adding this to our TODO list.<br>
<br>
Christophe<br>
<br>
<br>
<br>
<br>
> Best regards,<br>
> A.S.<br>
> <br>
> Am Do., 31. Jan. 2019 um 14:53 Uhr schrieb Christophe Geuzaine <<a href="mailto:cgeuzaine@uliege.be" target="_blank">cgeuzaine@uliege.be</a>>:<br>
> <br>
> This was precisely the point of my example: if you embed the point after each point is created, you force a rebuild of the topology of the model. So the efficient script would be<br>
> <br>
> SetFactory("OpenCASCADE");<br>
> Box(1) = {0,0,0, 1,1,1};<br>
> N=10000;<br>
> For i In {1:N}<br>
> Point(100+i) = {0.25 + 5e-5*i, 0.1,0.1};<br>
> EndFor<br>
> Point{100+1:100+N} In Volume{1};<br>
> <br>
> Christophe<br>
> <br>
> <br>
> > On 31 Jan 2019, at 14:48, Al Sc <<a href="mailto:al.sc.gmsh@gmail.com" target="_blank">al.sc.gmsh@gmail.com</a>> wrote:<br>
> > <br>
> > Dear Christophe,<br>
> > <br>
> > my example files are scientific data, however originate from processing certain proprietary 3D models that were shared with me under certain restrictions. Therefore, it's difficult to share my original file with you.<br>
> > However, I was indeed able to reproduce the issue using only a slight modification of your example file!<br>
> > <br>
> > Compare the following two files:<br>
> > test1.geo:<br>
> > %%% %%% %%% %%% %%% %%% %%% %%% %%% %%%<br>
> > SetFactory("OpenCASCADE");<br>
> > Box(1) = {0,0,0, 1,1,1};<br>
> > For i In {1:1000}<br>
> > Point(100+i) = {0.25 + 1e-4*i, 0.1,0.1};<br>
> > Point{100+i} In Volume{1};<br>
> > EndFor<br>
> > %%% %%% %%% %%% %%% %%% %%% %%% %%% %%% <br>
> > <br>
> > test2.geo:<br>
> > %%% %%% %%% %%% %%% %%% %%% %%% %%% %%% <br>
> > SetFactory("OpenCASCADE");<br>
> > Box(1) = {0,0,0, 1,1,1};<br>
> > For i In {1:10000}<br>
> > Point(100+i) = {0.25 + 1e-5*i, 0.1,0.1};<br>
> > Point{100+i} In Volume{1};<br>
> > EndFor<br>
> > %%% %%% %%% %%% %%% %%% %%% %%% %%% %%% <br>
> > <br>
> > The first file contains 1000 internal pts, and the second one contains 10 times as much.<br>
> > Now run:<br>
> > $ time gmsh -1 test1.geo<br>
> > -> Takes 0.88 sec<br>
> > $ time gmsh -1 test2.geo <br>
> > -> Takes 75 sec <br>
> > This is a nearly 100 (!!!) times increase in parsing run time, when the model size is increased by only a factor of 10.<br>
> > This nicely illustrates what I meant by "quadratic growth of the parsing run time as a function of the number of internal pts."<br>
> > As a consequence of this "quadratic growth", the run time for larger models quickly becomes enormous.<br>
> > <br>
> > Best regards<br>
> > <br>
> > A.S.<br>
> > <br>
> > Am Do., 31. Jan. 2019 um 14:31 Uhr schrieb Christophe Geuzaine <<a href="mailto:cgeuzaine@uliege.be" target="_blank">cgeuzaine@uliege.be</a>>:<br>
> > <br>
> > Can you send a test file?<br>
> > <br>
> > I tried this, i.e. adding 1000 embedded points in a volume, and it is quite fast (< 2 seconds):<br>
> > <br>
> > SetFactory("OpenCASCADE");<br>
> > Box(1) = {0,0,0, 1,1,1};<br>
> > For i In {1:1000}<br>
> > Point(100+i) = {0.25 + 5e-4*i, 0.1,0.1};<br>
> > Point{100+i} In Volume{1};<br>
> > EndFor<br>
> > <br>
> > Maybe you modify the model after each insertion of an embedded point, which would force a rebuild of the topological model?<br>
> > <br>
> > Christophe<br>
> > <br>
> > <br>
> > > On 31 Jan 2019, at 13:04, Al Sc <<a href="mailto:al.sc.gmsh@gmail.com" target="_blank">al.sc.gmsh@gmail.com</a>> wrote:<br>
> > > <br>
> > > Dear Sir or Madam,<br>
> > > <br>
> > > some more details on the previously-reported case of extremely slow parsing of a gmsh file:<br>
> > > The file contains 34795 points -- of which 23041 points are "Point In Volume" (e.g. embedded_vertices of a GRegion?). Moreover, it contains 4998 "Plane Surface"s and one single "Volume". Almost all plane surfaces are triangles and quads -- except for <10 facets, which each have a very high vertex count (typ. 7000).<br>
> > > <br>
> > > I found out that if I remove all "Point In Volume" objects, then the parsing takes only 20 seconds. However, if all the "Point In Volume" objects are not removed, parsing takes around 3000 seconds. This led me to the hypothesis that there is some huge inefficiency with parsing gmsh files with "Point In Volume" (probably quadratic run time in N(PointInVolume)??).<br>
> > > <br>
> > > Furthermore, I analyzed the runs using "perf" (linux utility).<br>
> > > Run 1 (about 3000 seconds):<br>
> > > $ time perf record ./gmsh-3.0.6-Linux64/bin/gmsh -1 input_orig.geo<br>
> > > Run 2 (about 20 seconds):<br>
> > > $ time perf record ./gmsh-3.0.6-Linux64/bin/gmsh -1 input_no_point_in_volume.geo<br>
> > > In Run 1, "perf report" yields the following top-scoring functions:<br>
> > > 11.57% gmsh gmsh [.] GModel::getEdgeByTag<br>
> > > 7.73% gmsh gmsh [.] GEO_Internals::synchronize<br>
> > > 6.80% gmsh <a href="http://libc-2.12.so" rel="noreferrer" target="_blank">libc-2.12.so</a> [.] _int_free<br>
> > > 6.31% gmsh gmsh [.] GModel::getVertexByTag<br>
> > > 4.91% gmsh <a href="http://libc-2.12.so" rel="noreferrer" target="_blank">libc-2.12.so</a> [.] malloc<br>
> > > 4.53% gmsh gmsh [.] InterpolateCurve<br>
> > > 4.40% gmsh libstdc++.so.6.0.22 [.] std::_Rb_tree_increment<br>
> > > 3.88% gmsh <a href="http://libc-2.12.so" rel="noreferrer" target="_blank">libc-2.12.so</a> [.] memcpy<br>
> > > 3.69% gmsh gmsh [.] List_Nbr<br>
> > > 3.35% gmsh <a href="http://libc-2.12.so" rel="noreferrer" target="_blank">libc-2.12.so</a> [.] _int_malloc<br>
> > > 3.24% gmsh gmsh [.] GEntity::GEntity<br>
> > > 3.13% gmsh gmsh [.] avl_lookup<br>
> > > 2.63% gmsh gmsh [.] gmshFace::resetNativePtr<br>
> > > 2.53% gmsh gmsh [.] GEdge::addFace<br>
> > > 2.52% gmsh gmsh [.] CompareVertex<br>
> > > 1.97% gmsh gmsh [.] std::_List_base<GEdge*, std::allocator<GEdge*><br>
> > > 1.88% gmsh gmsh [.] GModel::getFaceByTag<br>
> > > 1.76% gmsh gmsh [.] Tree_Action<br>
> > > 1.74% gmsh gmsh [.] gmshEdge::degenerate<br>
> > > 1.63% gmsh gmsh [.] CompareCurve<br>
> > > 1.53% gmsh gmsh [.] std::_List_base<int, std::allocator<int> >::_M<br>
> > > 1.38% gmsh gmsh [.] GModel::deletePhysicalGroups<br>
> > > 1.23% gmsh gmsh [.] std::_List_base<GEdgeSigned, std::allocator<GE<br>
> > > 1.10% gmsh gmsh [.] GVertex::addEdge<br>
> > > 0.85% gmsh gmsh [.] List_Read<br>
> > > 0.75% gmsh gmsh [.] GEdge::getBeginVertex<br>
> > > 0.73% gmsh gmsh [.] GFace::computeMeanPlane<br>
> > > 0.73% gmsh <a href="http://libc-2.12.so" rel="noreferrer" target="_blank">libc-2.12.so</a> [.] free<br>
> > > 0.67% gmsh gmsh [.] CTX::instance<br>
> > > 0.65% gmsh gmsh [.] gmshEdge::resetMeshAttributes<br>
> > > <br>
> > > This suggests that maybe GModel::getEdgeByTag is eventually called a quadratic number of times in the number of PointInVolume-objects -- and this causes the drastic slow-down.<br>
> > > <br>
> > > Could you please investigate this? Thanks a lot!<br>
> > > (As already mentioned, this issue also occurs with gmsh-4.x.x)<br>
> > > <br>
> > > Best regards<br>
> > > A. S.<br>
> > > _______________________________________________<br>
> > > gmsh mailing list<br>
> > > <a href="mailto:gmsh@onelab.info" target="_blank">gmsh@onelab.info</a><br>
> > > <a href="http://onelab.info/mailman/listinfo/gmsh" rel="noreferrer" target="_blank">http://onelab.info/mailman/listinfo/gmsh</a><br>
> > <br>
> > — <br>
> > Prof. Christophe Geuzaine<br>
> > University of Liege, Electrical Engineering and Computer Science <br>
> > <a href="http://www.montefiore.ulg.ac.be/~geuzaine" rel="noreferrer" target="_blank">http://www.montefiore.ulg.ac.be/~geuzaine</a><br>
> > <br>
> > <br>
> > <br>
> <br>
> — <br>
> Prof. Christophe Geuzaine<br>
> University of Liege, Electrical Engineering and Computer Science <br>
> <a href="http://www.montefiore.ulg.ac.be/~geuzaine" rel="noreferrer" target="_blank">http://www.montefiore.ulg.ac.be/~geuzaine</a><br>
> <br>
> <br>
> <br>
<br>
— <br>
Prof. Christophe Geuzaine<br>
University of Liege, Electrical Engineering and Computer Science <br>
<a href="http://www.montefiore.ulg.ac.be/~geuzaine" rel="noreferrer" target="_blank">http://www.montefiore.ulg.ac.be/~geuzaine</a><br>
<br>
<br>
<br>
</blockquote></div>