On Tue, Jun 27, 2023 at 03:32:30PM +0200, Ralf Hemmecke wrote:
> On 27.06.23 14:07, Waldek Hebisch wrote:
> > > > Both Lisp version and the above behave rather badly when called
> > > > from command line (the same is true for parseAndEvalStr).
> > > > Namely, after calling it interpreter is apparently waiting
> > > > for more input from the string, but none is coming. So
> > > > command line is effectively blocked. Probably does not
> > > > matter for server style use, but definitely it is not "universal"
> > > > function.
> > >
> > > Maybe I do not quite get what you say. Is it: "The function works nicely,
> > > but the user cannot send another string during the time the first call to
> > > interpret_block is running?" In other words I cannot have two instances of
> > > interpret_block running at the same time?
> > > I wonder how this could be ever relevant when FriCAS anyway uses just one
> > > processor.
> >
> > To explain more: interpret_block gets simple input and should do its
> > work in almost no time, but apparently it never finishes. I must
> > admit that natural question is how it can work at all in
> > webspad? I did not look but probably some of extra variable
> > setting causes it to finish.
>
> Oh... that sounds scary. I never saw that my |interpret-block| lisp function
> did not return, OK, only for long running processes that are expected not to
> return.
>
> > BTW: To see what I mean try
> >
> > s := "1 + 1"
> > interpret_block(s)$Lisp
>
> Yes, I also see that with pure FriCAS and even loading the boot function
> into a jfricas session and executing interpret_block(s)$Lisp never returns.
>
> Hmmm, strange. But then I never call interpret-block directly in
> webspad.lisp. In fact, it can have two reasons. One is this:
>
> (defun |webspad-parseAndEvalStr| (code)
> (setf |$printStorageIfTrue| T) ; Make sure we get "Storage:" line.
> (setf |$fortranFormat| NIL) ; we don't want Fortran output
> (setf |$htmlFormat| NIL) ; we don't want Html output
> (setf |$openMathFormat| NIL) ; we don't want OpenMath output
> (setf |$MARGIN| 0) ; we don't want indentation
> (eq (catch 'SPAD_READER (catch '|top_level| (|interpret-block| code)))
> '|restart|))
>
> and if that is not sufficient to return, then webspad only calls that
> function after having modified a number of streams.
>
> https://github.com/fricas/jfricas/blob/master/jfricas/webspad.lisp#L155
>
> I suspect that it is the last line in |webspad-parseAndEvalStr| that saves
> me. Unfortunately, I were completely lost if I had to explain why this line
> is there and what would happen if I removed it.
The last line is to make sure that in case of errors webspad-parseAndEvalStr
is still in control. Otherwise control would pass to top level of the
interpreter. This affects only error handling, in normal case this
should be no-op.
> > > Although it would be an interesting idea to send and evaluate other input
> > > to
> > > FriCAS during a long running command, but wouldn't that badly interfere
> > > with
> > > session management? When the first command does something like "z:=1; for
> > > i
> > > in 1..10^100 repeat print(i)" and the second one says "z:=2", would the
> > > first one suddenly print 2?
> >
> > Not a problem at all. Effectively this is done when you run
> > Hyperdoc examples.
>
> But you maybe saying that hyperdoc runs in a different frame, so my current
> session is actually not affected.
Yes.
> BTW, HyperDoc probably starts a completely new FriCAS process with no
> assigned variables whatsoever. Or will it contact the running kernel and
> just use a new frame?
Hyperdoc connects to running FriCAS. For example, when you compile a
new domain this would unknown to other process, but Hyperdoc has
info about new domain.
> Actually, my question is whether it would be possible to clone a running
> fricas session and continue with some computation in one clone with at the
> same time with another computation in another clone?
Well, that is what Unix fork is doing. Camm did this for GCL (I am
not sure if it was experimental version or regular one). For sbcl
there is extra factor, namely sbcl uses threads so there would be
some effort to avoid confusion within sbcl. However, it is not
clear if such form of parallelizm is really better than separate
processes: after fork processes are separate.
> Yes, I somehow want to
> use the many processors on my machine and are always sad that I must start
> two completely separate fricas sessions with only string communication
> between them. Somehow more parallelism in FriCAS would be wonderful...
> dream, dream.
Well, I am not aware of a CAS that can work really in parallel fashion.
Namely, CAS has things like symbol tables/caches and one needs to
for correct operation one needs to serialize access to such structures.
The effect could be that parallel version on many processors is
slower than serial version on single processor. Namely, on symbol
table intensive code real work is likely to be serial anyway, but
_possiblity_ of access from different threads leads to slowdown.
What is done is to give parallel implementations to performance
critical routines. For example parallel operations on big matrices
or on big polynomials.
--
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/ZJr0IkFYmsZSExH2%40fricas.math.uni.wroc.pl.