3 Replies - 379 Views - Last Post: 28 August 2013 - 09:10 PM Rate Topic: -----

#1 Raminator  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 283
  • Joined: 16-July 12

Using VB.NET for calculations... On a VGA!

Posted 28 August 2013 - 08:25 PM

So, going back to an old project of mine, Brown Numbers!, but now with a totally different objective. The calculating part has been done for ages, but i've been thinking, what if i get it to run on a GPU instead of the CPU, calculations would happens much faster!(I guess). I have an ATI Radeon HD6870, and i was wondering how would it be possible to send the calculations to the GPU, instead of doing them "locally", also, code for the brown number calculator below.
Imports System.Numerics
Imports System.IO
Imports System.Text
Module Module1
    Dim nn As BigInteger = 1
    Dim square As BigInteger
    Dim count As BigInteger = 50
    Dim factorial(2) As BigInteger
    Dim filename As String = "C:\Users\Arengorn\Desktop\bnlog.txt"
    Dim sw As StreamWriter = File.CreateText(filename)
    Sub Main()

        For nn = 1 To count
            count = count * count
            factorial(0) = getfact(nn)
            factorial(1) = factorial(0) + 1
            square = getsqrt(factorial(1))
            If (square <> 0) Then
                writeresult()
                ' log()
                'troubleshoot()
            End If
        Next
    End Sub
    Private Sub troubleshoot()
        Console.Write(nn)
        Console.Write(",")
        Console.Write(factorial(0))
        Console.Write(",")
        Console.Write(factorial(1))
        Console.Write(",")
        Console.WriteLine(square)
    End Sub
    Private Sub writeresult()
        Console.Write("(")
        Console.Write(nn)
        Console.Write(",")
        Console.Write(square)
        Console.Write(")")
        Console.WriteLine(" ")
    End Sub
    Private Sub log()
        sw.WriteLine(nn)
        sw.WriteLine(square)
        sw.WriteLine("")
    End Sub
    Function getfact(ByVal num As BigInteger) As BigInteger
        Dim fact As BigInteger = 1
        For c As BigInteger = 1 To num
            fact = fact * c
        Next
        Return (fact)
    End Function
    Function getsqrt(ByVal sq As BigInteger) As BigInteger
        Dim upperbound As BigInteger
        Dim lowerbound As BigInteger
        Dim guess As BigInteger
        Dim guessguess As BigInteger
        Dim keepgoing As Boolean = True
        getsqrt = 0
        upperbound = sq / 4
        lowerbound = 0
        Do While keepgoing
            guess = ((upperbound - lowerbound) / 2) + lowerbound
            guessguess = guess * guess
            If (guessguess = sq) Then
                getsqrt = guess
                keepgoing = False
            Else
                If (guessguess > sq) Then
                    upperbound = guess
                End If
                If (guessguess < sq) Then
                    lowerbound = guess
                End If
                If (lowerbound = upperbound) Or (lowerbound + 1 = upperbound) Then
                    keepgoing = False
                End If
            End If
        Loop
    End Function
End Module



Is This A Good Question/Topic? 0
  • +

Replies To: Using VB.NET for calculations... On a VGA!

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2240
  • View blog
  • Posts: 9,410
  • Joined: 29-May 08

Re: Using VB.NET for calculations... On a VGA!

Posted 28 August 2013 - 08:52 PM

Nope. .Net currently limited to CPU parallelisation.

You'll need to use something like C++ along with AMP/CUDA
Was This Post Helpful? 1
  • +
  • -

#3 Raminator  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 283
  • Joined: 16-July 12

Re: Using VB.NET for calculations... On a VGA!

Posted 28 August 2013 - 08:57 PM

View PostAdamSpeight2008, on 29 August 2013 - 03:52 AM, said:

Nope. .Net currently limited to CPU parallelisation.

You'll need to use something like C++ along with AMP/CUDA

Hmm, interesting idea. I never really tried C or C++ for real, only C for learning programming logic. I'll step into it, but, on your opinion, from a scale from 0 to 100 in difficulty where would this be?
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2240
  • View blog
  • Posts: 9,410
  • Joined: 29-May 08

Re: Using VB.NET for calculations... On a VGA!

Posted 28 August 2013 - 09:10 PM

I have know Idea.

Is your problem suitable for paralielisation?
Its tends to be best for stuff that has independent calculations. Eg matrix multiply

Have a look at a talk called The Elephant in the CPU
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1