On Fri, Apr 16, 2021 at 01:48:13AM +0200, Kurt Pagani wrote:
> On 16.04.2021 00:39, Waldek Hebisch wrote:
> > On Thu, Apr 15, 2021 at 05:59:54PM +0200, Ralf Hemmecke wrote:
> >> I am calling an external program in a .spad file like this:
> >>
> >> systemCommand(cmd)$MoreSystemCommands
> >>
> >> where cmd is
> >>
> >> "system /usr/bin/zsolve-4ti2 DATA"
> >>
> >> When I switch on timing I get something like and call the function from
> >> my .spad file, I get
> >>
> >> Time: 0 (IN) + 0.04 (EV) + 0.00 (OT) = 0.05 sec
> >>
> >> although the actual computation (via 4ti2) took actually longer than one
> >> minute.
> >>
> >> Understandibly, the time spent in FriCAS is negligible, but is there
> >> some way to tell FriCAS to show the time spent in the external computation?
> > 
> > ATM no.  This requires support in operationg system which in turn
> > would require support in Lisp.  
> 
> According to
> https://stackoverflow.com/questions/6065446/executing-a-shell-command-from-common-lisp,
> "uiop:run-program" is a viable solution.
> "Trivial shell" also works fine: 
> https://common-lisp.net/project/trivial-shell/,
> however, requires some installations, whereas "uiop" loads with "(require 
> :asdf)".
> 
> syscmd(s) ==> systemCommand(s)$MoreSystemCommands
> lisp1(s)  ==> syscmd(string(FORMAT('NIL,"lisp ~A",s)$Lisp))
> 
> Example: sleep 2 sec
> 
> lisp1 "(require :asdf)"
> lisp1 "(time (uiop:run-program _"sleep 2_" :output *standard-output*))"
> 
> thus:
> 
> mysys(cmd) == lisp1(FORMAT('NIL, "(time (uiop:run-program _"~A_" _
>                     :output *standard-output*))", cmd)$Lisp)
> 
> 
> (11) -> mysys "sleep 4"
>    Compiling function mysys with type String -> Void
> Evaluation took:
>   4.049 seconds of real time
>   0.000000 seconds of total run time (0.000000 user, 0.000000 system)
>   0.00% CPU
>   4 forms interpreted
>   12,522,875,702 processor cycles
>   65,504 bytes consed

Sorry Kurt, I do not know what the command above are supposed to
solve.  First, ASDF does not "always" work:

)lisp (require :asdf)
 
   >> System error:
   Don't know how to REQUIRE ASDF.
See also:
  The SBCL Manual, Variable SB-EXT:*MODULE-PROVIDER-FUNCTIONS*
  The SBCL Manual, Function REQUIRE

Correctly setting up ASDF requieres some effort...

We can run shell commands, Ralf asked about having their  
CPU time counted to total CPU time (note that our time report
is about CPU time).  Avoiding poblematic dependency I did:

)lisp (time (sb-ext::run-program "/bin/sh" '("-c" "(yes | head -c 100000000 | 
wc)") :search t))

Evaluation took:
  3.420 seconds of real time
  0.004000 seconds of total run time (0.000000 user, 0.004000 system)
  0.12% CPU
  20 forms interpreted
  8,212,561,209 processor cycles
  32,768 bytes consed

This gives right real time (we can get it without using 'time'), but
CPU time does not count external program.

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/20210416013404.GA35584%40math.uni.wroc.pl.

Reply via email to