473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Plain Table Optimization Problem (not database, just a plain table)

Hi,

I have a C program I'm optimizing, and I would like to hear any idea about what is more important in here.

The program is very simple, I have a huge table of long integers (123MB aprox, on my PC that has Vista 32 bits with a Core 2 Duo the long integer is 32 bytes), who's format currently is:
Table = PART 0 PART 1 PART 2 PART 3 PART 4 PART 5 PART 6
Where PART i is a segment of the table.

These are the sizes of each part of the table, in bytes:
PART 1: 208
PART 2: 10816
PART 3: 276016
PART 4: 4597008
PART 5: 17565392
PART 6: 32352896
PART 7: 74718128

p is the pointer to the beggining of the table.

I later traverse the table like this:
Expand|Select|Wrap|Line Numbers
  1. clock_t clock_tTimer;
  2. long c1, c2, c3, c4, c5, c6, c7;
  3. long *p1, *p2, *p3, *p4, *p5, *p6;
  4. long i;
  5. long iSum=0;
  6.  
  7. iSum=0;
  8. clock_tTimer=clock();
  9. for (i=0;i<NUMBER_OF_TESTS;i++) {
  10.     for (c1 = 1; c1 < 47; c1++) {
  11.         p1 = p+p[BASE_ADDRESS+c1];
  12.         for (c2 = c1+1; c2 < 48; c2++) {
  13.             p2 = p+p1[c2];
  14.             for (c3 = c2+1; c3 < 49; c3++) {
  15.                 p3 = p+p2[c3];
  16.                 for (c4 = c3+1; c4 < 50; c4++) {
  17.                     p4 = p+p3[c4];
  18.                     for (c5 = c4+1; c5 < 51; c5++) {
  19.                         p5 = p+p4[c5];
  20.                         for (c6 = c5+1; c6 < 52; c6++) {
  21.                             p6 = p+p5[c6];
  22.                             for (c7 = c6+1; c7 < 53; c7++) {
  23.                                 iSum+=p6[c7];
  24.                             }
  25.                         }
  26.                     }
  27.                 }
  28.             }
  29.         }
  30.     }
  31. }
  32. clock_tTimer=clock()-clock_tTimer;
  33.  
I have two versions of the table.

In the first one the states are generated in each part (the part is where I jump with cx, meaning that with c1 I jump to what I called part 1, with c2 to part 2, and so on) in the same order they are traversed later.

The work of the second version is still in progress and I can improve it further, but the idea is that it tries to minimize the distance between the jumps from one loop to the inner loop (for example the distance from p4 to p5.

For now the faster version is the first one (the one that has the states in each part ordered in the same way they are traversed), and the second version is trailing like for 20% of the speed that seems to be too much for me.

What do you think might be doing the first version to be faster?
Might this be related with a cache of the processor?
Do you think the second version with further organization to minimize the distances may beat the first version?
Do I have to understand something about the cache of the processor to better understand what to do?
Any idea on how to further optimize this?

TIA & Regards ...
Apr 7 '08 #1
1 1475
BUMP.

(I have to type now at least 20 characters to be able to submit).
Apr 8 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Roderik | last post by:
Hi, When developing a website in general when should I choose to put content in a database. For menu options, settings, and listings like products it seems to be clear for me to put them in. But...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
4
by: jane | last post by:
HI, I try to create summary table like following: create table summary (a int, b int, c int) (select a.aa, b.bb, b.cc from table_a a ,table_b b where a.key=b.key) data initially deferred...
9
by: Andrea | last post by:
Hi, I've read the former postings but was not able to solve my problem: I have a Summary Table (or MQT as you like it) and the query optimizer does not seem to use the summary table. I run...
5
by: Praveen_db2 | last post by:
Dear All Db2 version: 8.1 OS: Windows I have 2 questions: 1) What is the optimizer which db2 uses, rule based or cost based? If any one can clear out the difference between the two it will be...
10
by: Sumanth | last post by:
Hi, I have a table that I would like to partition. It has a column c1 which has 100 distinct values. I was planning to partition the table on column c1 using a partioned index, and then apply...
4
by: Konstantin Andreev | last post by:
Recently I was engaged in the database optimization for one big commercial application. During this business I was greatly astound by the fact that it's impossible in DB2 to get the accurate size of...
5
by: Kevin | last post by:
Using a base table, a MQT table was created. With optimization - when querying the base table with calcuation that are already completed in the MQT - I would assume the optimizer would use the MQT...
4
by: Hemant Shah | last post by:
Folks, Our client has a program that browses whole table from begining to end. The table has 1 million rows in it. REORGCHK does not show any problems. It has unique index defined on KEY0...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.