Click here to Skip to main content
14,577,604 members
Rate this:
Please Sign up or sign in to vote.
See more:
I'm new to this forum.. Updated as a new post by mistake.. sorry..


I know some basic C# and I wrote a program.
The program consumes the CPU due to a lot of calculations.
I took an i7-2600K and it still would take me several years to finish processing..

A friend told me that I can send massive calc to the GPU. After reading about it online I realized that this is the only possible solution for me.
I took an NVIDIA 470 and tried to use it with several DLL's with not much of understanding in how it's done.

Basically, I have a foreach loop that I need to send to the GPU
When it was multicored it was simple - I just changed the syntax to
parallel.Foreach, but to the GPU - I don't really understand how it's done without
changing the entire code - I just want to rap it so just part of it
will be send to the GPU.

Any thoughts ??

Please remember I'm new in this - explain me like I'm retarded :)

Many thanks,
Updated 27-Feb-12 12:04pm
OriginalGriff 26-Feb-12 3:09am
Sorry, but we can't. We do not have a clue what you algorithm is doing, or how it works, or anything about it really.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi, have you tried to read this Cudafy[^] or any of the other exelent articles on CodeProject?

One more thing; if your calculation would take years, i'd take a good look at the calculation itself. If you e.g. are doing matrix calculations and you are creating a new matix every time to store intermediate results you'll gain very little. The issue would be that the amount of memory allocations is just taking to much time.

Hope this helps,

Cheers, AT
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hello again
Sorry OriginalGriff, and others..
I've attached the loop I would like to send to the GPU.
As for Cudafy, I've stumbled upon it, and other dll's.. microsoft's, nvidia, etc.. and didn't understand nothing.
I realized the inner loop: foreach (decimal Quote in QuotesList) takes most of the processing time.. but the functions in there are written impeccable.
So back to my question, f I'll divide the Parallel.ForEach loop to the GPU - would it run faster? and if so, how it's done ??

Please forgive my newbidity and many thanks for your help

Parallel.ForEach<params10>(Params10List, parallelOptions, Prm10 =>     
    SectionParams T1 = new SectionParams();
    T1.TempWeek = TempWeek;
    T1.Counter = -1;
    StrategyData StrategyDataTempT1 = new StrategyData();
    StrategyDataTempT1.WeekResults = new List<decimal>();
    StrategyDataTempT1.Prm10 = Prm10;
    StrategyDataTempT1.Symbol = Symbol;
    StrategyDataTempT1.StrNumber = StrategyNumber;
    StrategyDataTempT1.SubStrNumber = Prm10.SubStrategyNum;
    Strategys StrategyT1 = new Strategys(Point, Spread, Prm10);   //Creates the Strategy here each time with different 'Prm10'.                                                           
    foreach (decimal Quote in QuotesList)  
        #region //Save weekly results:
        if (T1.TempWeek < DateTimeList[T1.Counter])  //sum of weeks Results :
            SaveWeekResults(StrategyDataTempT1, T1.LastWeekSum);
            T1.LastWeekSum = StrategyDataTempT1.TotalGain;
            T1.TempWeek = T1.TempWeek.AddDays(7);                      
        #endregion //(Save weekly results)
        T1.StrategyRequest = StrategyT1.OperateStrategy(Quote, StrategyNumber);
        #region//Strategy analysis:
        if (T1.StrategyRequest != 0)
            CalculateClosedDeals(Quote, ref Spread, ref T1, T1.StrategyRequest);                                         
            BuySellWithOrCounterDirection(ref StrategyDataTempT1, ref T1, ref QuotesList);
        T1.OpenDealsSum = CalculateOpenDeals(Quote, ref Spread, ref T1);                                              
        StrategyDataTempT1.TotalGain = T1.CloseDralsSum + T1.OpenDealsSum;
        CalcMaxDD(ref T1, StrategyDataTempT1);
        #endregion//(Strategy analysis)
    SaveWeekResults(StrategyDataTempT1, T1.LastWeekSum);
    T1.TempWeek = FirstSaturday;
    StrategyDataTempT1.TotalGain = Math.Round(StrategyDataTempT1.TotalGain, PointRound);   
    StrategyDataTempT1.MaxSizeDeal = T1.MaxSizeDeal;
    StrategyDataTempT1.DealSends = T1.DealSends;
    if (StrategyDataTempT1.MaxDD != 0)
        StrategyDataTempT1.GainToMaxDD = StrategyDataTempT1.TotalGain / StrategyDataTempT1.MaxDD;
        StrategyDataTempT1.GainToMaxDD = 0;

    #region //Calc STDEV:
    if (StrategyDataTempT1.TotalGain != 0)

        T1.Avg = StrategyDataTempT1.WeekResults.Average();
        foreach (decimal WResult in StrategyDataTempT1.WeekResults)
            T1.Value = WResult - T1.Avg;
            T1.sumOfDerivation += ((T1.Value) * (T1.Value));
        T1.DsumOfDerivation = (double)T1.sumOfDerivation;
        StrategyDataTempT1.STDEV = Math.Sqrt((1.0 / (double)StrategyDataTempT1.WeekResults.Count()) * T1.DsumOfDerivation);

        StrategyDataTempT1.STDEV = 0;

    #endregion //(Calc STDEV)

    #region //Save results to List :
    lock (StrategyDataList)
    #endregion //(Save results to List)

});//End of parallel section of T1!   

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100