473,395 Members | 1,441 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,395 software developers and data experts.

Paging Fault and Loops order

Hi,
i was studying the virtual memory and the page fault concept in
particularly [see,
http://www.cs.man.ac.uk/~rizos/CS205...-02/lect11.pdf ]

Considering this concept and the two versions code given below. Assume
that the matrix "a" is stored row by row , and considering that the
program is given only 1024 frames, version A below leads to 1024*1024
page fault whereas version B leads to only 1024 Page Fault, thus run
faster.

I have never paid attention to this issue. as a programmer do we have
to? is the compiler intelligent enough to order the loop execution in
the most effective way, i.e. switch automatically version A like code
to version B

thanks

int a[1024][1024];
/* version A */
for (j=0; j<1024; j++)
for (i=0;i<1024; i++)
A[i][j]=0;
/* version B */
for (i=0; i<1024; i++)
for (j=0;j<1024; j++)
A[i][j]=0;

Nov 12 '06 #1
6 1650
el*********@yahoo.com writes:
Hi,
i was studying the virtual memory and the page fault concept in
particularly [see,
http://www.cs.man.ac.uk/~rizos/CS205...-02/lect11.pdf ]

Considering this concept and the two versions code given below. Assume
that the matrix "a" is stored row by row , and considering that the
program is given only 1024 frames, version A below leads to 1024*1024
page fault whereas version B leads to only 1024 Page Fault, thus run
faster.

I have never paid attention to this issue. as a programmer do we have
to? is the compiler intelligent enough to order the loop execution in
the most effective way, i.e. switch automatically version A like code
to version B
In standard C, I think the compiler is prohibed to switch from one
version to another. A very good C compiler could provide a warning on
version A.

int a[1024][1024];
/* version A */
for (j=0; j<1024; j++)
for (i=0;i<1024; i++)
A[i][j]=0;
/* version B */
for (i=0; i<1024; i++)
for (j=0;j<1024; j++)
A[i][j]=0;

--
__Pascal Bourguignon__ http://www.informatimago.com/

ATTENTION: Despite any other listing of product contents found
herein, the consumer is advised that, in actuality, this product
consists of 99.9999999999% empty space.
Nov 12 '06 #2
In article <11*********************@h48g2000cwc.googlegroups. com>,
<el*********@yahoo.comwrote:
>i was studying the virtual memory and the page fault concept in
particularly [see,
http://www.cs.man.ac.uk/~rizos/CS205...-02/lect11.pdf ]
>Considering this concept and the two versions code given below. Assume
that the matrix "a" is stored row by row , and considering that the
program is given only 1024 frames, version A below leads to 1024*1024
page fault whereas version B leads to only 1024 Page Fault, thus run
faster.
>I have never paid attention to this issue. as a programmer do we have
to?
Yes.
>is the compiler intelligent enough to order the loop execution in
the most effective way, i.e. switch automatically version A like code
to version B
Not usually, no.

*Some* compilers might be able to do it in the special case
of assigning a constant: in particular, some compilers designed
to compile into parallel operations must be able to use
their "code motion" and "strength reduction" analysis to determine
how to minimize the cache effects. A compiler that was smart about
cache effects might even introduce a padding column so that
a[x][0] and a[x+1][0] are on different cache lines. Compilers
are *allowed* to be smart about such things, but by no means
should you assume it.
Consider this situation:

double a[1024][1024] already initialized to something

/* version C*/
double total = 0.; for (j=0;j<1024;j++) for (i=0;i<1024;i++) total += A[i][j];

/* version D*/
double total = 0.; for (i=0;i<1024;i++) for (j=0;j<1024;j++) total += A[i][j];

This cannot be reordered, not unless the compiler can pre-determine that
all of the values are the same or that the matrix is symmetric. If
it cannot determine one of those conditions, then it must do the work
in the order specified, because adding doubles in a different order
can lead to different round-off errors.

The parallel compilers I mentioned earlier would usually have options
that control the amount of latittude they have for reordering operations
where the reordering might end up with a different result due to
round-off.
>int a[1024][1024];
/* version A */
for (j=0; j<1024; j++)
for (i=0;i<1024; i++)
A[i][j]=0;
>/* version B */
for (i=0; i<1024; i++)
for (j=0;j<1024; j++)
A[i][j]=0;
--
All is vanity. -- Ecclesiastes
Nov 12 '06 #3
el*********@yahoo.com writes:
>
I have never paid attention to this issue. as a programmer do we have
to? is the compiler intelligent enough to order the loop execution in
the most effective way, i.e. switch automatically version A like code
to version B
I've never seen a compiler smart enough to reorder loops to reduce
page faults in any cases whatever. I can tell you from personal
experience that if you got it wrong, the big old disk drives on a DEC
VAX 11/780 really would start moving around on the floor.
--
Joseph J. Pfeiffer, Jr., Ph.D. Phone -- (505) 646-1605
Department of Computer Science FAX -- (505) 646-1002
New Mexico State University http://www.cs.nmsu.edu/~pfeiffer
Nov 12 '06 #4
In article <11*********************@h48g2000cwc.googlegroups. com>,
<el*********@yahoo.comwrote:
>is the compiler intelligent enough to order the loop execution in
the most effective way, i.e. switch automatically version A like code
to version B
Yes, this is a common optimization in modern optimizing compilers.

-- greg
Nov 12 '06 #5

Greg Lindahl wrote:
In article <11*********************@h48g2000cwc.googlegroups. com>,
<el*********@yahoo.comwrote:
is the compiler intelligent enough to order the loop execution in
the most effective way, i.e. switch automatically version A like code
to version B

Yes, this is a common optimization in modern optimizing compilers.
How is this optimization called?

Does gcc do that? If so, which command option turn it on/off?

Nov 12 '06 #6
"Pascal Bourguignon" <pj*@informatimago.comwrote in message
news:87************@thalassa.informatimago.com...
el*********@yahoo.com writes:
>i was studying the virtual memory and the page fault concept in
particularly [see,
http://www.cs.man.ac.uk/~rizos/CS205...-02/lect11.pdf ]

Considering this concept and the two versions code given below. Assume
that the matrix "a" is stored row by row , and considering that the
program is given only 1024 frames, version A below leads to 1024*1024
page fault whereas version B leads to only 1024 Page Fault, thus run
faster.

I have never paid attention to this issue. as a programmer do we have
to? is the compiler intelligent enough to order the loop execution in
the most effective way, i.e. switch automatically version A like code
to version B

In standard C, I think the compiler is prohibed to switch from one
version to another. A very good C compiler could provide a warning on
version A.
A compliant C compiler can do anything it likes provided it is impossible to
tell the difference between what the standard specifies the result must be
and the actual result. In the case the OP mentioned:
>int a[1024][1024];
/* version A */
for (j=0; j<1024; j++)
for (i=0;i<1024; i++)
A[i][j]=0;

/* version B */
for (i=0; i<1024; i++)
for (j=0;j<1024; j++)
A[i][j]=0;
(I ignore the fact the above mistakenly uses 'A' instead of 'a')

If, as is likely, assigning 0 to an int sets all bits to zero, either of
these versions /could/ be compiled to the same as:

memset(a, 0, sizeof a);

I don't know if any compilers are "clever enough" to realise this though.

Alex
Nov 12 '06 #7

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

Similar topics

1
by: Guoqi Zheng | last post by:
Sir, The default paging of datagrid is somehow use too much resource, so I am using Stored procedure for the paging. You can find my Stored procedure at the end of this message. It works...
2
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
0
by: Paul Wilson | last post by:
Hi guys, I've learnt thata SQLDataAdapters support paging with the overloaded FILL method (having start record & max records as parameters). & also learnt that the ideal way to achieve paging is...
0
by: anonieko | last post by:
This approach I found very efficient and FAST when compared to the rowcount, or Subquery Approaches. This is before the advent of a ranking function from DB such as ROW_NUMBER() in SQL Server...
1
by: rbg | last post by:
I am using derived tables to Page data on the SQL Server side. I used this link as my mentor for doing paging on the SQL Serverhttp://msdn2.microsoft.com/en-us/library/ms979197.aspx I wanted to...
8
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table,...
2
by: rn5a | last post by:
In a shopping cart app, a ASPX page retrieves the order details & personal details of a user from a MS-Access database table depending upon the username of the user. The order details of a...
5
by: Donald Adams | last post by:
Hi, I will have both web and win clients and would like to page my data. I could not find out how the datagrid control does it's paging though I did find some sample code that says they do it...
3
osward
by: osward | last post by:
Hi, everyone, I had managed to make use of the date link from a simple calendar script to my query table. When I click on the date's link or Prev and Next Month link, The table first row will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
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...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...

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.