Re: Java vs C++ ?
- From: DP <pfennige@xxxxxxxxxxxx>
- Date: Wed, 24 Jan 2007 19:40:07 +0100
It looks like that your have an array on which cells are marked
as "boundaries" or not. If not boundary, then the new value of
the cell xyValue[i][j]) at the next "iteration" is the average
of the 4 nearest neighbors at the previous state.
If this is what you want to do, then the algorithm is flawed
because the array is modified in place, which destroy the
values of the neighbor cells of lower index.
I wonder also why the second index depends on i instead of
j (see xyValue[0][i]).
Dan
Peter Christensen wrote:
"DP" <pfennige@xxxxxxxxxxxx> skrev i en meddelelse news:45b61c0d$1@xxxxxxxxxxxxxxxx.
Peter Christensen wrote:I've been writing my simulation program in Java 2, and I didn't see this at a problem before. But now I would like to do some more precise analysis, and now the computers performance is an important limiting factor. -I used Java 2 as the programming language, even though I know that C++ would be faster, partly because I like the Java language, but also because I did't have a C++ compiler at the moment.
I just wonder, if I can really win something by writing the critical part of my program in C++ instead of Java. How much could that be?
The only part of my program, which is really time-consuming is this:
public static float iteration() {
float newValue;
float errorSum = 0;
for (int i=0;i<xRange;i++) {
for (int j=0;j<yRange;j++) {
if (!xyBound[i][j]) {
if (j == 0) {
newValue = (xyValue[i+1][0]+xyValue[i-1][0]
+xyValue[i][1]+xyValue[0][i])/4;
} else if (i == 0) {
newValue = (xyValue[1][j]+xyValue[j][0]
+xyValue[0][j+1]+xyValue[0][j-1])/4;
} else {
newValue = (xyValue[i+1][j]+xyValue[i-1][j]
+xyValue[i][j+1]+xyValue[i][j-1])/4;
}
errorSum += Math.abs(newValue - xyValue[i][j]);
xyValue[i][j] = newValue;
}
}
}
return errorSum;
}
- References:
- Java vs C++ ?
- From: Peter Christensen
- Re: Java vs C++ ?
- From: DP
- Re: Java vs C++ ?
- From: Peter Christensen
- Java vs C++ ?
- Prev by Date: Re: Java vs C++ ?
- Next by Date: Closed form solution to quadratic fit?
- Previous by thread: Re: Java vs C++ ?
- Next by thread: Re: Java vs C++ ?
- Index(es):
Relevant Pages
|