parallelism and/or thread safety

Apr 5, 2013 at 1:48 PM
First of all great port and thanks for sharing your work. It's a really comprehensive library you made. Did you ever consider parallellism and or making portions thread safe ? What are your thoughts about this?
Coordinator
Apr 5, 2013 at 3:00 PM
Edited Apr 6, 2013 at 7:02 AM
Thanks, finally someone voted ...

Never considered, but obviously the library isn't thread safe:
void ParallelTest()
{
    var task1 = System.Threading.Tasks.Task.Factory.StartNew(() =>
    {
    var generator = new MeshExplorer.Generators.CircleWithHole();
    var geometry = generator.Generate(200, 5, 0);

    try
    {
        Mesh mesh = new Mesh();
        mesh.Behavior.MinAngle = 30;
        mesh.Triangulate(geometry);
        mesh.Refine(true);
        mesh.Refine(true);
        mesh.Smooth();
        mesh.Refine(true);
        mesh.Smooth();
    }
    catch (Exception)
    {
        throw;
    }
    });

    var task2 = System.Threading.Tasks.Task.Factory.StartNew(() =>
    {
    var generator = new MeshExplorer.Generators.CircleWithHole();
    var geometry = generator.Generate(200, 5, 0);

    try
    {
        Mesh mesh = new Mesh();
        mesh.Behavior.MinAngle = 30;
        mesh.Triangulate(geometry);
        mesh.Refine(true);
        mesh.Refine(true);
        mesh.Smooth();
        mesh.Refine(true);
        mesh.Smooth();
    }
    catch (Exception)
    {
        throw;
    }
    });

    try
    {
    System.Threading.Tasks.Task.WaitAll(task1, task2);
    }
    catch (AggregateException ae)
    {
    throw ae.Flatten();
    }
}
If I find some time, I'll look into the problem. There are same places where I use static variables, which surely cause trouble.

Now, regarding parallelism: when starting the project I had a look into parallel mesh generation and refinemend, but since the meshes I work on are small (less than 50000 triangles), I never tried to implement.

Parallel mesh refinement is usually done by partitioning an initial mesh and then doing refinement on different cores. Partitioning is easily done with METIS and C# interop (got this working). But I didn't continue working on it and probably won't in the near future.

A good starting point could be http://crtc.wm.edu/html_output/constrained_delaunay.htm
Apr 5, 2013 at 4:11 PM
Ok, thanks for the reply. I will look into it myself as well. If I find something useful i will let you know. Again thanks for sharing this excellent port.


Coordinator
Apr 6, 2013 at 7:06 AM
So, after a first look, I think thread-safety would involve a lot of locking all across the library. No easy task ...
Dec 5, 2013 at 10:08 AM
Congrats, this is a great work here and so usefull.
Parallelism is not only about partitioning the work of a single triangulation. I would like to run // triangulations of a bunch of cities that I retrieve as a whole collection of data. So adding thread-safety would be a very cool feature :)