English
Source / code snippets

Matrixmultiplikation, traditional method: Falk-schema

 

p.specht

this traditional Algorithmus is only sooner fully belegten Matrizen meaningfully. for so-called 'Sparse Matrices' (slight - mostly along the master- or Nebendiagonale besetzte Matrizen; such zurück insb. in the area Finite items method with Statikberechnungen on) there faster modes.
' traditional Matrixmultiplikation V1.3beta (demonstration by P.woodpecker. go ahead Timingzwecken virtual!)
' HIER GEWÜNSCHTE TESTDIMENSIONEN EINGEBEN:
' Lines,Split of A / plummeted Split s&, plummeted Lines t & of B
var z&= 1000 : var s&= 100 : var t&= 100
' preparation
Window Title "Traditionelle Matrixmultiplikation (only for Timingzwecke)"
Font 2:@Set("RandSeed",10):Cls rnd(8^8)
set("Decimals",18)
Declare A![z&,s&],B![s&,t&],C![z&,t&],i&,j&,k&,w!,tm&,a$
' Matrix A traditional with Zufallswerten <> 0 occupy
Print " Erforderlicher Speicherplatz: ";int(((z&*s&+s&*t&+z&*t&)*8));" Byte"
Print " Matrix-Zufallsbelegung..."
tm&=&GetTickCount
i&=1:While i&<=z&
j&=1:While j&<=s&
w!=(50000000-rnd(100000000))/rnd(50000000)+1
A![i&,j&]=w!
inc j&:Endwhile
inc i&:Endwhile
tm&=&GetTickCount-tm&
Print " Matrix A ("+st$(int(s&*z&))+" items) traditional occupied in "+st$(tm&)+" ms."
' &Index here genullt, there it only as speedy Loop needed becomes:
tm&=&GetTickCount
b![]=rnd(99999+0*&index)+1
tm&=&GetTickCount-tm&
Print " Matrix B ("+st$(int(s&*t&))+" items) Highspeed-zufallsbelegt in "+st$(tm&)+" ms."
' Possibility to Überprüfung the Matrixfunktion on hand plainer Matrizen:

If 0' Funktionstest 0 = Off , 1 = ON

    z&=2 : s&=2 : t&=2
    ' Matrix A =
    A![1,1]=2 : A![1,2]=0
    A![2,1]=0 : A![2,2]=1
    ' Matrix B =
    B![1,1]=2 : B![1,2]=0
    B![2,1]=0 : B![2,2]=1

Endif

Print " The Matrizen are verlinkt in wide "+st$(s&)+" A-Spalten=B-Lines."
Beep
Print " ";int(z&*s&*t&);" Multiplikationen and Additionen necessary."
print "\n to that Start the Matrixmultiplikation Button pressing!"
SetTimer 12000 : WaitInput : killtimer
Print "\n Berechnung the "+st$(int(z&*t&))+" items of C runs."
Print " One point standing each for "+st$(int(t&))+" finished items."
print " This will ca. "+st$(int(z&/61+1))+" Lines need."
' traditional Matrixmultiplikation
tm&=&GetTickCount
W!=0
i&=1:While i&<=z&
k&=1:While k&<=t&
w!=0
j&=1:While j&<=s&
w!=w!+A![i&,j&]*B![j&,k&]
inc j&:Endwhile
C![i&,k&]=w!
inc k&:Endwhile
print ".";
case %pos>61:print
case %csrlin>22:cls
inc i&:Endwhile:print
tm&=&GetTickCount-tm&
Beep
Print " 2 Matrizen multipliziert in "+ if( tm& > 9000 , st$(tm&\1000)+" sec." ,st$(tm&)+" ms." )
Print "\n Result C spend?"
WaitInput
case IsKey(27):end
case IsKey(78):end
' spending the Result-Matrix C
CLS
tm&=&GetTickCount
i&=1:While i&<=z&
print "********* row "+trim$(st$(i&))+"By "+trim$(st$(z&))+":  *********"
k&=1:While k&<=t&

