[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JCSP - Initial Questions



Hi Anne, and Neil,

I'll try and help where I can.

* On rewiring the network the One2OneChannel object has to be replaced
by an Any2OneChannel object or One2AnyChannel object, etc. How can a
process removed easily? There is a Parallel.removeProcess method that
will be executed before a call to run(). The Reader process above reads
continuously from channelB and never stops. How can I swap the Writer
for another in that case? Code after processPool.run() will not be
reached.
I pretty much agree with Neil's observation on this. The only other suggestion I have is to develop a dynamic multiplexer and sit it between reader and writer. See DynamicDelta in jcsp.plugNplay for the reverse example. This will require one more process, but will allow you to change the channels going into the multiplexer "on the fly", the Reader being connected to the multiplexor.

The Parallel construct in JCSP is very well designed. When a process is removed, the thread it used is kept and re-used when another process is added to the Parallel. This avoids a serious problem of many threads being created and allocated memory, yet are not being used.

A method to get past processPool.run() is to execute it within a ProcessManager construct, providing a mechanism similar to FORK in occam (although processes don't block at termination waiting for all FORKed off processes). For example:

ProcessManager procMan = new ProcessManager(processPool);
procMan.start();
// ... Carry on doing something else.

The other possibility is to have a process that wraps around the behavior process, and when it needs to change send a new process into the wrapping process to swap behaviors. This is mobile processes in its simplest form; see Fred Barnes's and Peter Welch's paper Communicating Mobile Processes at www.wotug.org for a more in depth discussion.
* How many threads are there actually? Has every channel, or every
"plug" of a channel their own thread? Or only the CSProcess objects?
Again, Neil is right, until you start using the networked capabilities. In that case, each Link to another Node and each NetChannelInput has a process allocated to it.

p.s. You don't have to create a new StandardChannelFactory object to create channels. The static methods of Channel allow you to get round this.

Code:
public static void main(String[] args) {
   One2OneChannel channelA = Channel.createOne2One();
   One2OneChannel channelB = Channel.createOne2One();
      Parallel processPool = new Parallel(
     new CSProcess[] {
         new Writer(channelA.out()),
new Incrementer(channelA.in(), channelB.out()), new Reader(channelB.in())
     }
   );

   processPool.run();
 }

Regards.

Kevin Chalmers
Research Student
Napier University
Edinburgh

Neil Brown wrote:
Hi Anne,

I will try to answer as many of your questions as best I can, inline.

Anne van Rossum wrote:
Dear list members,

Currently I am playing with the JCSP library. I wrote this code that has
a Writer that writes values on channelA, an Incrementer that increments
those values and a Reader that reads them and displays them at the
console:

Code:
public static void main(String[] args) {
    ChannelFactory channelFactory = new StandardChannelFactory();
    One2OneChannel channelA = channelFactory.createOne2One();
    One2OneChannel channelB = channelFactory.createOne2One();
       Parallel processPool = new Parallel(
      new CSProcess[] {
          new Writer(channelA.out()),
new Incrementer(channelA.in(), channelB.out()), new Reader(channelB.in())
      }
    );

    processPool.run();
  }

Questions:
I have the following questions regarding this example:
* The CSProcesses run parallel, but it is unclear how each process gets
its processing time. Maybe the Reader gets much more cycles than the
Writer. Who knows?
Pre-empting your later question too, each CSProcess in JCSP is its own Thread object. In a normal Parallel, all the threads have equal priority, so the cycles are worked out by the JVM (which usually just uses the underlying Operating System's threads). In most JCSP programs, a process will run until it performs a channel communication, at which point it will end up waiting for the other party in the communication, so the thread will be scheduled out.

* The CSProcesses may be placed in any order. The Incrementer can not
read a value from its input channel when it is not available. How is
this implemented? Is the Incrementer polling channelA? Or send channelA
an event to the Incrementer?
The underlying implementation uses Java's monitors. The Incrementer will wait on a monitor, thereby blocking it. Then other processes will get scheduled, and once a value is written to the channel the Incrementer will unblock again. There is no wasted time from polling the channel.
* The nomenclature of channel.in() and channel.out() is confusing.
Channel.out() should be the endpoint of the channel, not the output of
the component where a channel starts. If a channel is a first-class
entity, it should be treated like that.
I know Peter (one of the authors) is aware of this confusion. We think in a process-oriented manner, hence out() is from the perspective of the process. reader() and writer() would have been better - and may yet be used in future.
* The Parallel construct is rigid. Why is it not coupled to some kind of
"parallel" thread pool (or actually a process pool)? The implementation
of above gives all processes (supposedly) the same amount of processing
time in parallel. An "alternative" construct is also allowed. And some
implementing "priorities". That's it. How can I code other process pools
with other policies?
Put simply, JCSP does not have support for other policies. It is something that could probably be added with some work, but the design is simple: one process = one thread.
* On rewiring the network the One2OneChannel object has to be replaced
by an Any2OneChannel object or One2AnyChannel object, etc. How can a
process removed easily? There is a Parallel.removeProcess method that
will be executed before a call to run(). The Reader process above reads
continuously from channelB and never stops. How can I swap the Writer
for another in that case? Code after processPool.run() will not be
reached.
I do not completely understand this. Do you want to remove a process before the Parallel is run, or while it is running. The former does not seem very useful, the latter is dangerous. By the sounds of it you may also want to replace processes on the fly? That would usually be done by coding a custom process that changes its behaviour (in effect, becoming another process) when you send it a signal.

You are correct that the code after processPool.run() will not run. The next version of JCSP will feature a mechanism called poison, which allows for the graceful termination of process networks, which will allow for a clean shutdown, even of seemingly never-ending processes like the Reader.

* How many threads are there actually? Has every channel, or every
"plug" of a channel their own thread? Or only the CSProcess objects?
Just to repeat what I said previously - each process is its own thread. Nothing else is a thread.
Background:
What do I have in mind? I like to develop large-grain dataflow model
where the large-grain processes are aggregations of small-grain
processes (and have a better performance). If such a conversion (from
small to large-grain processes) can be automated, software will
automatically adjust to the amount and type of hardware processors
(multiple CPUs, FPGAs, etc.) For that:
* Different CSProcesses should be implemented;
* Those should be swapped for each other easily;
* Those should be compared w.r.t. performance;
* Aggregations of CSProcesses should be compared with the distinct
CSProcesses w.r.t. performance;
* Channels should be plugged somewhere else easily.
Etc. etc.

If you want different strata of processes, the next version of C++CSP will have two layers of processes - sub-thread processes with high-performance, composing thread-level processes. However, have you yet tested JCSP to make sure that its performance requires this extra work beyond the simple one process = one thread? I'm not clear if you are needing high-performance computing or not.

As for different CSProcesses - I'm not sure how easily Java supports mechanisms for concurrency besides the standard threads. Do you have an idea for another way of doing things?

I hope that helps, and I hope we can find a way for JCSP to fit your needs.

Thanks,

Neil.




This message is intended for the addressee(s) only and should not be read, copied or disclosed to anyone else outwith the University without the permission of the sender.
It is your responsibility to ensure that this message and any attachments are scanned for viruses or other defects. Napier University does not accept liability for any loss
or damage which may result from this email or any attachment, or for errors or omissions arising after it was sent. Email is not a secure medium. Email entering the University's system is subject to routine monitoring and filtering by the University.