The Computer Language
23.03 Benchmarks Game

mandelbrot Python 3 #5 program

source code

# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
#
# contributed by Tupteq
# modified by Simon Descarpentries
# modified by Ivan Baldin
# 2to3 plus Daniel Nanz fix

import sys
from array import array
from multiprocessing import Pool

def do_row(fy):
    local_abs = abs
    two_over_size = 2.0 / size
    xr_offs = range(7, -1, -1)
    xr_iter = range(50)

    result = array('B')
    for x in range(7, size, 8):
        byte_acc = 0
        for offset in xr_offs:
            z = 0j
            c = two_over_size * (x - offset) + fy

            for i in xr_iter:
                z = z * z + c
                if local_abs(z) >= 2:
                    break
            else:
                byte_acc += 1 << offset

        result.append(byte_acc)

    if x != size - 1:
        result.append(byte_acc)

    return result.tostring()

def main(out):
    out.write(('P4\n%d %d\n' % (size, size)).encode('ASCII'))

    pool = Pool()
    step = 2.0j / size
    for row in pool.imap(do_row, (step*y-(1.5+1j) for y in range(size))):
        out.write(row)

if __name__ == '__main__':
    size = int(sys.argv[1])
    main(sys.stdout.buffer)
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Python 3.11.1


Tue, 24 Jan 2023 19:45:08 GMT

MAKE:
mv mandelbrot.python3-5.python3 mandelbrot.python3-5.py
pyright .
No configuration file found.
No pyproject.toml file found.
stubPath /home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/typings is not a valid directory.
Assuming Python platform Linux
Searching for source files
Found 1 source file
pyright 1.1.288
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/mandelbrot.python3-5.py
  /home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/mandelbrot.python3-5.py:35:8 - error: "x" is possibly unbound (reportUnboundVariable)
  /home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/mandelbrot.python3-5.py:36:23 - error: "byte_acc" is possibly unbound (reportUnboundVariable)
  /home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/mandelbrot.python3-5.py:38:19 - error: Cannot access member "tostring" for type "array[int]"
    Member "tostring" is unknown (reportGeneralTypeIssues)
3 errors, 0 warnings, 0 informations 
Completed in 1.979sec
make: [/home/dunham/all-benchmarksgame/2000-benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:388: mandelbrot.python3-5.python3_run] Error 1 (ignored)

3.71s to complete and log all make actions

COMMAND LINE:
/opt/src/Python-3.11.1/bin/python3 -OO mandelbrot.python3-5.py 1000

PROGRAM FAILED 


(BINARY) PROGRAM OUTPUT NOT SHOWN

multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/opt/src/Python-3.11.1/lib/python3.11/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/mandelbrot.python3-5.py", line 38, in do_row
    return result.tostring()
           ^^^^^^^^^^^^^^^
AttributeError: 'array.array' object has no attribute 'tostring'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/mandelbrot.python3-5.py", line 50, in <module>
    main(sys.stdout.buffer)
  File "/home/dunham/all-benchmarksgame/benchmarksgame_i53330/mandelbrot/tmp/mandelbrot.python3-5.py", line 45, in main
    for row in pool.imap(do_row, (step*y-(1.5+1j) for y in range(size))):
  File "/opt/src/Python-3.11.1/lib/python3.11/multiprocessing/pool.py", line 873, in next
    raise value
AttributeError: 'array.array' object has no attribute 'tostring'