Sponsored Content
Full Discussion: Which is more expensive ?
Top Forums Programming Which is more expensive ? Post 302131762 by Perderabo on Monday 13th of August 2007 03:39:02 PM
Old 08-13-2007
I would code your first snippet but compile with an optimizer. These days optimizers will unroll loops if unrolling is advantageous. That particular loop is not a real great candidate for unrolling anyway. A better candidate would be:

for(i=0; i<100; i++) A[i]=0;

Most superscalar cpus can execute:
A[i]=0;
A[i+1]=0;
A[i+2]=0;
simultaneously. How deep it can go depends on the cpu and that's why leaving unrolling to an optimizer is a good idea. The optimizer should know the target cpu. But your case involved a system call which is different. You're only saving some loop overhead.

Apparently, if you explicitly unroll a loop when it is not advantageous, most optimizers will not reroll the loop. At least this was the case circa 1998 when my copy of "High Performance Computing" was published. If you have that book, see chapter 8, "Loop Optimizations" and chapter 9, "Understanding Parallelism". This is still a great book and it's not just for Fortran programmers.

Anyway, if you are not in control of which fd's might be open, you need to to loop up to OPEN_MAX closing them. High fd's might have been opened and then setrlimit() called lower to the max fd.
 

2 More Discussions You Might Find Interesting

1. Programming

calling pthread_self (on ubuntu), expensive?

Hi all, Is anyone aware of what operations are involved when a call to pthread_self() is made, obtaining the unique thread ID on a Ubuntu system (or even any Linux flavour)? Specifically, to retrieve the thread id, is there any locking required or atomic operations? I'm building an... (11 Replies)
Discussion started by: gorga
11 Replies

2. What is on Your Mind?

Very Expensive Running Shoes

You really should not need one third of the entire US budget to buy a pair of running shoes... even if they are name brand. What have these guys been smoking? It reminds me of the old joke... Customer: At those prices you aren't going to sell many shoes. Salesman: Ah, but all we need to do is... (4 Replies)
Discussion started by: Perderabo
4 Replies
CLOOG(1)							   User Commands							  CLOOG(1)

NAME
CLooG - The Chunky Loop Genertor SYNOPSIS
cloog [ options | file ] ... DESCRIPTION
Options for code generation: -l <depth> Last loop depth to optimize (-1: infinity) (default setting: -1). -f <depth> First loop depth to start loop separation (-1: infinity) (default setting: 1). -stop <depth> Loop depth to stop code generation (-1: infinity) (default setting: -1). -strides <boolean> Handle non-unit strides (1) or not (0) (default setting: 0). -first-unroll <depth> First loop dimension to unroll (-1: no unrolling) Options for pretty printing: -otl <boolean> Simplify loops running one time (1) or not (0) (default setting: 1). -esp <boolean> Allow complex equalities spreading (1) or not (0) (default setting: 0). -fsp <level> First level to begin the spreading (default setting: 1). -block <boolean> Make a new statement block per iterator in C programs (1) or not (0) (default setting: 0). -compilable <number> Compilable code by using preprocessor (not 0) or not (0), number being the value of the parameters (default setting: 0). -callable <boolean> Testable code by using preprocessor (not 0) or not (0) (default setting: 0). General options: -o <output> Name of the output file; 'stdout' is a special value: when used, output is standard output (default setting: stdout). -v, --version Display the version information (and more). -q, --quiet Don't print any informational messages. -h, --help Display this information. The special value 'stdin' for 'file' makes CLooG to read data on standard input. For bug reporting or any suggestions, please send an email to the author <cedric.bastoul@inria.fr>. ----- This is a loop generator for scanning Z-polyhedra. It is based on the work of F. Quillere and C. Bastoul on high level code genera- tion and of the PolyLib Team on polyhedral computation. This program is distributed under the terms of the GNU Lesser General Public License (details at http://www.gnu.org/licenses/lgpl-2.1.html). ----- It would be fair to refer the following paper in any publication resulting from the use of this software or its library: @InProceedings{Bas04, author = {Cedric Bastoul}, title = {Code Generation in the Polyhedral Model Is Easier Than You Think}, booktitle = {PACT'13 IEEE International Conference on Parallel Architecture and Compilation Techniques}, pages = {7--16}, month = {september}, year = 2004, address = {Juan-les-Pins} } ----- For any information, please ask the author at <cedric.bastoul@inria.fr>. SEE ALSO
The full documentation for CLooG is maintained as a Texinfo manual. If the info and CLooG programs are properly installed at your site, the command info CLooG should give you access to the complete manual. CLooG 0.17.0 gmp bits The Chunky Loop Generator July 2012 CLOOG(1)
All times are GMT -4. The time now is 10:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy