Performance in csharp, scientific simulation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Walker

    #16
    Re: Performance in csharp, scientific simulation

    In message <1122300034.553 506.321160@z14g 2000cwz.googleg roups.com>,
    Michael Gorbach <mgorbach@gmail .com> writes[color=blue]
    >Thanks everyone for the great responses. I love this newsgroup!
    >Steve, yes I do know about mono and i will use it if i dont port, but
    >its speed is questionable. At best, it will run as fast as microsoft
    >.net, at worst there will be a performance hit.[/color]

    Sniffing round the net, Mono currently appears to be a little slower
    than Microsoft's implementation, but I'd expect the gap to close.

    --
    Steve Walker

    Comment

    • Jon Skeet [C# MVP]

      #17
      Re: Performance in csharp, scientific simulation

      Michael Gorbach <mgorbach@gmail .com> wrote:[color=blue]
      > Thanks everyone for the great responses. I love this newsgroup!
      > Steve, yes I do know about mono and i will use it if i dont port, but
      > its speed is questionable. At best, it will run as fast as microsoft
      > .net, at worst there will be a performance hit.[/color]

      That depends on what you do with it. When some colleagues were
      investigating performance comparisons, they found that for many things
      ..NET was faster than Mono, but for some others Mono was faster than
      ..NET.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Dov

        #18
        Re: Performance in csharp, scientific simulation

        I am learning C# and I am writing scientific software. What I did
        find so far is that when the data is in arrays, the differences between
        C# and the equivalent C++/C codes are very small.

        I tried (1) a Monte-Carlo simulation, and (2) translated from C a
        routine that solves a system of linear equations (simq from the CEPHES
        package) and benchmarked a large system with the coefficients
        initialized by random number generator. The C/C++ & C# versions ended
        with the same result and nearly the same time.

        However, when I translated part of the Stepanov benchmark ( a C++
        benchmark that measures abstraction penalty ) I did find a major
        performance hit. I suspect that the current C# optimizer is currently
        not yet developed enough to deal with high level of abstraction. Of
        course, I am a C# beginner and perhaps I can learn to translate better.

        I think that if you are a little careful in performance-critical
        parts of your code, you can achieve nearly C speeds.

        Dov

        Michael Gorbach wrote:[color=blue]
        > I was asked this summer to write a monte carlo code to simulation
        > magnetic nanoparticles. For the nonphysicists, basicly it is a
        > simulation where most of the time is taken up by looping through each
        > pair in an array of 500 or so particles, in order to calculate
        > interaction potential. I wrote what i have so far in csharp because i
        > wanted to learn it and though it would give me some good experience. I
        > am now beginning to understand that .net and managed code in general
        > lags far behind performance wise. Eventually i am probably going to
        > have to port to c++, unmanaged, because the simulation code will need
        > to run on linux as well.
        > My question is this:
        > What can i do in my chsarp code right now to speed up the performance.
        > The main method that is run hundreds of times a second basicly involves
        > calculating a vector dot product (using my own vector class), and an
        > exponential. Would marking the method unsafe speed anything up>[/color]

        Comment

        • Dov Bai

          #19
          Re: Performance in csharp, scientific simulation

          I am learning C# and I am writing scientific software. What I did
          find so far is that when the data is in arrays, the differences between

          C# and the equivalent C++/C codes are very small.


          I tried (1) a Monte-Carlo simulation, and (2) translated from C a
          routine that solves a system of linear equations (simq from the CEPHES
          package) and benchmarked a large system with the coefficients
          initialized by random number generator. The C/C++ & C# versions ended
          with the same result and nearly the same time.


          However, when I translated part of the Stepanov benchmark ( a C++
          benchmark that measures abstraction penalty ) I did find a major
          performance hit. I suspect that the current C# optimizer is currently
          not yet developed enough to deal with high level of abstraction. Of
          course, I am a C# beginner and perhaps I can learn to translate better.



          I think that if you are a little careful in performance-critical
          parts of your code, you can achieve nearly C speeds.


          Dov


          Michael Gorbach wrote:[color=blue]
          > I was asked this summer to write a monte carlo code to simulation
          > magnetic nanoparticles. For the nonphysicists, basicly it is a
          > simulation where most of the time is taken up by looping through each
          > pair in an array of 500 or so particles, in order to calculate
          > interaction potential. I wrote what i have so far in csharp because i
          > wanted to learn it and though it would give me some good experience. I
          > am now beginning to understand that .net and managed code in general
          > lags far behind performance wise. Eventually i am probably going to
          > have to port to c++, unmanaged, because the simulation code will need
          > to run on linux as well.
          > My question is this:
          > What can i do in my chsarp code right now to speed up the performance.
          > The main method that is run hundreds of times a second basicly involves
          > calculating a vector dot product (using my own vector class), and an
          > exponential. Would marking the method unsafe speed anything up>[/color]

          Comment

          • Michael Gorbach

            #20
            Re: Performance in csharp, scientific simulation

            My particles are stored in a class Nanoparticle, which contains a
            member of a Vector class i created. The dot product operator is done by
            the * operator which i overloaded for the Vector class. It simply uses
            a for loop over the coordinates to do the dot product.

            Comment

            • Dov Bai

              #21
              Re: Performance in csharp, scientific simulation

              And that is probably the source of your slowdown - you have created at
              least two levels of abstraction above your particles: (1) The Vector
              class, and (2) overloading the Vector operations (e.g. the * operator).

              Dov

              Comment

              • Michael Gorbach

                #22
                Re: Performance in csharp, scientific simulation

                What is the simplest way to do that without created this slowdown?

                Comment

                • Dov Bai

                  #23
                  Re: Performance in csharp, scientific simulation

                  Where performance is critical, try to use built-in data structures. For
                  example, if you have 3D particles use two dimensional jagged arrays
                  (e.g. double [][] ) to store the coordinates. The size of the first
                  dimension is the number of particles and of the the second dimension is
                  3 (for x, y, z).

                  Dov

                  Michael Gorbach wrote:[color=blue]
                  > What is the simplest way to do that without created this slowdown?[/color]

                  Comment

                  Working...