/mobile Handheld Friendly website

 performance measurements

Each table row shows performance measurements for this ATS program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
1,0000.100.11?2148  0% 8% 8% 100%
4,0001.571.581,3682148  0% 1% 0% 100%
16,00024.6524.6630,1482148  0% 0% 0% 100%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read mandelbrot benchmark to see what this program should do.

 notes

ATS/Anairiats version 0.2.8

 mandelbrot ATS program source code

(*
** The Computer Language Benchmarks Game
** http://benchmarksgame.alioth.debian.org/
**
** contributed by Hongwei Xi 
**
** compilation command:
**   atscc -D_GNU_SOURCE -D_ATS_MULTITHREAD -lpthread -msse2 -O3 mandelbrot2.dats -o mandelbrot2
**
*)

(* ****** ****** *)

#define TIMES 50
#define LIMIT 2.0; #define LIMIT2 (LIMIT * LIMIT)

(* ****** ****** *)

staload "libc/SATS/SIMD_v2df.sats" // no dynamic loading

(* ****** ****** *)

staload "libc/SATS/sched.sats"
staload TYPES = "libc/sys/SATS/types.sats"
macdef pid_t = $TYPES.pid_of_int

staload "libats/SATS/parworkshop.sats"
staload _ = "libats/DATS/parworkshop.dats"

(* ****** ****** *)

viewtypedef work = () -<lincloptr1> void
viewtypedef WSptr (l:addr) = WORKSHOPptr (work, l)

(* ****** ****** *)

fun fwork {l:agz}
  (ws: !WSptr l, wk: &work >> work?): int = let
  val wk = wk
  val pfun = __cast (wk) where {
    extern castfn __cast
      (wk: !work >> opt (work, i >= 1)): #[i:nat] uintptr i
  } // end of [val]
in
  if pfun >= (uintptr1_of_uint1)1U then let
    prval () = opt_unsome {work} (wk)
    val () = wk ()
    val () = cloptr_free (wk)
  in
    1 // the worker is to continue
  end else let
    val u = uint1_of_uintptr1 (pfun)
    val i = int_of_uint (u)
    prval () = opt_unnone {work} (wk)
    prval () = cleanup_top {work} (wk)
  in
    ~i // the worker is to pause or quit
  end // end of [if]
end // end of [fwork]

(* ****** ****** *)

#define i2d double_of_int

%{^
ATSinline()
ats_void_type output_byte (
  ats_ptr_type A, ats_int_type i, ats_byte_type b
) {
  ((char*)A)[i] = b ; return ;
} // end of [output_byte]
%}
extern
fun output_byte (A: ptr, i: int, b: byte): void = "output_byte"
// end of [output_byte]

(* ****** ****** *)

