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


Groups > comp.lang.forth > #20494

Re: pde2 floating point benchmark code

From mhx@iae.nl (Marcel Hendrix)
Subject Re: pde2 floating point benchmark code
Newsgroups comp.lang.forth
Message-ID <93771894008434@frunobulax.edu> (permalink)
Date 2013-03-09 17:58 +0200
References <19669094008434@frunobulax.edu>
Organization Wanadoo

Show all headers | View raw


mhx@iae.nl (Marcel Hendrix) wrote Re: pde2 floating point benchmark code

> Krishna Myneni <krishna.myneni@ccreweb.org> writes Re: pde2 floating point benchmark code

>> On Mar 8, 1:04 pm, m...@iae.nl (Marcel Hendrix) wrote:
>>> Krishna Myneni <krishna.myn...@ccreweb.org> writes Re: pde2 floating point benchmark code
[..]
> Here's an experimental approach.

[..]FORTH> 1e-5 GO
> dx = 1.000000e-1 dt = 1.000000e-2 error 4.153411e0  0.001 seconds elapsed.
> dx = 5.000000e-2 dt = 2.500000e-3 error 6.851562e-2  0.002 seconds elapsed.
> dx = 2.500000e-2 dt = 6.250000e-4 error 1.693734e-2  0.004 seconds elapsed.
> dx = 1.250000e-2 dt = 1.562500e-4 error 4.222571e-3  0.023 seconds elapsed.
> dx = 6.250000e-3 dt = 3.906250e-5 error 1.054911e-3  0.168 seconds elapsed.
> dx = 3.125000e-3 dt = 9.765625e-6 error 2.636820e-4  1.349 seconds elapsed.
> dx = 1.562500e-3 dt = 2.441406e-6 error 6.591764e-5  10.810 seconds elapsed.
> dx = 7.812500e-4 dt = 6.103516e-7 error 1.647923e-5  86.704 seconds elapsed.
> dx = 3.906250e-4 dt = 1.525879e-7 error 4.119797e-6  696.044 seconds elapsed. ok
[..]

This one works for 2 threads (but not for 4) and is indeed two times faster still.
I tried 4 threads, but apparently the interactions become too complex then and the
error doesn't decrease as fast as expected.

FORTH> 1e-5 GO
dx = 1.000000e-1 dt = 1.000000e-2 error 1.050422 1.874837 7.074819 4.268937e0  0.003 seconds elapsed.
dx = 5.000000e-2 dt = 2.500000e-3 error 1.051084 1.867074 7.040390 2.038034e-2  0.003 seconds elapsed.
dx = 2.500000e-2 dt = 6.250000e-4 error 1.051243 1.865146 7.031773 5.098856e-3  0.006 seconds elapsed.
dx = 1.250000e-2 dt = 1.562500e-4 error 1.051283 1.864665 7.029618 1.274944e-3  0.022 seconds elapsed.
dx = 6.250000e-3 dt = 3.906250e-5 error 1.051293 1.864545 7.029079 3.187503e-4  0.108 seconds elapsed.
dx = 3.125000e-3 dt = 9.765625e-6 error 1.051295 1.864515 7.028945 7.968847e-5  0.746 seconds elapsed.
dx = 1.562500e-3 dt = 2.441406e-6 error 1.051296 1.864508 7.028911 1.992217e-5  5.732 seconds elapsed.
dx = 7.812500e-4 dt = 6.103516e-7 error 1.051296 1.864506 7.028902 4.980547e-6  45.438 seconds elapsed.
dx = 3.906250e-4 dt = 1.525879e-7 error 1.051296 1.864505 7.028900 1.245137e-6  460.515 seconds elapsed. ok

-marcel

-- ------------
NEEDS -threads
ANEW -diffuse3

0.01e		 FVALUE dx 	\ 0.01 m
0.5e 		 FVALUE D	\ Diffusion coefficient
20e 		 FVALUE u_ext    
0.5e 		 FVALUE fk	\ choose dt so that fk < 0.5
dx FSQR f2/ D F/ FVALUE dt
1e fk F2* F-     FVALUE 1-2fk 

#10 		  VALUE nx

1e-5 FCONSTANT dxmin
10e dxmin F/ F>S 1+ =: nxmax  

