Hello !
Who can explain why readind from array[][] is fast, but
writing (same place) might take a lot of time (I need many loops)
How to solve it (declare as static or force some compiler (VC 6.0)
options) ??? Thanks in advance
Here is example (but critical !!!) code...
void main(int argc, char* argv[])
{
unsigned char r[360][180], dat2, i,j,k;
int p;
for (p=0; p<650; p++) {
for (i=0; i<200; i++) {
for (j=0; j<200; j++) {
for (k=0; k<100; k++) {
dat2=r[j][i]; dat2=r[j][i]; dat2=r[j][i];
// r[j][i]=dat2; r[j][i]=dat2; r[j][i]=dat2;
// critical point: without it almost no execution time
// with it - 6 seconds on P3-1000 ???
}
}
}
}
} 6 2481
"Oleg Kornilov" <ol***********@mail.ru> wrote Hello ! Who can explain why readind from array[][] is fast, but writing (same place) might take a lot of time (I need many loops) How to solve it (declare as static or force some compiler (VC 6.0) options) ??? Thanks in advance Here is example (but critical !!!) code...
void main(int argc, char* argv[]) { unsigned char r[360][180], dat2, i,j,k; int p;
for (p=0; p<650; p++) { for (i=0; i<200; i++) { for (j=0; j<200; j++) { for (k=0; k<100; k++) {
dat2=r[j][i]; dat2=r[j][i]; dat2=r[j][i];
// r[j][i]=dat2; r[j][i]=dat2; r[j][i]=dat2; // critical point: without it almost no execution time // with it - 6 seconds on P3-1000 ???
} } } } }
My first guess is that the compiler is (correctly) optimizing out your reads
since the resulting value is never used for anything.
Claudio Puviani
"Oleg Kornilov" <ol***********@mail.ru> wrote in message
news:9c**************************@posting.google.c om... Hello ! Who can explain why readind from array[][] is fast, but writing (same place) might take a lot of time (I need many
loops) How to solve it (declare as static or force some compiler
(VC 6.0) options) ??? Thanks in advance Here is example (but critical !!!) code...
void main(int argc, char* argv[]) { unsigned char r[360][180], dat2, i,j,k; int p;
for (p=0; p<650; p++) { for (i=0; i<200; i++) { for (j=0; j<200; j++) { for (k=0; k<100; k++) {
dat2=r[j][i]; dat2=r[j][i]; dat2=r[j][i];
// r[j][i]=dat2; r[j][i]=dat2; r[j][i]=dat2; // critical point: without it almost no execution time // with it - 6 seconds on P3-1000 ???
} } } } }
Aren't you accessing outside your array bounds?
Oleg Kornilov wrote: Hello ! Who can explain why readind from array[][] is fast, but writing (same place) might take a lot of time (I need many loops) How to solve it (declare as static or force some compiler (VC 6.0) options) ??? Thanks in advance Here is example (but critical !!!) code...
One possible answer could be the cache. Another answer could be the
optimization: if you don't use the values you read in the compiler may omit
the loop completely.
Some nice performance tips:
* use unsigned int / size_t - variables for loop indicies.
* use Blitz++ arrays or 1D-valarrays for storing the data:
valarray<unsigned char> r(360*180);
r[180*row+column]=value;
* make usage of the superscalar architecture / SIMD calls
for(size_t i=0;i < 100;i++) value += data[i];
to
sum1=sum2=sum3=sum4=0.0;
for(size_t i=0;i < 100; i+=4)
{
sum1 += data[i];
sum2 += data[i+1];
sum3 += data[i+2];
sum4 += data[i+3];
}
sum1 += (sum2 + sum3 + sum4);
Although its for Athlons some nice tips are still usuable on
other modern machines: http://www.amd.com/us-en/assets/cont...te_papers_and_
tech_docs/22007.pdf
"John Ericson" <je************@pacbell.net> wrote... "Oleg Kornilov" <ol***********@mail.ru> wrote in message news:9c**************************@posting.google.c om... Hello ! Who can explain why readind from array[][] is fast, but writing (same place) might take a lot of time (I need many loops) How to solve it (declare as static or force some compiler (VC 6.0) options) ??? Thanks in advance Here is example (but critical !!!) code...
void main(int argc, char* argv[]) { unsigned char r[360][180], dat2, i,j,k; int p;
for (p=0; p<650; p++) { for (i=0; i<200; i++) { for (j=0; j<200; j++) { for (k=0; k<100; k++) {
dat2=r[j][i]; dat2=r[j][i]; dat2=r[j][i];
// r[j][i]=dat2; r[j][i]=dat2; r[j][i]=dat2; // critical point: without it almost no execution time // with it - 6 seconds on P3-1000 ???
} } } } }
Aren't you accessing outside your array bounds?
Nah, 'j' never goes above 199, which is well within 0..359 space,
so when 'i' goes above 179 (for only 20), he's not stepping on any
other memory, only the next 20 elements of the 'j+1' array or the
'r' superarray.
V
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:r26Xb.27653$uV3.49996@attbi_s51... "John Ericson" <je************@pacbell.net> wrote... "Oleg Kornilov" <ol***********@mail.ru> wrote in message news:9c**************************@posting.google.c om... Hello ! Who can explain why readind from array[][] is fast,
but writing (same place) might take a lot of time (I need
many loops) How to solve it (declare as static or force some
compiler (VC 6.0) options) ??? Thanks in advance Here is example (but critical !!!) code...
void main(int argc, char* argv[]) { unsigned char r[360][180], dat2, i,j,k; int p;
for (p=0; p<650; p++) { for (i=0; i<200; i++) { for (j=0; j<200; j++) { for (k=0; k<100; k++) {
dat2=r[j][i]; dat2=r[j][i]; dat2=r[j][i];
// r[j][i]=dat2; r[j][i]=dat2; r[j][i]=dat2; // critical point: without it almost no execution
time // with it - 6 seconds on P3-1000 ???
} } } } }
Aren't you accessing outside your array bounds?
Nah, 'j' never goes above 199, which is well within 0..359
space, so when 'i' goes above 179 (for only 20), he's not
stepping on any other memory, only the next 20 elements of the 'j+1' array
or the 'r' superarray.
V
:) You've got a point <ROTFL> - Victor, I sure enjoy your
posts!
Best regards, JE
Ruediger Knoerig <ru******@knoerig.de> wrote in message
news:c0**********@mamenchi.zrz.TU-Berlin.DE... Oleg Kornilov wrote:
Hello ! Who can explain why readind from array[][] is fast, but writing (same place) might take a lot of time (I need many loops) How to solve it (declare as static or force some compiler (VC 6.0) options) ??? Thanks in advance Here is example (but critical !!!) code... One possible answer could be the cache. Another answer could be the optimization: if you don't use the values you read in the compiler may
omit the loop completely. Some nice performance tips: * use unsigned int / size_t - variables for loop indicies.
Would you elabrate on this for us please?
* use Blitz++ arrays or 1D-valarrays for storing the data:
What is Blitz++ arrays? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kevin T. Ryan |
last post by:
Hi All -
I'm not sure, but I'm wondering if this is a bug, or maybe (more
likely) I'm misunderstanding something...see below:
>>> f = open('testfile', 'w')
>>> f.write('kevin\n')
>>>...
|
by: Yaroslav Bulatov |
last post by:
I made an array of 10 million floats timed how long it takes to sum
the elements, here's what I got (millis):
gcc -O2: 21
Python with numarray: 104
Python with Numeric: 302...
|
by: Jeevan |
last post by:
Hi,
I have an array of data (which I am getting from a socket connection).
I am working on a program which acts on this data but the program is
written to work on data from a file (not from an...
|
by: Oleg Kornilov |
last post by:
Hello !
Who can explain why readind from array is fast, but
writing (same place) might take a lot of time (I need many loops)
How to solve it (declare as static or force some compiler (VC 6.0)...
|
by: Matthew Crema |
last post by:
Hello,
Say I have 1000 text files and each is a list of 32768 integers.
I have written a C program to read this data into a large matrix. I am
using fopen in combination with fscanf to read...
|
by: Nick |
last post by:
I have found a class that compresses and uncompresses data but need
some help with how to use part of it below is the deflate method which
compresses the string that I pass in, this works OK. At...
|
by: dsmith |
last post by:
I need to write a data array out to disk, but unfortunately am running
into performance issues. The function is essentially:
private ushort theInt16Array = new ushort;
public void...
|
by: JoKur |
last post by:
Hello,
First let me tell you that I'm very new to C# and learning as I go. I'm
trying to write a client application to communicate with a server (that I
didn't write). Each message from the...
|
by: arne.muller |
last post by:
Hello,
I've come across some problems reading strucutres from binary files.
Basically I've some strutures
typedef struct {
int i;
double x;
int n;
double *mz;
|
by: John |
last post by:
Hi
I am trying to save settings of controls on my form to a file so I can read
them back later and recreate the controls on the form. I have figured out
how to go through all controls and get...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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,...
| |