CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2009
    Posts
    38

    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

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    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
  •  





Click Here to Expand Forum to Full Width

Featured