Question

C# and Visual Basic and the .NET CLR are excellent development environments for user interfaces and line-of-business applications, etc.

However, I've been writing a lot of code with execution timings that go around O(n^3): n > 1000, and in a couple of places, higher than that. Basically these loops read from one large array, do a little math and make five or six tests, and write the result to a second array of identical size.

Most of it is code that was ported from Intel Fortran programs, in order to bring them into a 64-bit world. I've noted that without any auto-vectorization of that code, execution times are much slower. .NET has no support for use of the SIMD operations found on every Intel processor sold today.

Since the functions already written in a tight algorithm that can be ported by a skilled programmer, I thought that asking that programmer to port the code to a C++ CLR library might be an approach.

  • Is it possible to get a C++ library that is auto-vectorized and also presents a CLR interface for a C#/VB program to call?
  • If no, do workarounds exist? Is a COM interface one such workaround?
  • If yes, what form would it have to take?
Was it helpful?

Solution

Sure, no problem. A C++/CLI class library project gives you the way to write a managed wrapper, a ref class, that can directly call native C++ code. Such a class is directly usable by any managed code.

VS2012 or higher required to get auto-vectorization and auto-parallelization in native C++ code. Designing the interop layer so the number of transitions from managed to unmanaged code and back is minimized can be important. In other words, don't copy a single double value at a time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top