CREATE x      nxmax DFLOATS ALLOT
CREATE u_x_0  nxmax DFLOATS ALLOT
CREATE u_j    nxmax DFLOATS ALLOT
CREATE u_jp1  nxmax DFLOATS ALLOT
CREATE golden 0e DF, 0e DF, 0e DF,

\ Compute the solution at t=1
\ Compute the absolute difference with the previous iteration
: res? ( F: -- err ) 
	CR ." dx = "  dx E. ." dt = "  dt E. ." error "  
	golden 0 DFLOAT[] DF@   u_j nx 7 #10 */ DFLOAT[] DF@ FDUP golden 0 DFLOAT[] DF!  FDUP F.  F- FSQR
	golden 1 DFLOAT[] DF@   u_j nx 8 #10 */ DFLOAT[] DF@ FDUP golden 1 DFLOAT[] DF!  FDUP F.  F- FSQR F+
	golden 2 DFLOAT[] DF@   u_j nx 9 #10 */ DFLOAT[] DF@ FDUP golden 2 DFLOAT[] DF!  FDUP F.  F- FSQR F+ 
	3e F/ FSQRT FDUP E. SPACE ;

: evolve1 ( -- )
	1e ( second) dt F/ F>S	2/  
	0 ?DO
		nx 2/ 1- 1 DO
			  u_j   I 1+ DFLOAT[] DF@  
			  u_j   I 1- DFLOAT[] DF@ F+ fk F*
			  u_j   I    DFLOAT[] DF@ 1-2fk F* F+  
			  u_jp1 I    DFLOAT[] DF!
		      LOOP
		u_jp1 1 DFLOAT[] DF@  u_jp1 0     DFLOAT[] DF!	\ b.c.: u_x(0, t) = 0
		nx 2/ 1- 1 DO
			  u_jp1 I 1+ DFLOAT[] DF@  
			  u_jp1 I 1- DFLOAT[] DF@ F+ fk F*
			  u_jp1 I    DFLOAT[] DF@ 1-2fk F* F+  
			  u_j   I    DFLOAT[] DF!
		      LOOP
		u_j   1 DFLOAT[] DF@  u_j   0     DFLOAT[] DF!  \ b.c.: u_x(0, t) = 0
	  LOOP  ;

: evolve2 ( -- )
	1e ( second) dt F/ F>S	2/  
	0 ?DO
		nx 1-  nx 2/ 1- 
			DO
			  u_j   I 1+ DFLOAT[] DF@  
			  u_j   I 1- DFLOAT[] DF@ F+ fk F*
			  u_j   I    DFLOAT[] DF@ 1-2fk F* F+  
			  u_jp1 I    DFLOAT[] DF!
		      LOOP
		u_jp1 1 DFLOAT[] DF@  u_jp1 0     DFLOAT[] DF!	\ b.c.: u_x(0, t) = 0
		nx 1-  nx 2/ 1-
			DO
			  u_jp1 I 1+ DFLOAT[] DF@  
			  u_jp1 I 1- DFLOAT[] DF@ F+ fk F*
			  u_jp1 I    DFLOAT[] DF@ 1-2fk F* F+  
			  u_j   I    DFLOAT[] DF!
		      LOOP
		u_j   1 DFLOAT[] DF@  u_j   0     DFLOAT[] DF!	\ b.c.: u_x(0, t) = 0
	  LOOP  ;

: evolve ( -- ) ( F: -- error )
	PAR
	  STARTP  evolve1  ENDP
	  STARTP  evolve2  ENDP
	ENDPAR	res? ;

: INIT ( F: dx -- )
	TO dx
	dx FSQR F2/ D F/ TO dt
	10e dx F/ F>S 1+ TO nx
    	nx nxmax > ABORT" init :: dx too small for preallocated array size" 
	0e nx 0 DO FDUP x     I DFLOAT[] DF! dx F+  LOOP  FDROP
	   nx 0 DO  1e  u_x_0 I DFLOAT[] DF!  	    LOOP
	u_ext  u_x_0 nx 1- DFLOAT[] DF!	\ b.c.: u(10, t) = u_ext
	u_x_0  u_j   nx  DFLOATS MOVE 
	u_x_0  u_jp1 nx  DFLOATS MOVE ;


