473,848 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Performance in csharp, scientific simulation

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>

Nov 17 '05 #1
22 3009
I believe before jumping to conclusions you must profile your application.
Aside from memory use you can find out which methods are taking most of time
/ calls and check if code is optimal in there.

As you might know, ideal performance is achieved by fetching result by
argument. Simple iteration is not always the best approach. This includes
names :-)

HTH
Alex

"Michael Gorbach" <mg******@gmail .com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
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>

Nov 17 '05 #2
I believe before jumping to conclusions you must profile your application.
Aside from memory use you can find out which methods are taking most of time
/ calls and check if code is optimal in there.

As you might know, ideal performance is achieved by fetching result by
argument. Simple iteration is not always the best approach. This includes
names :-)

HTH
Alex

"Michael Gorbach" <mg******@gmail .com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
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>

Nov 17 '05 #3
how do i go about doing this application profiling? im more or less new
to serious programming so any help would be appreaciated.
Also, what do you mean by "fetching result by argument?"

Are there are references on performance you could suggest?

Nov 17 '05 #4
how do i go about doing this application profiling? im more or less new
to serious programming so any help would be appreaciated.
Also, what do you mean by "fetching result by argument?"

Are there are references on performance you could suggest?

Nov 17 '05 #5
MIchael, in most testing scenarios the performance of well written (and
I stress "well - written") C# and C++ is comparable. Both eventually
are run as machine code. In the case of C#, where intensive math
computations are being made, performance can be increased by the
judicious and careful use of pointer - based arithmetic. Alex's
comment about profiling is right on the money, especially if this is a
new language you are just learning.

Compuware has an excellent freeware profiler (a "Community" edition)
and there are others. These can help you tremendously.

Nov 17 '05 #6
MIchael, in most testing scenarios the performance of well written (and
I stress "well - written") C# and C++ is comparable. Both eventually
are run as machine code. In the case of C#, where intensive math
computations are being made, performance can be increased by the
judicious and careful use of pointer - based arithmetic. Alex's
comment about profiling is right on the money, especially if this is a
new language you are just learning.

Compuware has an excellent freeware profiler (a "Community" edition)
and there are others. These can help you tremendously.

Nov 17 '05 #7
I would suggest to have a look at math books dealing with optimal
algorithms.

My comment is about most efficient computation, which is not always
achievable. y = f(x). X is argument. F - some function. If you can deliver y
for any given x, for example, using some table, you probably won't be able
to create anything more efficient in terms of speed. But you will pay with
memory use.

That's why I suggest profiling. You can start with also free MS CLRProfiler,
which you can download at
http://www.microsoft.com/downloads/d...DisplayLang=en
Source code is quite good in demonstrating some of common optimization
techniques, by the way

HTH
Alex

"Michael Gorbach" <mg******@gmail .com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
how do i go about doing this application profiling? im more or less new
to serious programming so any help would be appreaciated.
Also, what do you mean by "fetching result by argument?"

Are there are references on performance you could suggest?

Nov 17 '05 #8
I would suggest to have a look at math books dealing with optimal
algorithms.

My comment is about most efficient computation, which is not always
achievable. y = f(x). X is argument. F - some function. If you can deliver y
for any given x, for example, using some table, you probably won't be able
to create anything more efficient in terms of speed. But you will pay with
memory use.

That's why I suggest profiling. You can start with also free MS CLRProfiler,
which you can download at
http://www.microsoft.com/downloads/d...DisplayLang=en
Source code is quite good in demonstrating some of common optimization
techniques, by the way

HTH
Alex

"Michael Gorbach" <mg******@gmail .com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
how do i go about doing this application profiling? im more or less new
to serious programming so any help would be appreaciated.
Also, what do you mean by "fetching result by argument?"

Are there are references on performance you could suggest?

Nov 17 '05 #9
Last I checked CLR Profiler does *not* profile speed but only memory
usage. If the simulation is using fixed arrays, as I suspect, it
won't give any results.

Besides, the question was which is faster for this task -- C# or C++?
Just profiling C# evidently won't give any answer to this question.

On Fri, 22 Jul 2005 22:11:56 -0400, "AlexS"
<sa***********@ SPAMsympaticoPL EASE.ca> wrote:
I would suggest to have a look at math books dealing with optimal
algorithms.

My comment is about most efficient computation, which is not always
achievable. y = f(x). X is argument. F - some function. If you can deliver y
for any given x, for example, using some table, you probably won't be able
to create anything more efficient in terms of speed. But you will pay with
memory use.

That's why I suggest profiling. You can start with also free MS CLRProfiler,
which you can download at
http://www.microsoft.com/downloads/d...DisplayLang=en
Source code is quite good in demonstrating some of common optimization
techniques, by the way

HTH
Alex

--
http://www.kynosarges.de
Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3199
by: Steaming Balturd | last post by:
are there any php based economic simulations out there - not trading games per se, but more like simulating an economy, be it running a business or running a government? All i've been able to find are online space trading or role-playing style games, rather than any kind of "tycoon" or "civilisation" style games written in PHP.
12
9204
by: Dave Theese | last post by:
Hello all, I'm in a poition of trying to justify use of the STL from a performance perspective. As a starting point, can anyone cite any benchmarks comparing vectors to plain old statically-declared arrays? I'll also be looking at the other STL containers later... Also, I'd appreciate any comments anyone has on the suitability of the little program below for comparing vectors and arrays. One obvious shortcoming is that it uses...
5
2961
by: a | last post by:
Is there a performance hit if I have many "using" statements that are unnecessary? For example: using System.Collections; when nowhere in my code I'm using System.Collections namespace. I'm really thinking about the default "using" statements put by VS.NET.
13
1439
by: mgorbach | last post by:
Im writing a program that does monte carlo simulation and im having trouble figuring out how to get the threading model right. I have a simulation class which contains all simulation data and methods to run the simulation for an x number of sweeps. An instance of this object is declared in the class of my main form. The main form handles graphics (it shows the particles moving on the form). I am now trying to split up the work so that the...
0
376
by: Michael Gorbach | last post by:
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...
53
4412
by: Michael Tobis | last post by:
Someone asked me to write a brief essay regarding the value-add proposition for Python in the Fortran community. Slightly modified to remove a few climatology-related specifics, here it is. I would welcome comments and corrections, and would be happy to contribute some version of this to the Python website if it is of interest. ===
1
2394
by: Ted | last post by:
I have cross posted this to comp.lang.c++ and to sci.math.num- analysis in the belief that the topic is of interest to some in both groups. I am building my toolkit, in support of my efforts in producing high performance C++ code; code that is provably correct. The issue here is orthogonal to the question of expression templates, which at present seem to me to be relatively simple.
2
1261
by: PJ6 | last post by:
I'm pushing my CPU to its limit with a realtime physics simulation to learn more about coding for performance. In the simplest case, I have a form that, on a timer tick, drives the physics model forward by the time elapsed since the last tick measured by a stopwatch (since both the timer and DateTime.Now is not accurate), and then renders the newly calculated state to the UI. Now I noticed that when I pushed this process to its limit, I...
0
9738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11001
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10664
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10722
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10348
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9500
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7894
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4137
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.