1
#!/usr/bin/env scheme-script
(import (chezscheme))
(load-shared-object "./libnbody.so")

(define take-energy
  (foreign-procedure "take_energy" (long) double))

(cond ((pair? (cdr (command-line)))
       (let* ((n (string->number (cadr (command-line))))
              (st (current-time 'time-monotonic))
              (e (take-energy n))
              (et (current-time 'time-monotonic)))
         (printf "~,9f  per ~a sec ~%" e (time-difference et st))))
      (else (printf "Usage: ~a <n-iterations>~%" (car (command-line)))))

(define (compile-lib)
  (system "gcc -shared -O3 -fPIC -march=native -o libnbody.so libnbody.c"))

For immediate assistance, please email our customer support: [email protected]

Download RAW File