1

我重写了基准游戏mandelbot Smalltalk 程序,使用四核,有时有效,有时失败

在这里,我将代码简化为几种方法,足以在我的计算机上重现问题。(粘贴到纯文本文件中,另存为“example.st”并按照构建和运行说明进行操作)。

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


!Core.Example class methodsFor: 'testing'!

program
   | answers unusedParams workers |

     "write pbm header & then switch to binary mode"
   Stdout
      nextPutAll: 'P4'; nextPut: Character lf; 
      print: 16000; space; print: 16000; nextPut: Character lf;
      binary.

   workers := MatriX.VirtualMachines new: 4.
   [ 
      unusedParams := #(#a #b #c #d).
      answers := workers do: [:z| Example mandelbrotBits] with: unusedParams. 
      answers do: [:eachByteArray| Stdout nextPutAll: eachByteArray; flush].

   ] ensure: [workers release].
   ^''!


mandelbrotBits
   | s |
   s := WriteStream on: (ByteArray new: 8192).
   0 to: 4000 do: [ :y |
      0 to: 15999 do: [ :x |
         s nextPut: 1.
      ]
   ].
   ^s contents! !

构建和运行说明:

cp /usr/local/src/vw8.2pul/image/visualnc64.im example.im

/usr/local/src/vw8.2pul/bin/linuxx86_64/vwlinuxx86_64 example.im -nogui -pcl MatriX -filein example.st -doit 'ObjectMemory snapshotThenQuit'

/usr/local/src/vw8.2pul/bin/linuxx86_64/vwlinuxx86_64 example.im -nogui -evaluate "Example program" > out

堆栈跟踪:

Unhandled exception: Xtreams.Incomplete

----------------------------------------------------------------------
optimized [] in MatriX.VirtualMachines>>do:actions:arguments:
Receiver:
    an UndefinedObject
Arguments:
    job = an Array[4]
    exception = a Xtreams.Incomplete
Context PC = 8

----------------------------------------------------------------------
Dictionary>>keysAndValuesDo:
Receiver:
    a Dictionary
Instance Variables:
    tally = 1
Arguments:
    aBlock = BlockClosure [] in MatriX.VirtualMachines>>do:actions:arguments:
Temporaries:
    index = 2
    elem = #(BlockClosure [] in [] in Example class>>program #(#d) BlockClosure [] in [] in MatriX.VirtualMachines>>do:actions:arguments: BlockClosure [] in [] in MatriX.VirtualMachines>>do:actions:arguments:) -> a Xtreams.Incomplete
Context PC = 36

----------------------------------------------------------------------
MatriX.VirtualMachines>>do:actions:arguments:
Receiver:
    a MatriX.VirtualMachines
Instance Variables:
    machines = an OrderedCollection[4]
    closeBlock = BlockClosure [] in MatriX.VirtualMachines class>>withAll:
    machinesLock = a Semaphore[0]
    work = an OrderedCollection[0]
    workLock = a Semaphore[0]
    workReady = a Semaphore[4]
Arguments:
    numberOfJobs = 4
    actionsBlock = BlockClosure [] in MatriX.VirtualMachines>>actionsBlock:
    argumentsBlock = BlockClosure [] in MatriX.VirtualMachines>>do:with:
Temporaries:
    results = an Array[4]
    exceptions = a Dictionary[1]
    workComplete = a Semaphore[0]
Context PC = 67

----------------------------------------------------------------------
MatriX.VirtualMachines>>do:with:
Receiver:
    a MatriX.VirtualMachines
Instance Variables:
    machines = an OrderedCollection[4]
    closeBlock = BlockClosure [] in MatriX.VirtualMachines class>>withAll:
    machinesLock = a Semaphore[0]
    work = an OrderedCollection[0]
    workLock = a Semaphore[0]
    workReady = a Semaphore[4]
Arguments:
    actions = BlockClosure [] in [] in Example class>>program
    aObjects = an Array[4]
Context PC = 14
4

0 回答 0