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
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?
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
LEARN ABOUT PHP
fann_get_cascade_candidate_stagnation_epochs