Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #22139

Parallel FIB

From mhx@iae.nl (Marcel Hendrix)
Subject Parallel FIB
Newsgroups comp.lang.forth
Message-ID <62150201988434@frunobulax.edu> (permalink)
Date 2013-05-02 01:20 +0200
Organization Wanadoo

Show all headers | View raw


Here is a parallel version of the FIB benchmark (I am modernizing 
the Gforth benchmark set). 

I couldn't find a use for a 4th core, but the speedup is 
already about 7 times (2 times for a pure algorithm compare).

-marcel

-- ---------
ANEW -pfibs

NEEDS -tps

: fib ( n1 -- n2 )
    DUP 2 < IF
	DROP 1
    ELSE
	DUP
	1- RECURSE
	SWAP 2- RECURSE
	+
    ENDIF ;

0 VALUE n
VARIABLE fibs

\ ... f5          f4       f3       f2        f1             F0
\ ... (f6+f7)  (f5+f6)  (f5+f4)  (f4+f3)   (f3+f2)       f2+2f3+f4
\ ...                            (2f4+f5)  (f3+2f4+f5)   f3+4f4+2f5
\ ...                            (3f5+2f6) (3f4+2f5)     3f4+5f5+2f6
: pfib ( n1 -- n2 )
	TO n  n 6 < IF  n fib EXIT  ENDIF
	fibs OFF
	PAR
	  STARTP  n 4 - fib 3 * fibs LOCKED+! DROP  ENDP
	  STARTP  n 5 - fib 5 * fibs LOCKED+! DROP  ENDP
	  STARTP  n 6 - fib 2*  fibs LOCKED+! DROP  ENDP
	ENDPAR
	fibs @ ;

: sfib ( n1 -- n2 )
	TO n  n 6 < IF  n fib EXIT  ENDIF
	n 4 - fib 3 * 
	n 5 - fib 5 * +
	n 6 - fib 2*  + ;

: bench	CR ." \ serial FIB(47)   : " TIMER-RESET #47  fib U. .ELAPSED 
	CR ." \ new FIB(47)      : " TIMER-RESET #47 sfib U. .ELAPSED 
	CR ." \ parallel FIB(47) : " TIMER-RESET #47 pfib U. .ELAPSED ; 

\ FORTH> bench
\ serial FIB(47)   : 4807526976 46.130 seconds elapsed.
\ new FIB(47)      : 4807526976 13.344 seconds elapsed. 
\ parallel FIB(47) : 4807526976 7.018 seconds elapsed. ok

Back to comp.lang.forth | Previous | NextNext in thread | Find similar


Thread

Parallel FIB mhx@iae.nl (Marcel Hendrix) - 2013-05-02 01:20 +0200
  Re: Parallel FIB anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-02 14:13 +0000
    Re: Parallel FIB Paul Rubin <no.email@nospam.invalid> - 2013-05-02 08:25 -0700
    Re: Parallel FIB mhx@iae.nl (Marcel Hendrix) - 2013-05-03 07:04 +0200
      Re: Parallel FIB anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-03 12:26 +0000
        Re: Parallel FIB Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-03 15:23 +0200
          Re: Parallel FIB fred <email@address.com> - 2013-05-03 16:56 +0100
          Re: Parallel FIB Bernd Paysan <bernd.paysan@gmx.de> - 2013-05-03 18:13 +0200
        Re: Parallel FIB mhx@iae.nl (Marcel Hendrix) - 2013-05-03 21:14 +0200
          Re: Parallel FIB anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-05-04 13:45 +0000
        Re: Parallel FIB mhx@iae.nl (Marcel Hendrix) - 2013-05-03 21:29 +0200
          Re: Parallel FIB mhx@iae.nl (Marcel Hendrix) - 2013-05-03 23:53 +0200
            Re: Parallel FIB Paul Rubin <no.email@nospam.invalid> - 2013-05-03 18:10 -0700
              Re: Parallel FIB mhx@iae.nl (Marcel Hendrix) - 2013-05-04 07:07 +0200
                Re: Parallel FIB mhx@iae.nl (Marcel Hendrix) - 2013-05-06 21:09 +0200
        Re: Parallel FIB albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-05-04 00:26 +0000

csiph-web