-
December 7th, 2012, 09:19 PM
#1
For loop optimization
I have identified the bottleneck in my code, and I was hoping for some advice on how to get the code running more quickly/efficiently.
Code:
for(s = 0; s < start.size(); s++){
inc = factor_base_index[s];
mpz_set_ui(base2, inc);
sz = mpz_sizeinbase(base2, 2);
for(st = start[s]; st < 262144; st += inc){
//increment the zero array by ~log2(inc)
mpz_add_ui(zero[st], zero[st], sz);
}
}
The bold line is where the majority of the work is being done.
All this is doing is taking a prime number, storing it in the variable inc, finding the number of bits in inc, and incrementing the array 'zero' by the number of bits.
Any help would be really appreciated
-
December 7th, 2012, 10:14 PM
#2
Re: For loop optimization
Here are some methods of calculating log2 of a number: http://graphics.stanford.edu/~seande...egerLogObvious
Some more high performance than others.
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|