2

I have a C# prototype that is heavily data parallel, and I've had extremely successful order of magnitude speed ups using the Parallel.For construct in .NETv4. Now I need to write the program in native code, and I'm wondering what my options are. I would prefer something somewhat portable across various operating systems and compilers, but if push comes to shove, I can go with something Windows/VC++.

I've looked at OpenMP, which looks interesting, but I have no idea whether this is looked upon as a good solution by other programmers. I'd also love suggestions for other portable libraries I can look at.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
sooniln
  • 14,607
  • 4
  • 29
  • 35
  • 1
    Out of curiosity, what's the reason for making the whole app native? – JSBձոգչ Jun 04 '10 at 22:19
  • 1
    Cross-platform high-level multi-threading is a path fraught with peril. – zdav Jun 04 '10 at 22:23
  • Ideally, this will be integrated with an app that is already written in C/C++. I was thinking I would like to make it 'not too difficult' to port to other systems, but comments have made me change my mind on that :) – sooniln Jun 04 '10 at 23:08
  • All great answers, sorry I could only pick one :( – sooniln Jun 07 '10 at 18:26
  • This might have a related answers https://stackoverflow.com/questions/21247586/what-can-you-do-to-stop-running-out-of-stack-space-when-multithreading/46699947#46699947 As I put an implementation of a parallel sort there minus the task scheduler. But a fairly performant one can be written easily and I linked to a presentation on how – Beached Oct 12 '17 at 03:06

4 Answers4

2

If you're happy with the level of parallelism you're getting from Parallel.For, OpenMP is probably a pretty good solution for you -- it does roughly the same kinds of things. There's also work and research being done on parallelized implementations of the algorithms in the standard library. Code that uses the standard algorithms heavily can gain from this with even less work.

Some of this is done using OpenMP, while other is using hand-written code to (attempt to) provide greater benefits. In the long term, we'll probably see more of the latter, but for now, the OpenMP route is probably a bit more practical.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
1

You should check out Intel's Thread Building Blocks. Visual Studio 2010 also offers a Concurrency Runtime native. The .NET 4.0 libraries and the ConcRT are designed very similarly, if not identically.

Puppy
  • 144,682
  • 38
  • 256
  • 465
1

If you're using Parallel.For in .Net 4.0, you should also look at the Parallel Pattern Library in VS2010 for C++; many things are similar and it is library based.

If you need to run on another platform besides Windows the PPL is also implemented in Intel's Thread Building Blocks which has an open source version.

Regarding the other comment on similarities / differences vs. .Net 4.0, the parallel loops in the PPL (parallel_for, parallel_for_each, parallel_invoke) are virtually identical to the .Net 4.0 loops. The task model is slightly different, but should be straightforward.

Rick
  • 3,285
  • 17
  • 17
0

if you want something that is versatile, as in portable across various OS and environments, it would be very difficult to not to consider Java. And they are very similar to C# so it be a very easy transition.

Unless you want to pull out your ninja scalpel and wanting to make your code extremely efficient, I would say java over VC++ or C++.

Anatoli
  • 922
  • 2
  • 11
  • 25
  • I'm not convinced java would give much of a boost over c#, only more portable. – zdav Jun 04 '10 at 22:19
  • well, portability was what he was looking for... At least that's the impression I'm under... – Anatoli Jun 04 '10 at 22:22
  • Well 1) Perf is extremely important for me, and 2) it will need to be integrated with an app already written in C/C++. I would prefer not to have to load the CLR in this app as this is a really heavyweight change. – sooniln Jun 04 '10 at 23:09