if %csrlin>22:SetTimer 700: WaitInput :Killtimer:cls:endif

    Print "S"+trim$(st$(k&))+":"+stature$("%e",C![i&,k&]),
    case %pos > 50:print
    inc k&:Endwhile :print
    inc i&:Endwhile
    tm&=&GetTickCount-tm&
    Print "\n Matrix C outputted in " + if( tm& > 9000 , st$(tm&\1000)+" sec." , st$(tm&)+" ms." )
    WaitInput
    End
 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
04/17/21  
 




p.specht

with Assembler (XPSE) speed
Benchmark 1; a[100x100] * b[100x10]:
Interpreter 81.256 s / ProfComp: 23.565 s / XPSE-nProc: 0.234 s
Benchmark 2: a[1000x1000] * b[1000x400]:
Interp: 6h 22mins / ProfComp: 2481.222 s / XPSE-nProc: 116.02 s
Window Title "Beschleunigte Matrixmultiplikation"
' (CL) Copyleft 2012-09 P.woodpecker(at)gmx.at

if 0

     $DEFINE XPSE
     $IFDEF xpse
     {$cleq}
     $ENDIF

endif

Windowstyle 1048
window 0,0-%maxx,%maxy
randomize
font 2
cls rnd(8^8)
set("decimals",15)
set("numwidth",27)
declare z&,s&,t&,i&,j&,k&,status&
z&=100
s&=100
t&=100
dec z&:dec s&:dec t&
declare a![z&,s&],b![s&,t&],c![z&,t&]

whileLoop 0,s&

    a![&Loop,&Loop]=-1

endwhile

status&=show(z&,s&,a![]):print
b![]=rnd(1000)*10^(rnd(5)*(1-2*rnd(2)))
status&=show(s&,t&,b![]):print
var tm&=&GetTickCount
status&=Multipli(z&,s&,t&,addr(a![0,0]),addr(b![0,0]),addr(c![0,0]))
tm&=&GetTickCount-tm&
status&=show(s&,t&,c![]):print
print tm&/1000,"sec.\nREADY."
Waitinput
End

proc show

    parameters u&,v&,m![]

    if u&>5

        print u&+1;" values per Zeile"

    else

        declare mm!

        whileloop 0,u&:i&=&Loop

            whileloop 0,v&:j&=&Loop

                mm!=m![i&,j&]
                'if (mm!<10^10) and (mm!>10^-11) and (mm!<>0)
                print m![i&,j&],
                'else : print stature$("%e",m![i&,j&]), : endif

            endwhile

            print

            if %csrlin>30:waitinput:cls rnd(8^8):endif

            endwhile

            print

        endif

        return 1

    endproc

     $IFDEF xpse

    Nproc Multipli

        parameters z&,s&,t&,a_&,b_&,c_&
        declare sum!,prod!,aa!,bb!,cc!,i&,j&,k&

        WhileLoop 0,z&:i&=&Loop

            WhileLoop 0,t&:k&=&Loop

                sum!=0.0

                WhileLoop 0,s&:j&=&Loop

                    aa!=getfloat(a_&,8*(i&+(z&+1)*j&))
                    bb!=getfloat(b_&,8*(j&+(s&+1)*k&))
                    prod!=aa!*bb!
                    sum!=sum!+prod!

                endwhile

                setfloat(c_&,8*(i&+(s&+1)*k&),sum!)

            endwhile

        endwhile

        return 0

    endproc

     $ENDIF
    'Proc Multipli
    'parameters z&,s&,t &,a_&,b_&,c_&
    'declare sum!,prod!,aa!,bb!,cc!,i&,j&,k&
    'WhileLoop 0,z&
    'i&=&Loop
    'WhileLoop 0,t &
    'k&=&Loop
    'sum!=0
    'WhileLoop 0,s&
    'j&=&Loop
    'sum!=sum!+a![i&,j&]*b![j&,k&]
    'endwhile
    'c![i&,k&]=sum!
    'endwhile
    'locate 2,2:print trim$(st$(i&));
    'endwhile
    'return 0
    'endproc
 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/07/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

733 Views

Untitledvor 0 min.
Ernst07/21/21
Glubbfan06/19/21
Uwe ''Pascal'' Niemeier06/13/21
R.Schneider05/28/21
More...

Themeninformationen

this Topic has 1 subscriber:

p.specht (2x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie