Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Basically i need a routine that takes BigInt1 and BigInt2 then returns the multiplied BigInt.

I have tried just dividing the biggest BigInt by the smaller one creating a looping routine that runs across several threads adding to a BigInt total although it worked it was (much) slower than just executing BigInt.Multiply on one thread! xD.

my original loop looked something like below inside each thread and despite 100% my CPU it was far too slow.
C#
      private void MultiplicationThread()
       {
           int MyThreadID = GetNextThreadID();
           if (PartsOfBig[MyThreadID] > 0)
           {
               BigInteger NextBlock = new BigInteger();
               NextBlock = BigInteger.Multiply(PartsOfBig[MyThreadID],TheSmall[MyThreadID]);
               lock (TheBigLock)
               {
                   TheBig = BigInteger.Add(TheBig, NextBlock);
               }
           }
       }
}
Posted
Updated 4-Aug-14 2:24am
v5
Comments
A-s-h-l-e-y 4-Aug-14 8:25am    
Updated with loop from this program*

Quote:
it worked it was (much) slower than just executing BigInt.Multiply on one thread
Yes, that's what I do expect for such a case. When you do the operation in different cores, several values need to be checked and updated for each step of the operation between the individual cores, and that slows the process down severely. By doing multi-threading the wrong way, an application can be slowed down extremely.
There are some articles here on CP explaining the background in great detail.
 
Share this answer
 
I don't think you're going to find a solution to this. Multiplication is not really a parallel problem. It's normally atomic.

Also, it doesn't appear as though you're tracking carry-overs or adding them back into the appropriate places so you're answer is going to come out wrong.
 
Share this answer
 
Comments
A-s-h-l-e-y 5-Aug-14 19:47pm    
Nope answer is right just no speed advantage.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900