fn mandelbrot {l:agz}
  (ws: !WSptr l, A: ptr, h: int, w: int): void = let

  val h_rcp = 1.0 / (i2d h) and w_rcp = 1.0 / (i2d w)
  
  fun test (x: int, y: int):<cloref1> int = let
    val x2 = i2d (x << 1)
    val Cr0 = x2 * w_rcp - 1.5
    val Cr1 = (x2 + 2.0) * w_rcp - 1.5
    val y2 = i2d (y << 1)
    val Ci0 = y2 * h_rcp - 1.0
    val Ci1 = Ci0
    val Crv = v2df_make (Cr0, Cr1)
    val Civ = v2df_make (Ci0, Ci1)
  
    fun loop (
        eo: int
      , Cr: double, Ci: double, Zr: double, Zi: double
      , times: int
      ) :<fun1> int = let
      val Tr = Zr * Zr and Ti = Zi * Zi; val Tri = Tr + Ti
    in
      case+ 0 of
      | _ when Tri <= LIMIT2 => begin
          if times = 0 then eo else let
            val Zr_new = Tr - Ti + Cr; val Zi_new = 2.0 * (Zr * Zi) + Ci
          in
            loop (eo, Cr, Ci, Zr_new, Zi_new, times-1)
          end // end of [if]
        end // end of [_ when ...]
      | _ => 0
    end // end of [loop]
  
    fun loopv
      (Zrv: v2df, Ziv: v2df, times: int):<cloref1> int = let
      val Trv = Zrv * Zrv and Tiv = Ziv * Ziv; val Triv = Trv + Tiv
      val Tri0 = v2df_get_fst (Triv) and Tri1 = v2df_get_snd (Triv)
      val Zrv_new = Trv - Tiv + Crv
      val Ziv_new = (x + x) + Civ  where { val x = Zrv * Ziv }
    in
      case+ 0 of
      | _ when Tri0 <= LIMIT2 => begin case+ 0 of
        | _ when Tri1 <= LIMIT2 => begin
            if times = 0 then 0x3 else loopv (Zrv_new, Ziv_new, times-1)
          end // end of [_ when ...]
        | _ => begin
            if times = 0 then 0x2 else let
              val Zr0_new = v2df_get_fst (Zrv_new) and Zi0_new = v2df_get_fst (Ziv_new)
            in
              loop (0x2(*eo*), Cr0, Ci0, Zr0_new, Zi0_new, times-1)
            end // end of [if]
          end // end of [_]
        end // end of [_ when ...]
      | _ => begin case+ 0 of
        | _ when Tri1 <= LIMIT2 => begin
            if times = 0 then 0x1 else let
              val Zr1_new = v2df_get_snd (Zrv_new) and Zi1_new = v2df_get_snd (Ziv_new)
            in
              loop (0x1(*eo*), Cr1, Ci1, Zr1_new, Zi1_new, times-1)
            end // end of [if]
          end // end of [_ when ...]
        | _ => 0x0 // return value
        end // end of [_]
    end // end of [loopv]
  in
    loopv (v2df_0_0, v2df_0_0, TIMES)
  end // end of [test]
  
  #define i2b byte_of_int
  fun output_one (
      x: int, y: int, i: int, b: byte, n: natLte 8
    ) :<cloref1> void =
    if x < w then let
      val res = test (x, y); val res = i2b res in
      case+ 0 of
      | _ when n >= 2 => begin
          output_one (x + 2, y, i, (b << 2) + res, n - 2)
        end // end of [_ when ...]
      | _ (*n=0*) => let
          val () = output_byte (A, i, b) // A[i] = b
        in
          output_one (x + 2, y, i+1, res, 6)
        end // end of [_]
    end else begin
      output_byte (A, i, b << n)
    end // end of [if]
  // end of [output_one]
  
  macdef byte = byte_of_int
  val () = output_all (ws, 0) where {
    fun output_all {l:agz}
      (ws: !WSptr l, y: int):<cloref1> void =
      if y < h then let
        val () = workshop_insert_work (ws, f) where {
          val i = y * ((w + 7) / 8)
          val f = lam (): void =<lincloptr1> output_one (0, y, i, (byte)0, 8)
        } // end of [val]
      in
        output_all (ws, y+1) 
      end // end of [if]
    // end of [output_all]
  } // end of [val]  
  val () = workshop_wait_blocked_all (ws)
in
  // nothing
end // end of [mandelbrot]

(* ****** ****** *)

fun ncore_get (): int = let
  var cs: cpu_set0_t // uninitialized
  prval () = cpusetinit (cs) // not a real initialization
  stavar nset: int
  val nset = cpusetsize_get (cs)
  val err = sched_getaffinity ((pid_t)0, nset, cs)
  val () = assert_errmsg (nset >= 2, #LOCATION)
  var count: Nat = 0
  var i: Nat // uninitialized
  val () = for* (cs: cpu_set_t nset) =>
    (i := 0; i < 16; i := i + 1)
    if (CPU_ISSET (i, cs) > 0) then (count := count + 1)
  // end of [val]
in
  count
end // end of [ncore_get]

(* ****** ****** *)

%{^
ats_void_type
print_bytearr (
  ats_ptr_type A, ats_size_type sz
) {
  int n, lft = sz ;
  while (lft > 0) { n = fwrite (A, 1, lft, stdout) ; lft -= n ; }
  return ;
} // end of [print_bytearr]
%} // end of [%{^]


#define QSZ 1024

implement main (argc, argv) = let
  val () = assert_errmsg_bool1
    (argc >= 2, "Exit: wrong command format!\n")
  val i = int1_of_string (argv.[1])
  val () = assert_errmsg_bool1
    (i >= 2, "The input integer needs to be at least 2.\n")
//
  val ncore = ncore_get ()
  val nworker =
    (if (argc >= 3) then int_of argv.[2] else ncore): int
  // val () = (prerr "nworker = "; prerr nworker; prerr_newline ())
  val nworker = int1_of_int (nworker)
  val () = assert_errmsg (nworker > 0, #LOCATION)
  val ws = workshop_make<work> (QSZ, fwork)
  val _err = workshop_add_nworker (ws, nworker)
  val () = assert_errmsg (_err = 0, #LOCATION)
//
  val h = i
  val w8 = (i + 7) / 8
  val sz = h nmul w8
  val sz = size1_of_int1 (sz)
  val [l0:addr] (pfgc, pfarr | p) = malloc_gc (sz)
  val () = mandelbrot (ws, p, i, i)
  extern fun print_bytearr (A: ptr, sz: size_t): void = "print_bytearr"
  val () = begin
    printf ("P4\n%i %i\n", @(i, i)); if (h > 0) then print_bytearr (p, sz)
  end // end of [val]
  val () = free_gc (pfgc, pfarr | p)
//
  var i: Nat = 0
  val () = while (i < nworker) let
    val _quit = $extval (work, "(void*)0")
    val () = workshop_insert_work (ws, _quit) in i := i + 1
  end // end of [val]
  val () = workshop_wait_quit_all (ws)
  val () = workshop_free_vt_exn (ws)
in
  // nothing
end // end of [main]

(* ****** ****** *)

(* end of [mandelbrot2.dats] *)

 make, command-line, and program output logs

Wed, 23 Jan 2013 06:50:34 GMT

MAKE:
/usr/local/src/ats-lang-anairiats-0.2.9/bin/atscc -D_GNU_SOURCE -D_ATS_MULTITHREAD -lpthread -pipe -Wall -O3 -fomit-frame-pointer -march=native -mfpmath=sse -msse2 mandelbrot.dats -o mandelbrot.ats_run 
/usr/local/src/ats-lang-anairiats-0.2.9/bin/atsopt --output mandelbrot_dats.c --dynamic mandelbrot.dats
In file included from mandelbrot_dats.c:19:0:
/usr/local/src/ats-lang-anairiats-0.2.9/prelude/CATS/basics.cats: In function ‘atspre_fprint_newline’:
/usr/local/src/ats-lang-anairiats-0.2.9/prelude/CATS/basics.cats:271:11: warning: variable ‘n2’ set but not used [-Wunused-but-set-variable]
/usr/local/src/ats-lang-anairiats-0.2.9/prelude/CATS/basics.cats:271:7: warning: variable ‘n1’ set but not used [-Wunused-but-set-variable]
mandelbrot_dats.c: In function ‘fwork_0’:
mandelbrot_dats.c:303:1: warning: label ‘__ats_lab_fwork_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘loop_3’:
mandelbrot_dats.c:371:1: warning: label ‘__ats_lab_1_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c:346:1: warning: label ‘__ats_lab_0_1’ defined but not used [-Wunused-label]
mandelbrot_dats.c:345:1: warning: label ‘__ats_lab_0_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘loopv_4’:
mandelbrot_dats.c:489:1: warning: label ‘__ats_lab_7_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c:473:1: warning: label ‘__ats_lab_6_1’ defined but not used [-Wunused-label]
mandelbrot_dats.c:472:1: warning: label ‘__ats_lab_6_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c:468:1: warning: label ‘__ats_lab_5_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c:452:1: warning: label ‘__ats_lab_4_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c:435:1: warning: label ‘__ats_lab_3_1’ defined but not used [-Wunused-label]
mandelbrot_dats.c:434:1: warning: label ‘__ats_lab_3_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c:428:1: warning: label ‘__ats_lab_2_1’ defined but not used [-Wunused-label]
mandelbrot_dats.c:427:1: warning: label ‘__ats_lab_2_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘test_2’:
mandelbrot_dats.c:556:1: warning: label ‘__ats_lab_test_2’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘output_one_5’:
mandelbrot_dats.c:646:1: warning: label ‘__ats_lab_9_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c:630:1: warning: label ‘__ats_lab_8_1’ defined but not used [-Wunused-label]
mandelbrot_dats.c:629:1: warning: label ‘__ats_lab_8_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘__ats_fun_7’:
mandelbrot_dats.c:707:1: warning: label ‘__ats_lab___ats_fun_7’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘DEQUEptrnxt_01823_ats_clo_ptr_type’:
mandelbrot_dats.c:761:1: warning: label ‘__ats_lab_DEQUEptrnxt_01823_ats_clo_ptr_type’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘deque_insert_end_01804_ats_clo_ptr_type’:
mandelbrot_dats.c:790:1: warning: label ‘__ats_lab_deque_insert_end_01804_ats_clo_ptr_type’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘queue_insert_01781_ats_clo_ptr_type’:
mandelbrot_dats.c:811:1: warning: label ‘__ats_lab_queue_insert_01781_ats_clo_ptr_type’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘workshop_insert_work_01760_ats_clo_ptr_type’:
mandelbrot_dats.c:874:1: warning: label ‘__ats_lab_workshop_insert_work_01760_ats_clo_ptr_type’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘mandelbrot_1’:
mandelbrot_dats.c:962:1: warning: label ‘__ats_lab_mandelbrot_1’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘ncore_get_13’:
mandelbrot_dats.c:1019:1: warning: label ‘__ats_lab_11’ defined but not used [-Wunused-label]
mandelbrot_dats.c:1016:1: warning: label ‘__ats_lab_12’ defined but not used [-Wunused-label]
mandelbrot_dats.c:993:1: warning: label ‘__ats_lab_ncore_get_13’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘workshop_make_01753_ats_clo_ptr_type’:
mandelbrot_dats.c:1033:1: warning: label ‘__ats_lab_workshop_make_01753_ats_clo_ptr_type’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘deque_remove_beg_01807_ats_clo_ptr_type’:
mandelbrot_dats.c:1053:1: warning: label ‘__ats_lab_deque_remove_beg_01807_ats_clo_ptr_type’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘queue_remove_01783_ats_clo_ptr_type’:
mandelbrot_dats.c:1075:1: warning: label ‘__ats_lab_queue_remove_01783_ats_clo_ptr_type’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘workshop_remove_work_01761_ats_clo_ptr_type’:
mandelbrot_dats.c:1153:1: warning: label ‘__ats_lab_workshop_remove_work_01761_ats_clo_ptr_type’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘worker_19’:
mandelbrot_dats.c:1252:1: warning: label ‘__ats_lab_15_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c:1218:1: warning: label ‘__ats_lab_14_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c:1210:1: warning: label ‘__ats_lab_13_1’ defined but not used [-Wunused-label]
mandelbrot_dats.c:1209:1: warning: label ‘__ats_lab_13_0’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘workshop_add_worker_01758_ats_clo_ptr_type’:
mandelbrot_dats.c:1296:1: warning: label ‘__ats_lab_workshop_add_worker_01758_ats_clo_ptr_type’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘workshop_add_nworker_01759_ats_clo_ptr_type’:
mandelbrot_dats.c:1349:1: warning: label ‘__ats_lab_workshop_add_nworker_01759_ats_clo_ptr_type’ defined but not used [-Wunused-label]
mandelbrot_dats.c: In function ‘mainats’:
mandelbrot_dats.c:1441:1: warning: label ‘__ats_lab_17’ defined but not used [-Wunused-label]
mandelbrot_dats.c:1395:1: warning: label ‘__ats_lab_mainats’ defined but not used [-Wunused-label]
In file included from mandelbrot_dats.c:29:0:
mandelbrot_dats.c: At top level:
/usr/local/src/ats-lang-anairiats-0.2.9/prelude/CATS/pointer.cats:52:14: warning: ‘atspre_null_ptr’ defined but not used [-Wunused-variable]
In file included from mandelbrot_dats.c:30:0:
/usr/local/src/ats-lang-anairiats-0.2.9/prelude/CATS/printf.cats:57:1: warning: ‘atspre_fprintf_err’ defined but not used [-Wunused-function]
/usr/local/src/ats-lang-anairiats-0.2.9/prelude/CATS/printf.cats:69:1: warning: ‘atspre_fprintf_exn’ defined but not used [-Wunused-function]
/usr/local/src/ats-lang-anairiats-0.2.9/prelude/CATS/printf.cats:105:1: warning: ‘atspre_prerrf_exn’ defined but not used [-Wunused-function]
In file included from mandelbrot_dats.c:33:0:
/usr/local/src/ats-lang-anairiats-0.2.9/prelude/CATS/string.cats:351:14: warning: ‘atspre_stropt_none’ defined but not used [-Wunused-variable]
In file included from mandelbrot_dats.c:41:0:
/usr/local/src/ats-lang-anairiats-0.2.9/libc/CATS/SIMD_v2df.cats:57:15: warning: ‘atslib_v2df_1_1’ defined but not used [-Wunused-variable]
mandelbrot_dats.c:528:1: warning: ‘loopv_4_closure_make’ defined but not used [-Wunused-function]
mandelbrot_dats.c:595:1: warning: ‘test_2_closure_make’ defined but not used [-Wunused-function]
mandelbrot_dats.c:691:1: warning: ‘output_one_5_closure_make’ defined but not used [-Wunused-function]
mandelbrot_dats.c:942:1: warning: ‘output_all_6_closure_make’ defined but not used [-Wunused-function]
gcc -I/usr/local/src/ats-lang-anairiats-0.2.9/ -I/usr/local/src/ats-lang-anairiats-0.2.9/ccomp/runtime/ -L/usr/local/src/ats-lang-anairiats-0.2.9/ccomp/lib/ /usr/local/src/ats-lang-anairiats-0.2.9/ccomp/runtime/ats_prelude.c -D_GNU_SOURCE -D_ATS_MULTITHREAD -lpthread -pipe -Wall -O3 -fomit-frame-pointer -march=native -mfpmath=sse -msse2 mandelbrot_dats.c -o mandelbrot.ats_run -lats_mt -lats 
rm mandelbrot.dats
0.50s to complete and log all make actions

COMMAND LINE:
./mandelbrot.ats_run 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN

Revised BSD license

  Home   Conclusions   License   Play