The Computer Language
24.04 Benchmarks Game

mandelbrot VW Smalltalk #2 program

source code

"* The Computer Language Benchmarks Game
    https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
    contributed by Paolo Bonzini 
    reworked for multicore by Isaac Gouy *"!


Smalltalk.Core defineClass: #BenchmarksGame
    superclass: #{Core.Object}
    indexedType: #none
    private: false
    instanceVariableNames: ''
    classInstanceVariableNames: ''
    imports: ''
    category: ''!

!Core.BenchmarksGame class methodsFor: 'benchmarks game'!

do: n
   Stdout
      nextPutAll: 'P4'; nl; 
      print: n; space; print: n; nl;
      binary.

   self splitCombinePutMandelbrot: n on: Stdout.
   ^''!

splitCombinePutMandelbrot: anInteger on: aStream
   | chunks chunkSize extent first last nprocs workers |
   nprocs := (ExternalProcess shOne: 'nproc') asNumber + 5.

   workers := MatriX.VirtualMachines new: nprocs.
   [   
      chunkSize := anInteger // nprocs + 1.
      first := (0 to: (nprocs - 1)) collect: [:each| (each * chunkSize + 1) - 1].
      last := first collect: [:each| (each + chunkSize - 1) min: (anInteger - 1)].
      extent := first collect: [:each| anInteger].

      chunks := workers 
         do: [ :i :j :n | BenchmarksGame mandelbrotRowsFrom: i to: j for: n]
         with: first 
         with: last
         with: extent.

      chunks do: [:each| aStream nextPutAll: each].

   ] ensure: [workers release].!

mandelbrotRowsFrom: first to: last for: extent
   | s |
   s := ReadWriteStream on: (ByteArray new: 8192).
   self putMandelbrotRowsFrom: first to: last for: extent on: s.
   ^s contents!

putMandelbrotRowsFrom: first to: last for: extent on: aStream
   | bits ci cr i limit2 m stepi stepr tr zi zr |
   limit2 := 4.0d0.
   m := 50.

   stepr := 2.0d0 / extent.
   stepi := 2.0d0 / extent.

   first to: last do: [ :y |
      bits := 0.
      ci := stepi * y asFloat - 1.0d0.
      0 to: extent - 1 do: [ :x |
         cr := stepr * x asFloat - 1.5d0.
         zr := cr. zi := ci.

         bits := bits bitShift: 1.
         i := 1.  
         [
            tr := (zr*zr) - (zi*zi) + cr.
            zi := 2.0d0 * zr * zi + ci.
            zr := tr.
            (zr*zr) + (zi*zi) < limit2 and: [ (i := i + 1) < m ]
         ] whileTrue.

         i = m ifTrue: [ bits := bits + 1 ].
         (x bitAnd: 7) == 7 ifTrue: [
            aStream nextPut: bits.
            bits := 0.
         ]
      ]. 
      (extent bitAnd: 7) == 0 ifFalse: [
         bits := bits bitShift: 8 - (extent bitAnd: 7).
         aStream nextPut: bits.
      ]
   ]! !

!Core.Stream methodsFor: 'benchmarks game'!

nl
   self nextPut: Character lf! !
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
VisualWorks® 8.3
Aug 19 2017


 Tue, 05 Mar 2024 07:14:55 GMT

MAKE:
cp /opt/src/vw8.3pul/image/visualnc64.im mandelbrot.vw-2.vw_run.im
/opt/src/vw8.3pul/bin/visual mandelbrot.vw-2.vw_run.im -nogui -pcl MatriX -filein mandelbrot.vw-2.vw -doit 'ObjectMemory snapshotThenQuit'

Autoloading MatriX from $(VISUALWORKS)/preview/matrix/MatriX.pcl
Autoloading Xtreams-Support from $(VISUALWORKS)/xtreams/Xtreams-Support.pcl
Autoloading Xtreams-Core from $(VISUALWORKS)/xtreams/Xtreams-Core.pcl
Autoloading Xtreams-Terminals from $(VISUALWORKS)/xtreams/Xtreams-Terminals.pcl
Autoloading Xtreams-Transforms from $(VISUALWORKS)/xtreams/Xtreams-Transforms.pcl
Autoloading Xtreams-Substreams from $(VISUALWORKS)/xtreams/Xtreams-Substreams.pcl
Autoloading Xtreams-Multiplexing from $(VISUALWORKS)/xtreams/Xtreams-Multiplexing.pcl
Filing in from:
	mandelbrot.vw-2.vw
BenchmarksGame class<benchmarks game
Stream<benchmarks game
Do you want to add Root.Smalltalk.Core.Stream>>nl to the previously unchanged package, Collections-Streams
						OK to continue?
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/mandelbrot.vw-2.vw_run.im created at March 4, 2024 11:14:32 PM
7.86s to complete and log all make actions

COMMAND LINE:
 /opt/src/vw8.3pul/bin/visual mandelbrot.vw-2.vw_run.im -nogui -evaluate "BenchmarksGame do: 16000"

(BINARY) PROGRAM OUTPUT NOT SHOWN