-- Stop when difference between two last iterations not smaller than ERROR
: GO ( F: error -- )
	     FLOCAL error
	0.1e FLOCAL xstart 
	golden 3 DFLOATS ERASE
	BEGIN  
	   xstart INIT  
	   TIMER-RESET  evolve .ELAPSED
	   error F>  EKEY? 0= AND
	WHILE
	   xstart F2/ TO xstart
	REPEAT ;

0.01e init CR TIMER-RESET evolve FDROP .ELAPSED

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

pde2 floating point benchmark code krishna.myneni@ccreweb.org - 2013-03-04 18:02 -0800
  Re: pde2 floating point benchmark code Mark Wills <markrobertwills@yahoo.co.uk> - 2013-03-04 23:23 -0800
    Re: pde2 floating point benchmark code krishna.myneni@ccreweb.org - 2013-03-05 05:22 -0800
  Re: pde2 floating point benchmark code Doug Hoffman <glidedog@gmail.com> - 2013-03-05 12:11 -0500
    Re: pde2 floating point benchmark code krishna.myneni@ccreweb.org - 2013-03-05 16:11 -0800
      Re: pde2 floating point benchmark code Doug Hoffman <glidedog@gmail.com> - 2013-03-06 04:26 -0500
        Re: pde2 floating point benchmark code krishna.myneni@ccreweb.org - 2013-03-06 05:22 -0800
          Re: pde2 floating point benchmark code Doug Hoffman <glidedog@gmail.com> - 2013-03-06 09:44 -0500
  Re: pde2 floating point benchmark code krishna.myneni@ccreweb.org - 2013-03-05 16:17 -0800
    Re: pde2 floating point benchmark code mhx@iae.nl (Marcel Hendrix) - 2013-03-06 23:06 +0200
      Re: pde2 floating point benchmark code krishna.myneni@ccreweb.org - 2013-03-07 04:57 -0800
        Re: pde2 floating point benchmark code m.a.m.hendrix@tue.nl - 2013-03-07 05:49 -0800
        Re: pde2 floating point benchmark code mhx@iae.nl (Marcel Hendrix) - 2013-03-07 21:12 +0200
          Re: pde2 floating point benchmark code krishna.myneni@ccreweb.org - 2013-03-07 16:07 -0800
      Re: pde2 floating point benchmark code Doug Hoffman <glidedog@gmail.com> - 2013-03-10 09:17 -0400
        Re: pde2 floating point benchmark code mhx@iae.nl (Marcel Hendrix) - 2013-03-10 18:33 +0200
          Re: pde2 floating point benchmark code Doug Hoffman <glidedog@gmail.com> - 2013-03-11 04:54 -0400
    Re: pde2 floating point benchmark code humptydumpty <ouatubi@gmail.com> - 2013-03-07 22:32 -0800
      Re: pde2 floating point benchmark code Krishna Myneni <krishna.myneni@ccreweb.org> - 2013-03-08 05:19 -0800
        Re: pde2 floating point benchmark code mhx@iae.nl (Marcel Hendrix) - 2013-03-08 21:04 +0200
          Re: pde2 floating point benchmark code Krishna Myneni <krishna.myneni@ccreweb.org> - 2013-03-08 16:31 -0800
            Re: pde2 floating point benchmark code Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-03-09 00:56 +0000
              Re: pde2 floating point benchmark code Krishna Myneni <krishna.myneni@ccreweb.org> - 2013-03-08 19:52 -0800
                Re: pde2 floating point benchmark code Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2013-03-09 09:09 +0000
            Re: pde2 floating point benchmark code mhx@iae.nl (Marcel Hendrix) - 2013-03-09 13:37 +0200
              Re: pde2 floating point benchmark code Krishna Myneni <krishna.myneni@ccreweb.org> - 2013-03-09 06:28 -0800
              Re: pde2 floating point benchmark code mhx@iae.nl (Marcel Hendrix) - 2013-03-09 17:58 +0200
        Re: pde2 floating point benchmark code humptydumpty <ouatubi@gmail.com> - 2013-03-08 12:23 -0800
          Re: pde2 floating point benchmark code Krishna Myneni <krishna.myneni@ccreweb.org> - 2013-03-08 16:43 -0800

csiph-web