The Computer Language
Benchmarks Game

thread-ring F# Mono LLVM #3 program

source code

(*  The Computer Language Benchmarks Game

    Contributed by Jomo Fisher

    Uses F# asyncs. Asyncs are triggered by tailcall in sequence as progress is 
    made around the ring. 
let ringLength = 503

let cells = Array.zeroCreate ringLength
let threads = Array.zeroCreate ringLength
let answer = ref -1

let createWorker i = 
    let next = (i+1)%ringLength
    async { let value = cells.[i]
            if false then () 
            match value with
            | 0 -> answer := i+1
            | _ -> 
                cells.[next] <- value - 1 
                return! threads.[next] }
let main args = 
    cells.[0] <- if args.Length>0 then int args.[0] else 50000000
    for i in 0..ringLength-1 do 
        threads.[i]<-createWorker i

    let result = Async.StartImmediate(threads.[0])
    printfn "%d" !answer


notes, command-line, and program output

32-bit Ubuntu one core
F# Compiler for F# 4.0 (Open Source Edition)
Mono JIT compiler version 4.5.1 (master/3e844dd Fri May  6 19:24:07 PDT 2016)
	LLVM:          yes(3.6.0svn-mono-master/9f79399)
	GC:            sgen

Sat, 07 May 2016 20:09:31 GMT

mv threadring.fsharp-3.fsharp threadring.fsharp-3.fs
/usr/local/bin/fsharpc --target:exe --platform:x86 -O  -o threadring.fsharp-3.fsharp_run.exe threadring.fsharp-3.fs
F# Compiler for F# 4.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License

/home/dunham/benchmarksgame_onecore/threadring/tmp/threadring.fsharp-3.fs(9,1): warning FS0221: The declarations in this file will be placed in an implicit module 'Threadring.fsharp-3' based on the file name 'threadring.fsharp-3.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file.
rm threadring.fsharp-3.fs
4.18s to complete and log all make actions

/usr/local/bin/mono --llvm --gc=sgen threadring.fsharp-3.fsharp_run.exe 50000000