changeset 2371:c84282ec1654 octave-forge

Changed the directory structure to match the package system
author hauberg
date Sun, 20 Aug 2006 13:45:44 +0000
parents 24d6a5cdedfe
children 38e4c6572b8d
files main/parallel/COPYING main/parallel/DESCRIPTION main/parallel/Makefile main/parallel/README main/parallel/connect.cc main/parallel/doc/README main/parallel/getid.m main/parallel/inst/getid.m main/parallel/inst/scloseall.m main/parallel/inst/server.m main/parallel/pserver.cc main/parallel/recv.cc main/parallel/reval.cc main/parallel/sclose.cc main/parallel/scloseall.m main/parallel/send.cc main/parallel/server.m main/parallel/src/Makefile main/parallel/src/connect.cc main/parallel/src/pserver.cc main/parallel/src/recv.cc main/parallel/src/reval.cc main/parallel/src/sclose.cc main/parallel/src/send.cc main/parallel/src/swab.h main/parallel/swab.h
diffstat 26 files changed, 2242 insertions(+), 1893 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/COPYING	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,339 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+                          675 Mass Ave, Cambridge, MA 02139, USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                            NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) 19yy  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) 19yy name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/DESCRIPTION	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,10 @@
+Name: Parallel
+Version: 1.0.0
+Date: 2006-08-05
+Author: Hayato Fujiwara
+Maintainer: Hayato Fujiwara
+Title: Parallel Computing.
+Description: Add a description to this package!
+Depends: octave (>= 2.9.7)
+License: GPL version 2 or later
+Url: http://octave.sf.net
--- a/main/parallel/Makefile	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-
-sinclude ../../Makeconf
-
-OCTS = sclose.oct  connect.oct pserver.oct  \
-	recv.oct  reval.oct  send.oct
-
-
-all: $(OCTS)
-
-clean: ; -$(RM) *.o core octave-core *.oct *~
--- a/main/parallel/README	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,145 +0,0 @@
-
-Octave parallel execution package for cluster computers
-
-Description
-
- This is a package to add parallel computing functions to Octave. The
-parallel computing functions are supported without any additional
-parallel computing libraries such as MPI and PVM.  The operation has
-been confirmed only on Linux (but it may be applicable to other
-operating systems).
-
-
-
-Requirements
-
- 1. GNU Octave 2.1.43 that is available at http://www.octave.org/
- 2. two or more computers
-
-
-
-How to use
- Note first that this package assumes the use in a multiple-computer 
- system consisting of a master (your console) computer and some 
- slave computers.  Run Octave with argument "server.m" on every slave 
- computer.
-
- $ octave /usr/local/share/octave/2.1.43/site/m/octave-forge/parallel/server.m
-
- Run Octave without argument "server.m" on the master computer
-
- $ octave -q -f script.m 
-  or
- $ octave
-
- > script
-
-
-
-Command references
-
-connect (hosts) 
- Make bi-directional connections among the computers specified by 
- the matrix "hosts" and return the matrix of the sockets (file 
- descriptors) directed to the listed computers.
- This command should be executed on the master computer before 
- starting parallel computation. For example, 
- you can execute the following command on the master computer:
-        connect ([ "host1"; "host2"; "host3" ])
-                => [ 0, 0; 5, 3; 6, 4 ]
- where host1, host2 and host3 are the host names (or IP addresses).  
- In a typical situation, host1 is the master, and host2 and host3 
- are the slave computers.  A pair of socket numbers (e.g., "5, 3")
- is assigned to each host.  As a side effect, this command automatically 
- issues the connect commands at the slave computers host2 and host3 
- in order to establish the connection from each slave computer 
- (host2 or host3) to the other master/slave computers.  Note that
- the return value of the connect command automatically executed 
- on each slave computer is stored in the variable "sockets".  The
- slave computer can refer this variable to send/receive data to/from
- other computers.  As a result, the bi-directional complete connection
- among the listed computers is established.
-
-
-send (x, sockets)
- Send the variable "x" to the computers specified by matrix "sockets".
- For example,
-
-        send ([ 1+2i, 3; 4, 5+6i ],sockets(2:3,:));
-
- The variable can be any Octave data type.
-
-recv (socket)
- Receive a variable from the computer specified by the row vector "socket". 
- For example,
-
-        recv (sockets(1,:))
-           => [ 1+2i, 3; 4, 5+6i ]
-
-reval (commands, sockets)
- Evaluate "commands" at the remote hosts specified by the matrix "sockets".
- For example,
-
-        reval ([ "a=[ 1:3 ]"; "a=a'*a" ],socket(2,:));
-
-sclose (sockets)
- Close the connections specified by the matrix "sockets".
- Returns zero on success, or nonzero if an error occurred.
- For example,
-
-        sclose (sockets);
-
-
-
-Notes for the current version:
-* The slave computer must have the directory whose name and path are 
-  identical with the current directory of the master computer.
-
-
-Sample program:
- The following Octave script calculates the sum of the integers 
- from 1 to 100.  The computation is divided into half and assigned 
- to "host2" and "host3".
-
-clear;
-hosts = [ "host1"; "host2"; "host3" ];
-sockets = connect(hosts);
-psum = zeros(1,2);
-reval( "send(sum([1:50]),sockets(1,:))", sockets(2,:));
-reval( "send(sum([51:100]),sockets(1,:))", sockets(3,:));
-psum(1) = recv(sockets(2,:));
-psum(2) = recv(sockets(3,:));
-sum(psum)
-scloseall(sockets);
-
-
- In the following script, the variable s="Hello, again!" 
- passes through 4 computers.
-
-clear;
-hosts = [ "host1"; "host2"; "host3"; "host4" ]; 
-sockets = connect(hosts);
-s="Hello, again!";
-send(s,sockets(2,:));
-reval( "s=recv(sockets(1,:));",sockets(2,:));
-reval( "send(s,sockets(3,:));",sockets(2,:));
-reval( "s=recv(sockets(2,:));",sockets(3,:));
-reval( "send(s,sockets(4,:));",sockets(3,:));
-reval( "s=recv(sockets(3,:));",sockets(4,:));
-reval( "send(s,sockets(1,:));",sockets(4,:));
-s2=recv(sockets(4,:))
-scloseall(sockets);
-
-
-
-License:
- This package is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
-
-
-Comments and suggestions should be directed to: 
- h_fujiwara@users.sourceforge.net
-
--- a/main/parallel/connect.cc	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,262 +0,0 @@
-/*
-
-Copyright (C) 2002 Hayato Fujiwara
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-*/
-
-#include <octave/oct.h>
-
-#include "defun-dld.h"
-#include "dirfns.h"
-#include "error.h"
-#include "help.h"
-#include "oct-map.h"
-#include "systime.h"
-#include "ov.h"
-#include "oct-obj.h"
-#include "utils.h"
-#include "oct-env.h"
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <errno.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <netinet/in.h>
-
-#define BUFF_SIZE SSIZE_MAX
-
-// COMM
-
-DEFUN_DLD (connect, args, ,
-  "connect (hosts)\n\
-\n\
-Connect hosts and return sockets.")
-{
-
-  int sock=0,col=0,row=0,i,j,len;
-  double *sock_v=0;
-  if (args.length () == 1)
-    {
-      int pid=0,nl;
-      struct sockaddr_in *addr;
-      struct hostent *he;
-      octave_value hosts=args(0);
-      charMatrix cm=hosts.char_matrix_value();
-      char *host,*pt,myname[16];
-      
-      errno=0;
-      gethostname(myname,15);
-      row= cm.rows();
-      col= cm.columns();
-      cm= cm.transpose(); 
-      
-      sock_v=(double *)calloc(3,row*sizeof(double));
-       
-
-      for(i=1;i<row;i++){
-	host=(char *)calloc(1,col+1);
-	strncpy(host,&cm.data()[col*i],col);
-	pt=strchr(host,' ');
-	if(pt==NULL)
-	  host[col]='\0';
-	else
-	  *pt='\0';
-	
-	sock=socket(PF_INET,SOCK_STREAM,0);
-	if(sock==-1){
-	  error("socket error ");
-	}
-	
-	addr=(struct sockaddr_in *) calloc(1,sizeof(struct sockaddr_in));
-	
-	addr->sin_family=AF_INET;
-	addr->sin_port=htons(12502);
-	he=gethostbyname(host);
-	if(he == NULL){
-	  error("Unknown host %s",host);
-	}
-	memcpy(&addr->sin_addr,he->h_addr_list[0],he->h_length);
-	
-	for(j=0;j<10;j++){
-	  if(connect(sock,(struct sockaddr *)addr,sizeof(*addr))==0){
-	    break;
-	  }else if(errno!=ECONNREFUSED){
-	    error("connect error ");
-	  }else {
-	    usleep(5000);
-	  }
-	}
-	if(!sock)
-	  error("Unable to connect to %s: Connection refused",host);
-	
-	sock_v[i+row]=sock;
-	
-	free(addr);
-	free(host);
-
-	int num_nodes=row-1;
-
-	pid=getpid();
-	nl=htonl(num_nodes);
-	write(sock,&nl,sizeof(int));
-	nl=htonl(i);
-	write(sock,&nl,sizeof(int));
-	nl=htonl(pid);
-	write(sock,&nl,sizeof(int));
-
-	host=(char *)calloc(128,sizeof(char));
-	for(j=0;j<row;j++){
-	  strncpy(host,&cm.data()[col*j],col);
-	  pt=strchr(host,' ');
-	  if(pt==NULL)
-	    host[col]='\0';
-	  else
-	    *pt='\0';
-	  len=strlen(host)+1;
-	  nl=htonl(len);
-	  write(sock,&nl,sizeof(int));
-	  write(sock,host,len);
-	}
-	free(host);
-	int comm_len;
-       	std::string directory = octave_env::getcwd ();
-	comm_len=directory.length();
-	nl=htonl(comm_len);
-	write(sock,&nl,sizeof(int));
-	write(sock,directory.c_str(),comm_len);
-      }      
-      usleep(100);
-
-      for(i=1;i<row;i++){
-	
-	host=(char *)calloc(1,col+1);
-	
-	strncpy(host,&cm.data()[col*i],col);
-	pt=strchr(host,' ');
-	if(pt==NULL)
-	  host[col]='\0';
-	else
-	  *pt='\0';
-	
-	sock=socket(PF_INET,SOCK_STREAM,0);
-	if(sock==-1){
-	  perror("socket : ");
-	  exit(-1);
-	}
-	
-	addr=(struct sockaddr_in *) calloc(1,sizeof(struct sockaddr_in));
-	
-	addr->sin_family=AF_INET;
-	addr->sin_port=htons(12501);
-	he=gethostbyname(host);
-	if(he == NULL){
-	  error("Unknown host %s",host);
-	}
-	memcpy(&addr->sin_addr,he->h_addr_list[0],he->h_length);
-	while(1){
-	  for(j=0;j<10;j++){
-	    if(connect(sock,(struct sockaddr *)addr,sizeof(*addr))==0){
-	      break;
-	    }else if(errno!=ECONNREFUSED){
-	      perror("connect : ");
-	      exit(-1);
-	    }else {
-	      usleep(5000);
-	    }
-	  }
-	  if(!sock)
-	    error("Unable to connect to %s: Connection refused",host);
-	  
-	  int bufsize=262144;
-	  socklen_t ol;
-	  ol=sizeof(bufsize);
-	  setsockopt(sock,SOL_SOCKET,SO_SNDBUF,&bufsize,ol);
-	  setsockopt(sock,SOL_SOCKET,SO_RCVBUF,&bufsize,ol);
-	  bufsize=1;
-	  ol=sizeof(bufsize);
-	  setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&bufsize,ol);
-	  
-
-	  int len=0,result=0;;
-	  //send pppid
-	  nl=htonl(pid);
-	  write(sock,&nl,sizeof(int));
-	  //send name size
-	  strncpy(myname,cm.data(),col);
-	  pt=strchr(myname,' ');
-	  if(pt==NULL)
-	    myname[col]='\0';
-	  else
-	    *pt='\0';
-	  len=strlen(myname);
-	  nl=htonl(len);
-	  write(sock,&nl,sizeof(int));
-	  //send name
-	  write(sock,myname,len+1);
-	  //recv result code
-	  read(sock,&nl,sizeof(int));
-	  result=ntohl(nl);
-	  if(result==0){
-	    sock_v[i]=sock;
-	    //recv endian
-	    read(sock,&nl,sizeof(int));
-	    sock_v[i+2*row]=ntohl(nl);
-	    //send endian
-	    nl=htonl(__BYTE_ORDER);
-	    write(sock,&nl,sizeof(int));
-	    break;
-	  }else{
-	    close(sock);
-	  }
-	}
-	
-	free(addr);
-	free(host);
-      }
-
-      char lf='\n';
-      for(i=1;i<row;i++){
-	write((int)sock_v[i+row],&lf,sizeof(char));
-	//	cout << i+row <<endl;
-      }
-    }
-  else
-    {
-      print_usage ();
-      octave_value retval;
-      return retval;
-    }
-      
-
-  Matrix mx(row,3);
-  double *tmp =mx.fortran_vec();
-  for (i=0;i<3*row;i++)
-    tmp[i]=sock_v[i];
-  octave_value retval(mx);
-
-  return retval;
-}
-
-
-/*
-;;; Local Variables: ***
-;;; mode: C++ ***
-;;; End: ***
-*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/doc/README	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,145 @@
+
+Octave parallel execution package for cluster computers
+
+Description
+
+ This is a package to add parallel computing functions to Octave. The
+parallel computing functions are supported without any additional
+parallel computing libraries such as MPI and PVM.  The operation has
+been confirmed only on Linux (but it may be applicable to other
+operating systems).
+
+
+
+Requirements
+
+ 1. GNU Octave 2.1.43 that is available at http://www.octave.org/
+ 2. two or more computers
+
+
+
+How to use
+ Note first that this package assumes the use in a multiple-computer 
+ system consisting of a master (your console) computer and some 
+ slave computers.  Run Octave with argument "server.m" on every slave 
+ computer.
+
+ $ octave /usr/local/share/octave/2.1.43/site/m/octave-forge/parallel/server.m
+
+ Run Octave without argument "server.m" on the master computer
+
+ $ octave -q -f script.m 
+  or
+ $ octave
+
+ > script
+
+
+
+Command references
+
+connect (hosts) 
+ Make bi-directional connections among the computers specified by 
+ the matrix "hosts" and return the matrix of the sockets (file 
+ descriptors) directed to the listed computers.
+ This command should be executed on the master computer before 
+ starting parallel computation. For example, 
+ you can execute the following command on the master computer:
+        connect ([ "host1"; "host2"; "host3" ])
+                => [ 0, 0; 5, 3; 6, 4 ]
+ where host1, host2 and host3 are the host names (or IP addresses).  
+ In a typical situation, host1 is the master, and host2 and host3 
+ are the slave computers.  A pair of socket numbers (e.g., "5, 3")
+ is assigned to each host.  As a side effect, this command automatically 
+ issues the connect commands at the slave computers host2 and host3 
+ in order to establish the connection from each slave computer 
+ (host2 or host3) to the other master/slave computers.  Note that
+ the return value of the connect command automatically executed 
+ on each slave computer is stored in the variable "sockets".  The
+ slave computer can refer this variable to send/receive data to/from
+ other computers.  As a result, the bi-directional complete connection
+ among the listed computers is established.
+
+
+send (x, sockets)
+ Send the variable "x" to the computers specified by matrix "sockets".
+ For example,
+
+        send ([ 1+2i, 3; 4, 5+6i ],sockets(2:3,:));
+
+ The variable can be any Octave data type.
+
+recv (socket)
+ Receive a variable from the computer specified by the row vector "socket". 
+ For example,
+
+        recv (sockets(1,:))
+           => [ 1+2i, 3; 4, 5+6i ]
+
+reval (commands, sockets)
+ Evaluate "commands" at the remote hosts specified by the matrix "sockets".
+ For example,
+
+        reval ([ "a=[ 1:3 ]"; "a=a'*a" ],socket(2,:));
+
+sclose (sockets)
+ Close the connections specified by the matrix "sockets".
+ Returns zero on success, or nonzero if an error occurred.
+ For example,
+
+        sclose (sockets);
+
+
+
+Notes for the current version:
+* The slave computer must have the directory whose name and path are 
+  identical with the current directory of the master computer.
+
+
+Sample program:
+ The following Octave script calculates the sum of the integers 
+ from 1 to 100.  The computation is divided into half and assigned 
+ to "host2" and "host3".
+
+clear;
+hosts = [ "host1"; "host2"; "host3" ];
+sockets = connect(hosts);
+psum = zeros(1,2);
+reval( "send(sum([1:50]),sockets(1,:))", sockets(2,:));
+reval( "send(sum([51:100]),sockets(1,:))", sockets(3,:));
+psum(1) = recv(sockets(2,:));
+psum(2) = recv(sockets(3,:));
+sum(psum)
+scloseall(sockets);
+
+
+ In the following script, the variable s="Hello, again!" 
+ passes through 4 computers.
+
+clear;
+hosts = [ "host1"; "host2"; "host3"; "host4" ]; 
+sockets = connect(hosts);
+s="Hello, again!";
+send(s,sockets(2,:));
+reval( "s=recv(sockets(1,:));",sockets(2,:));
+reval( "send(s,sockets(3,:));",sockets(2,:));
+reval( "s=recv(sockets(2,:));",sockets(3,:));
+reval( "send(s,sockets(4,:));",sockets(3,:));
+reval( "s=recv(sockets(3,:));",sockets(4,:));
+reval( "send(s,sockets(1,:));",sockets(4,:));
+s2=recv(sockets(4,:))
+scloseall(sockets);
+
+
+
+License:
+ This package is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+
+
+Comments and suggestions should be directed to: 
+ h_fujiwara@users.sourceforge.net
+
--- a/main/parallel/getid.m	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-## Copyright (C) 2002 by Hayato Fujiwara
-##
-## This program is free software; you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 2 of the License, or
-## (at your option) any later version.
-## 
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-## GNU General Public License for more details.
-## 
-## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-function retval = getid (sockets)
-
-  retval = find(sockets==0)(1);
-  
-endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/inst/getid.m	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,21 @@
+## Copyright (C) 2002 by Hayato Fujiwara
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+function retval = getid (sockets)
+
+  retval = find(sockets==0)(1);
+  
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/inst/scloseall.m	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,22 @@
+## Copyright (C) 2002 by Hayato Fujiwara
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+function scloseall (sockets)
+
+  reval("sclose(sockets);exit;",sockets);
+  sclose(sockets);
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/inst/server.m	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,18 @@
+## Copyright (C) 2002 by Hayato Fujiwara
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+%LOADPATH = [ "/home/fujiwara/work/pal_oct//:", LOADPATH ]
+pserver
--- a/main/parallel/pserver.cc	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,599 +0,0 @@
-/*
-
-Copyright (C) 2002 Hayato Fujiwara
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-*/
-
-#include <octave/oct.h>
-
-#include "defun-dld.h"
-#include "dirfns.h"
-#include "error.h"
-#include "help.h"
-#include "oct-map.h"
-#include "systime.h"
-#include "ov.h"
-#include "oct-obj.h"
-#include "utils.h"
-#include "oct-env.h"
-#include "file-io.h"
-#ifndef HAVE_OCTAVE_29
-#include "pt-plot.h"
-#endif
-#include "sighandlers.h"
-#include "parse.h"
-#include "cmd-edit.h"
-#include "variables.h"
-#include "toplev.h"
-#include "sysdep.h"
-#include "oct-prcstrm.h"
-#include "oct-stream.h"
-#include "oct-strstrm.h"
-#include "oct-iostrm.h"
-#include "unwind-prot.h"
-#include "input.h"
-
-#ifdef NEED_OCTAVE_QUIT
-#define OCTAVE_QUIT do {} while (0)
-#else
-#include "quit.h"
-#endif
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <sys/poll.h>
-#include <netinet/in.h>
-#include <errno.h>
-#include <signal.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <setjmp.h>
-#include <netinet/in.h>
-
-#define BUFF_SIZE SSIZE_MAX
-
-static bool quitting_gracefully = false;
-
-// Handle server SIGTERM SIGQUIT
-
-static RETSIGTYPE
-sigterm_handler (int /* sig */)
-{
-  int len=118;
-  char hostname[120],pidname[128];
-  gethostname(hostname,len);
-  sprintf(pidname,"/tmp/.octave-%s.pid",hostname);
-  remove (pidname);
-  close_files ();
-
-  std::cerr << "exiting, " <<hostname <<std::endl;
-  cleanup_tmp_files ();
-  exit(0);
-
-}
-
-static RETSIGTYPE
-sigchld_handler(int /* sig */)
-{
-  int status;
-  /* Reap all childrens */
-  while (waitpid(-1, &status, WNOHANG) > 0)
-    ;
-  signal(SIGCHLD, sigchld_handler);
-}
-
-// XXX FIXME XXX -- this should really be static, but that causes
-// problems on some systems.
-std::stack<std::string> octave_atexit_functions;
-
-void
-do_octave_atexit_server (void)
-{
-  static bool deja_vu = false;
-
-  while (! octave_atexit_functions.empty ())
-    {
-      std::string fcn = octave_atexit_functions.top ();
-
-      octave_atexit_functions.pop ();
-
-      feval (fcn, octave_value_list (), 0);
-
-      flush_octave_stdout ();
-    }
-
-  if (! deja_vu)
-    {
-      deja_vu = true;
-
-      command_editor::restore_terminal_state ();
-
-      // XXX FIXME XXX -- is this needed?  Can it cause any trouble?
-      raw_mode (0);
-
-      close_files ();
-
-      cleanup_tmp_files ();
-
-      flush_octave_stdout ();
-
-      if (!quitting_gracefully && (interactive || forced_interactive))
-        std::cout << "\n";
-    }
-}
-
-void
-clean_up_and_exit_server (int retval)
-{
-  do_octave_atexit_server ();
-
-  exit (retval == EOF ? 0 : retval);
-}
-
-int
-reval_loop (int sock)
-{
-  // Allow the user to interrupt us without exiting.
-  int len=0;
-  char *ev_str;
-  std::string s;
-
-  octave_save_signal_mask ();
-
-  if (octave_set_current_context)
-    {
-#if defined (USE_EXCEPTIONS_FOR_INTERRUPTS)
-      panic_impossible ();
-#else
-      unwind_protect::run_all ();
-      raw_mode (0);
-      std::cout << "\n";
-      octave_restore_signal_mask ();
-#endif
-    }
-
-  can_interrupt = true;
-
-  octave_catch_interrupts ();
-
-  octave_initialized = true;
-
-  // The big loop.
-
-  char dummy;
-  read(sock,&dummy,sizeof(char));
-  int retval,count,r_len,num,fin,nl;
-  struct pollfd *pollfd;
-      
-  pollfd=(struct pollfd *)malloc(sizeof(struct pollfd));
-  pollfd[0].fd=sock;
-  pollfd[0].events=0;
-  pollfd[0].events=POLLIN|POLLERR|POLLHUP;
-
-  do
-    {
-      pollfd[0].revents=0;
-      num=poll(pollfd,1,-1);
-      if(num){
-	if(pollfd[0].revents && (pollfd[0].fd !=0)){
-	  if(pollfd[0].revents&POLLIN){
-	    fin=read(sock,&nl,sizeof(int));
-	    len=ntohl(nl);
-	    if(!fin)
-	      clean_up_and_exit_server (0);
-	  }
-	  if(pollfd[0].revents&POLLERR){
-	    std::cerr <<"Error condition "<<std::endl;
-	    clean_up_and_exit_server (POLLERR);
-	  }
-	  if(pollfd[0].revents&POLLHUP){
-	    std::cerr <<"Hung up "<<std::endl;
-	    clean_up_and_exit_server (POLLHUP);
-	  }
-        }
-      }
-      ev_str=new char[len+1];
-      count=0;
-      r_len=BUFF_SIZE;
-      while(count <len){
-	if((len-count) < BUFF_SIZE)
-	  r_len=len-count;
-	count +=read(sock,(char *)((int)ev_str+count),r_len);
-      }
-      //      read(sock,ev_str,len);
-      ev_str[len]='\0';
-
-      s=(std::string)ev_str;
-      eval_string(s,false,retval,0);
-
-      delete(ev_str);
-      if (error_state)
-        {
-	  nl=htonl(error_state);
-	  write(sock,&nl,sizeof(int));
-	  read(sock,&nl,sizeof(int));
-	  // clean_up_and_exit_server (retval);
-        }
-      else
-        {
-          if (octave_completion_matches_called)
-            octave_completion_matches_called = false;
-          else
-            command_editor::increment_current_command_number ();
-        }
-      // Blocking Execution
-      //      write(sock,&error_state,sizeof(error_state));
-    }
-  while (retval == 0);
-
-  return retval;
-}
-
-DEFUN_DLD (pserver,,,
-  "pserver\n\
-\n\
-Connect hosts and return sockets.")
-{
-      FILE *pidfile=0;
-      int ppid,len=118;
-      char hostname[120],pidname[128],errname[128],bakname[128];
-      struct stat fstat;
-      
-      gethostname(hostname,len);
-      sprintf(pidname,"/tmp/.octave-%s.pid",hostname);
-      if(stat(pidname,&fstat)==0){
-	std::cerr << "octave : "<<hostname<<": server already running"<<std::endl;
-	clean_up_and_exit (1);
-      }
-
-      if (fork())
-        clean_up_and_exit(0);
-      
-      /* Touch lock file. */
-      ppid=getpid();
-      pidfile = fopen (pidname, "w");
-      fprintf(pidfile,"%d\n",ppid);
-      fclose(pidfile);
-      std::cout <<pidname<<std::endl;
-
-      /* */
-      signal(SIGCHLD, sigchld_handler);
-      signal(SIGTERM,sigterm_handler);
-      signal(SIGQUIT,sigterm_handler);
-
-      /* Redirect stdin, stdout, and stderr to /dev/null. */
-      freopen("/dev/null", "r", stdin);
-      freopen("/dev/null", "w", stdout);
-
-      sprintf(errname,"/tmp/octave_error-%s.log",hostname);
-      if(stat(errname,&fstat)==0){
-	sprintf(bakname,"/tmp/octave_error-%s.bak",hostname);
-	rename(errname,bakname);
-      }
-      freopen(errname, "w", stderr);
-      
-
-      int sock=0,asock=0,dsock=0,dasock=0,pid=0;
-      struct sockaddr_in *addr,rem_addr;;
-
-      addr=(struct sockaddr_in *) calloc(1,sizeof(struct sockaddr_in));
-      
-      sock=socket(PF_INET,SOCK_STREAM,0);
-      if(sock==-1){
-	perror("socket ");
-	int len=118;
-	char hostname[120],pidname[128];
-	gethostname(hostname,len);
-	sprintf(pidname,".octave-%s.pid",hostname);
-	remove (pidname);
-	close_files ();
-	clean_up_and_exit (1);
-      }
-
-      addr->sin_family=AF_INET;
-      addr->sin_port=htons(12502);
-      addr->sin_addr.s_addr=INADDR_ANY;
-      
-      if(bind(sock,(struct sockaddr *) addr,sizeof(*addr))!=0){
-	perror("bind ");
-	int len=118;
-	char hostname[120],pidname[128];
-	gethostname(hostname,len);
-	sprintf(pidname,".octave-%s.pid",hostname);
-	remove (pidname);
-	close_files ();
-	clean_up_and_exit (1);
-      }
-      free(addr);
-
-      if(listen(sock,1)!=0){
-	perror("listen ");
-	clean_up_and_exit (1);
-      }
-
-
-      dsock=socket(PF_INET,SOCK_STREAM,0);
-      if(dsock==-1){
-	perror("socket : ");
-	exit(-1);
-      }
-      
-      addr=(struct sockaddr_in *) calloc(1,sizeof(struct sockaddr_in));
-      
-      addr->sin_family=AF_INET;
-      addr->sin_port=htons(12501);
-      addr->sin_addr.s_addr=INADDR_ANY;
-      
-      
-      if(bind(dsock,(struct sockaddr *) addr,sizeof(*addr))!=0){
-	perror("bind : ");
-	exit(-1);
-      }
-      if(listen(dsock,SOMAXCONN)!=0){
-	perror("listen : ");
-	exit(-1);
-      }
-      free(addr);
-      int param=1;
-      socklen_t ol=sizeof(param);
-      setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&param,ol);
-      setsockopt(dsock,SOL_SOCKET,SO_REUSEADDR,&param,ol);
-
-      int val=1,num_nodes,me,i,j=0,pppid=0,rpppid=0,result=0,nl;
-      int *sock_v;
-      char **host_list,rem_name[128];
-      struct hostent *he;      
-
-      ol=sizeof(val);
-
-      for(;;)
-	{
-	  asock=accept(sock,0,0);
-	  if(asock==-1){
-	    perror("accept com");
-	    clean_up_and_exit (1);
-	  }
-	  /* Normal production daemon.  Fork, and have the child process
-             the connection.  The parent continues listening. */
-	  
-	  if((pid=fork())==-1)
-	    {
-	      perror("fork ");
-	      clean_up_and_exit (1);
-	    }
-	  else if(pid==0) 
-	    {
-	      close(sock);
-	      signal(SIGCHLD,SIG_DFL);
-	      signal(SIGTERM,SIG_DFL);
-	      signal(SIGQUIT,SIG_DFL);
-
-	      val=1;
-	      ol=sizeof(val);
-	      setsockopt(asock,SOL_SOCKET,SO_REUSEADDR,&val,ol);
-	      
-	      read(asock,&nl,sizeof(int));
-	      num_nodes=ntohl(nl);
-	      read(asock,&nl,sizeof(int));
-	      me=ntohl(nl);
-	      read(asock,&nl,sizeof(int));
-	      pppid=ntohl(nl);
-	      sock_v=(int *)calloc((num_nodes+1)*3,sizeof(int));
-	      host_list=(char **)calloc(num_nodes,sizeof(char *));
-	      for(i=0;i<=num_nodes;i++){
-		read(asock,&nl,sizeof(int));
-		len=ntohl(nl);
-		host_list[i]=(char *)calloc(len,sizeof(char *));
-		read(asock,host_list[i],len);
-	      }
-
-	      sprintf(errname,"/tmp/octave_error-%s_%05d.log",hostname,pppid);
-	      if(stat(errname,&fstat)==0){
-		sprintf(bakname,"/tmp/octave_error-%s_%05d.bak",hostname,pppid);
-		rename(errname,bakname);
-	      }
-	      freopen(errname, "w", stderr);
-
-	      for(i=0;i<me;i++){
-		//      recv;
-		
-		len=sizeof(rem_addr);
-
-		while(1){
-		  dasock=accept(dsock,(sockaddr *)&rem_addr,(socklen_t *)&len);
-		  if(dasock==-1){
-		    perror("accept dat ");
-		    exit(-1);
-		  }
-		  int bufsize=BUFF_SIZE;
-		  socklen_t ol;
-		  ol=sizeof(bufsize);
-		  setsockopt(dasock,SOL_SOCKET,SO_SNDBUF,&bufsize,ol);
-		  setsockopt(dasock,SOL_SOCKET,SO_RCVBUF,&bufsize,ol);
-		  bufsize=1;
-		  ol=sizeof(bufsize);
-		  setsockopt(dasock,SOL_SOCKET,SO_REUSEADDR,&bufsize,ol);
-		  
-		  //recv pppid
-		  read(dasock,&nl,sizeof(int));
-		  rpppid=ntohl(nl);
-		  //recv name size
-		  read(dasock,&nl,sizeof(int));
-		  len=ntohl(nl);
-		  //recv name
-		  read(dasock,rem_name,len+1);
-		  rem_name[len]='\0';
-
-		  for(j=0;j<me;j++){
-		    if(strcmp(rem_name,host_list[j])==0){
-		      sock_v[j]=dasock;
-		      result=0;
-		      break;
-		    }else{
-		      result=-1;
-		    }
-		  }
-		  //send result code
-		  if(result==0){
-		    if(pppid==rpppid){
-		      result=0;
-		      nl=htonl(result);
-		      write(dasock,&nl,sizeof(int));
-		      //send endian
-		      nl=htonl(__BYTE_ORDER);
-		      write(dasock,&nl,sizeof(int));
-		      //recv endian
-		      read(sock,&nl,sizeof(int));
-		      sock_v[j+2*(num_nodes+1)]=ntohl(nl);
-		      break;
-		    }
-		  }else{
-		    result=-1;
-		    nl=htonl(result);
-		    write(dasock,&nl,sizeof(int));
-		    close(dasock);
-		    sleep(1);
-		  }
-		}
-	      }
-	      //	      close(dsock);
-	      //me
-	      errno=0;
-
-	      for(i=(me+1);i<=num_nodes;i++){
-		dsock=-1;
-		// connect;
-		dsock=socket(PF_INET,SOCK_STREAM,0);
-		if(dsock==-1){
-		  perror("socket : ");
-		  exit(-1);
-		}
-		addr=(struct sockaddr_in *) calloc(1,sizeof(struct sockaddr_in));
-		
-		addr->sin_family=AF_INET;
-		addr->sin_port=htons(12501);
-		he=gethostbyname(host_list[i]);
-		if(he == NULL){
-		  error("Unknown host %s",host_list[i]);
-		}
-		memcpy(&addr->sin_addr,he->h_addr_list[0],he->h_length);
-		while(1){
-		  for(j=0;j<10;j++){
-		    if(connect(dsock,(struct sockaddr *)addr,sizeof(*addr))==0){
-		      break;
-		    }else if(errno!=ECONNREFUSED){
-		      perror("connect : ");
-		      exit(-1);
-		    }else {
-		      usleep(5000);
-		    }
-		  }
-		  int bufsize=262144;
-		  socklen_t ol;
-		  ol=sizeof(bufsize);
-		  setsockopt(dsock,SOL_SOCKET,SO_SNDBUF,&bufsize,ol);
-		  setsockopt(dsock,SOL_SOCKET,SO_RCVBUF,&bufsize,ol);
-		  bufsize=1;
-		  ol=sizeof(bufsize);
-		  setsockopt(dsock,SOL_SOCKET,SO_REUSEADDR,&bufsize,ol);
-		  
-		  //send pppid
-		  write(dsock,&nl,sizeof(int));
-		  pppid=ntohl(nl);
-		  //send name size
-		  len=strlen(host_list[me]);
-		  nl=htonl(len);
-		  write(dsock,&nl,sizeof(int));
-		  //send name
-		  write(dsock,host_list[me],len+1);
-		  //recv result code
-		  read(dsock,&nl,sizeof(int));
-		  result=ntohl(nl);
-
-		  if(result==0){
-		    sock_v[i]=dsock;
-		    //recv endian
-		    read(sock,&nl,sizeof(int));
-		    sock_v[i+2*(num_nodes+1)]=ntohl(nl);
-		    //send endian
-		    nl=htonl(__BYTE_ORDER);
-		    write(sock,&nl,sizeof(int));
-		    break;
-		  }else{
-		    close(dsock);
-		  }
-		}
-		free(addr);
-	      }
-	      /*   for(i=0;i<=num_nodes;i++){
-		free(host_list[i]);
-	      }
-	      free(host_list);
-	      */
- 	      //normal act
-	      install_signal_handlers ();
-      
-	      atexit (do_octave_atexit_server);
-	      
-	      char * s;
-	      int stat;
-
-	      s=(char *)calloc(32,sizeof(char));
-	      sprintf(s,"sockets=[%d,0,%d]",sock_v[0],sock_v[2*(num_nodes+1)]);
-	      eval_string(std::string(s),true,stat);
-	      for(i=1;i<=num_nodes;i++){
-		sprintf(s,"sockets=[sockets;%d,0,%d]",sock_v[i+2*(num_nodes+1)]);
-		eval_string(std::string(s),true,stat);
-	      }
-		
-	      interactive = false;
-	      
-	      line_editing = false;
-
-//	      int retval = main_loop ();
-
-	      char *newdir;
-	      int newdir_len;
-	      read(asock,&nl,sizeof(int));
-	      newdir_len=ntohl(nl);
-	      newdir=(char *)calloc(sizeof(char),newdir_len+1);
-	      read(asock,newdir,newdir_len);
-	      int cd_ok=octave_env::chdir (newdir);
-	      if(cd_ok != true){
-		octave_env::chdir ("/tmp");
-	      }
-	      int retval = reval_loop(asock);
-	      
-	      if (retval == 1 && ! error_state)
-		retval = 0;
-	      
-	      close(asock);
-
-	      clean_up_and_exit_server (retval);
-	      
-	    }
-	  
-	  close(asock);
-	  
-	}
-      close(sock);
-      exit(-1);
-      
-}
--- a/main/parallel/recv.cc	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,254 +0,0 @@
-/*
-
-Copyright (C) 2002 Hayato Fujiwara
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-*/
-
-#include <octave/oct.h>
-
-#include "defun-dld.h"
-#include "dirfns.h"
-#include "error.h"
-#include "help.h"
-#include "oct-map.h"
-#include "systime.h"
-#include "ov.h"
-#include "oct-obj.h"
-#include "utils.h"
-#include "oct-env.h"
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/poll.h>
-#include <netinet/in.h>
-#include <errno.h>
-#include <netdb.h>
-#include <unistd.h>
-
-#include "swab.h"
-
-#define BUFF_SIZE SSIZE_MAX
-
-// COMM
-
-DEFUN_DLD (recv, args, ,
-  "recv (socket)\n\
-\n\
-Receive a variable from the computer specified by the row vector 'socket'.")
-{
-  octave_value retval;
-  int type_id=0,sock;
-  
-  if(args.length () == 1)
-    {
-      Matrix m=args(0).matrix_value();
-      struct pollfd *pollfd,*pollfd_d;
-      int num,error_code,sock_c,num_d,nl,endian;
-      
-      sock=(int) m.data()[0];
-      sock_c=(int) m.data()[1];
-      endian=(int) m.data()[2];
-
-      pollfd=(struct pollfd *)malloc(sizeof(struct pollfd));
-      pollfd_d=(struct pollfd *)malloc(sizeof(struct pollfd));
-      pollfd[0].fd=sock_c;
-      pollfd_d[0].fd=sock;
-      pollfd[0].events=0;
-      pollfd[0].events=POLLIN|POLLERR|POLLHUP;
-      pollfd_d[0].events=pollfd[0].events;
-      pollfd_d[0].revents=0;
-
-      num_d=0;
-      while(!num_d){
-	if(sock_c){
-	  int pid;
-	  pollfd[0].revents=0;
-	  num=poll(pollfd,1,0);
-	  if(num){
-	    if(pollfd[0].revents && (pollfd[0].fd !=0)){
-	      sockaddr_in r_addr;
-	      struct hostent *hehe;
-	      socklen_t len = sizeof(r_addr);
-	      getpeername(pollfd[0].fd, (sockaddr*)&r_addr, &len );
-	      hehe=gethostbyaddr((char *)&r_addr.sin_addr.s_addr,sizeof(r_addr.sin_addr), AF_INET);
-	      if(pollfd[0].revents&POLLIN){
-		pid=getpid();
-		read(pollfd[0].fd,&nl,sizeof(int));
-		error_code=ntohl(nl);
-		write(pollfd[0].fd,&nl,sizeof(int));
-		error("error occurred in %s\n\tsee %s:/tmp/octave_error-%s_%5d.log for detail",hehe->h_name,hehe->h_name,hehe->h_name,pid );
-	      }
-	      if(pollfd[0].revents&POLLERR){
-		error("Error condition - %s",hehe->h_name );
-	      }
-	      if(pollfd[0].revents&POLLHUP){
-		error("Hung up - %s",hehe->h_name );
-	      }
-	    }
-	  }
-	}
-	num_d=poll(pollfd_d,1,1000);
-      }
-      if(pollfd_d[0].revents && (pollfd_d[0].fd !=0)){
-	if(pollfd_d[0].revents&POLLIN){
-	  read(sock,&nl,sizeof(int));
-	  type_id=ntohl(nl);
-	}
-	if(pollfd_d[0].revents&POLLERR){
-	  error("Error condition ");
-	}
-	if(pollfd_d[0].revents&POLLHUP){
-	  error("Hung up " );
-	}
-      }
-
-      if(type_id==3)
-	{
-	  int col=0,row=0,length=0,count=0,r_len=0;
-	  unsigned long long int *conv;
-	  double *p;
-	  read(sock,&nl,sizeof(int));
-	  row=ntohl(nl);
-	  read(sock,&nl,sizeof(int));
-	  col=ntohl(nl);
-	  length=sizeof(double)*row*col;
-	  Matrix m(row,col);
-	  double* tmp = m.fortran_vec();
-	  errno=0;
-	  r_len=BUFF_SIZE;
-	  while(count <length){
-	    p=(double *)((int)tmp+count);
-	    if((length-count) < BUFF_SIZE)
-	      r_len=length-count;
-	    count +=read(sock,p,r_len);
-	    if(endian != __BYTE_ORDER){
-	      conv=(unsigned long long int *)((u_int32_t)p&0xfffffff8);
-	      for(int i=0;i<count/8;i++)
-		*conv++=swab64(conv);
-	    }
-	  }
-	  retval= octave_value(m);
-	}
-      else if(type_id==1)
-	{
-	  double d;
-	  unsigned long long int *conv;
-	  read(sock,&d,sizeof(d));
-	  if(endian != __BYTE_ORDER){
-	    conv=(unsigned long long int *)&d;
-	    *conv=swab64(conv);
-	  }
-	  retval= octave_value(d);
-	}
-      else if(type_id==4)
-	{
-	  int col=0,row=0,length=0,count=0,r_len=0;
-	  Complex *p;
-	  unsigned long long int *conv;
-	  read(sock,&nl,sizeof(int));
-	  row=ntohl(nl);
-	  read(sock,&nl,sizeof(int));
-	  col=ntohl(nl);
-	  length=sizeof(Complex)*row*col;
-	  ComplexMatrix cm(row,col);
-	  Complex* tmp = cm.fortran_vec();
-	  errno=0;
-	  r_len=BUFF_SIZE;
-	  while(count <length){
-	    p=(Complex  *)((int)tmp+count);
-	    if((length-count) < BUFF_SIZE)
-	      r_len=length-count;
-	    count +=read(sock,p,r_len);
-	    if(endian != __BYTE_ORDER){
-	      conv=(unsigned long long int *)((u_int32_t)p&0xfffffff8);
-	      for(int i=0;i<count/8;i++){
-		*conv++=swab64(conv);
-	      }
-	    }
-	  }
-	  retval= octave_value(cm);
-	  
-	}
-      else if(type_id==2)
-	{
-	  Complex cx;
-	  
-	  read(sock,&cx,sizeof(cx));
-	  if(endian != __BYTE_ORDER){
-	    long long int *conv;
-	    conv=(long long int *)&cx;
-	    *conv++=swab64(conv);
-	    *conv=swab64(conv);
-	  }
-	  retval= octave_value(cx);
-	  
-	}
-      else if(type_id==6)
-	{
-	  int col=0,row=0,length=0,count=0,r_len=0;
-	  
-	  read(sock,&nl,sizeof(int));
-	  row=ntohl(nl);
-	  read(sock,&nl,sizeof(int));
-	  col=ntohl(nl);
-	  length=sizeof(char)*row*col;
-	  charMatrix cmx(row,col);
-	  char* str = cmx.fortran_vec();
-	  errno=0;
-	  r_len=BUFF_SIZE;
-	  while(count <length){
-	    if((length-count) < BUFF_SIZE)
-	      r_len=length-count;
-	    count +=read(sock,(char *)((int)str+count),r_len);
-	  }
-	  retval= octave_value(cmx,1);
-	  
-	}
-      else if(type_id==7)
-	{
-	  int i,length=0,key_len=0;
-	  Octave_map m;
-	  octave_value_list ov_list;
-	  char *key;
-	  
-	  read(sock,&nl,sizeof(nl));
-	  length=ntohl(nl);
-	  for(i=0;i<length;i++){
-	    read(sock,&nl,sizeof(int));
-	    key_len=ntohl(nl);
-	    key = (char *)calloc(sizeof(char),key_len+1);
-	    read(sock,key,key_len);
-	    ov_list=Frecv(args(0),0);
-	    m.assign(key,ov_list(0)); 
-	  }
-	  retval=octave_value(m);
-	}
-    }
-  else
-    print_usage ();
-
-  return retval;
-
-}
-
-
-/*
-;;; Local Variables: ***
-;;; mode: C++ ***
-;;; End: ***
-*/
--- a/main/parallel/reval.cc	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,146 +0,0 @@
-/*
-
-Copyright (C) 2002 Hayato Fujiwara
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-*/
-
-#include <octave/oct.h>
-
-#include "defun-dld.h"
-#include "dirfns.h"
-#include "error.h"
-#include "help.h"
-#include "oct-map.h"
-#include "systime.h"
-#include "ov.h"
-#include "oct-obj.h"
-#include "utils.h"
-#include "oct-env.h"
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/poll.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <errno.h>
-#include <netdb.h>
-#include <unistd.h>
-
-#define BUFF_SIZE SSIZE_MAX
-
-// COMM
-
-DEFUN_DLD (reval, args, ,
-  "reval (commands,sockets)\n\
-\n\
-Evaluate 'commands' at the remote hosts specified by the matrix 'sockets'.")
-{
-  octave_value retval;
-
-  if(args.length () ==2)
-    {
-      int sock,row=0,col=0,nsock=0,i,j,k;
-      int error_code,count=0,r_len=0,nl;
-      octave_value val=args(0);
-      Matrix sock_m=args(1).matrix_value();
-      charMatrix cm=val.char_matrix_value();
-      char comm[256];
-      
-      nsock=sock_m.rows();
-
-      row=val.rows();
-      col=val.columns();
-
-      if(sock_m.data()[0]==0){
-	int num,pid;
-	struct pollfd *pollfd;
-	pollfd=(struct pollfd *)malloc(nsock*sizeof(struct pollfd));
-	for(i=0;i<nsock;i++){
-	  sock=(int)sock_m.data()[i+nsock];
-	  pollfd[i].fd=sock;
-	  pollfd[i].events=0;
-	  pollfd[i].events=POLLIN|POLLERR|POLLHUP;
-	}
-	
-	num=poll(pollfd,nsock,0);
-	if(num){
-	  for(k=0;k<nsock;k++){
-	    if(pollfd[k].revents && (pollfd[k].fd !=0)){
-	      sockaddr_in r_addr;
-	      struct hostent *hehe;
-	      socklen_t len = sizeof(r_addr);
-	      getpeername(pollfd[k].fd, (sockaddr*)&r_addr, &len );
-	      hehe=gethostbyaddr((char *)&r_addr.sin_addr.s_addr,sizeof(r_addr.sin_addr), AF_INET);
-	      
-	      if(pollfd[k].revents&POLLIN){
-		pid=getpid();
-		read(pollfd[k].fd,&nl,sizeof(int));
-		error_code=ntohl(nl);
-		write(pollfd[k].fd,&nl,sizeof(int));
-		error("error occurred in %s\n\tsee %s:/tmp/octave_error-%s_%5d.log for detail",hehe->h_name,hehe->h_name,hehe->h_name,pid );
-	      }
-	      if(pollfd[k].revents&POLLERR){
-		error("Error condition - %s",hehe->h_name );
-	      }
-	      if(pollfd[k].revents&POLLHUP){
-		error("Hung up - %s",hehe->h_name );
-	      }
-	    }
-	  }
-	}
-      }
-
-      for(i=0;i<nsock;i++){
-	sock=(int)sock_m.data()[i+nsock];
-	if(sock!=0){
-	  for(j=0;j<row;j++){
-	    strncpy(comm,(cm.extract(j,0,j,col-1).data()),col);
-	    comm[col]='\n';
-	    comm[col+1]='\0';
-	    nl=htonl(col);
-	    write(sock,&nl,sizeof(int));
-	    count=0;
-	    r_len=BUFF_SIZE;
-	    while(count <col){
-	      if((col-count) < BUFF_SIZE)
-		r_len=col-count;
-	      count +=write(sock,(char *)((int)comm+count),r_len);
-	    }
-
-	    // Blocking Execution
-//	    read(sock,&error_state,sizeof(int));
-//	    if(error_state){
-//	      error("Error occurred on %d" sock);
-//	    }
-
-	  }
-	}
-      }
-    }
-  else
-    print_usage ();
-
-  return retval;
-
-}
-
-/*
-;;; Local Variables: ***
-;;; mode: C++ ***
-;;; End: ***
-*/
--- a/main/parallel/sclose.cc	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-/*
-
-Copyright (C) 2002 Hayato Fujiwara
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-*/
-
-#include <octave/oct.h>
-
-#include "defun-dld.h"
-#include "dirfns.h"
-#include "error.h"
-#include "help.h"
-#include "oct-map.h"
-#include "systime.h"
-#include "ov.h"
-#include "oct-obj.h"
-#include "utils.h"
-#include "oct-env.h"
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/poll.h>
-#include <netinet/in.h>
-#include <errno.h>
-#include <netdb.h>
-#include <unistd.h>
-
-#define BUFF_SIZE SSIZE_MAX
-
-// COMM
-
-DEFUN_DLD (sclose, args, ,
-  "sclose (sockets)\n\
-\n\
-Close sockets")
-{
-  octave_value retval;
-  errno=0;
-
-  if(args.length () == 1)
-    {
-      int i,nsock=0,sock,k,error_code,err=0,nl;
-
-      nsock=args(0).matrix_value().rows()*2;
-      
-      if((int)args(0).matrix_value().data()[0]==0){
-	int num,pid;
-	struct pollfd *pollfd;
-	pollfd=(struct pollfd *)malloc(nsock*sizeof(struct pollfd));
-	for(i=0;i<nsock;i++){
-	  sock=(int)args(0).matrix_value().data()[i+nsock];
-	  pollfd[i].fd=sock;
-	  pollfd[i].events=0;
-	  pollfd[i].events=POLLIN|POLLERR|POLLHUP;
-	}
-	
-	num=poll(pollfd,nsock,0);
-	if(num){
-	  for(k=0;k<nsock;k++){
-	    if(pollfd[k].revents && (pollfd[k].fd !=0)){
-	      sockaddr_in r_addr;
-	      struct hostent *hehe;
-	      socklen_t len = sizeof(r_addr);
-	      getpeername(pollfd[k].fd, (sockaddr*)&r_addr, &len );
-	      hehe=gethostbyaddr((char *)&r_addr.sin_addr.s_addr,sizeof(r_addr.sin_addr), AF_INET);
-	      
-	      if(pollfd[k].revents&POLLIN){
-		pid=getpid();
-		read(pollfd[k].fd,&nl,sizeof(int));
-		error_code=ntohl(nl);
-		write(pollfd[k].fd,&nl,sizeof(int));
-		error("error occurred in %s\n\tsee %s:/tmp/octave_error-%s_%5d.log for detail",hehe->h_name,hehe->h_name,hehe->h_name,pid );
-	      }
-	      if(pollfd[k].revents&POLLERR){
-		error("Error condition - %s",hehe->h_name );
-	      }
-	      if(pollfd[k].revents&POLLHUP){
-		error("Hung up - %s",hehe->h_name );
-	      }
-	    }
-	  }
-	}
-      }
-
-      for(i=nsock-1;i>=0;i--){
-	sock=(int)args(0).matrix_value().data()[i];
-	if(sock!=0){
-	  if(close(sock)!=0)
-	    err++;
-	}
-      }
-      if(err)
-	error("sclose error %d",err);
-      retval=(double)err;
-    }
-  else
-    print_usage ();
-
-  return retval;
-
-}
-
-
-/*
-;;; Local Variables: ***
-;;; mode: C++ ***
-;;; End: ***
-*/
--- a/main/parallel/scloseall.m	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-## Copyright (C) 2002 by Hayato Fujiwara
-##
-## This program is free software; you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 2 of the License, or
-## (at your option) any later version.
-## 
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-## GNU General Public License for more details.
-## 
-## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-function scloseall (sockets)
-
-  reval("sclose(sockets);exit;",sockets);
-  sclose(sockets);
-
-endfunction
--- a/main/parallel/send.cc	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,270 +0,0 @@
-/*
-
-Copyright (C) 2002 Hayato Fujiwara
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-*/
-
-#include <octave/oct.h>
-#include <map>
-
-#include "defun-dld.h"
-#include "dirfns.h"
-#include "error.h"
-#include "help.h"
-#include "oct-map.h"
-#include "systime.h"
-#include "ov.h"
-#include "oct-obj.h"
-#include "utils.h"
-#include "oct-env.h"
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/poll.h>
-#include <netinet/in.h>
-#include <errno.h>
-#include <netdb.h>
-#include <unistd.h>
-
-#define BUFF_SIZE SSIZE_MAX
-
-// COMM
-
-DEFUN_DLD (send, args, ,
-  "send (X,sockets)\n\
-\n\
-Send the variable 'x' to the computers specified by matrix 'sockets'.")
-{
-  octave_value retval;
-  
-  typedef std::map<std::string, octave_value_list>::iterator iterator;
-  typedef std::map<std::string, octave_value_list>::const_iterator const_iterator;
-
-  if(args.length () ==2)
-    {
-      octave_value val=args(0);
-      Matrix sock_m=args(1).matrix_value();
-      int sock,i,k,error_code,nl;
-      int nsock=sock_m.rows();
-      int type_id=0; //=val.type_id();
-
-      if((int)sock_m.data()[0]==0){
-	int num,pid;
-	struct pollfd *pollfd;
-	pollfd=(struct pollfd *)malloc(nsock*sizeof(struct pollfd));
-	for(i=0;i<nsock;i++){
-	  sock=(int)sock_m.data()[i+nsock];
-	  pollfd[i].fd=sock;
-	  pollfd[i].events=0;
-	  pollfd[i].events=POLLIN|POLLERR|POLLHUP;
-	}
-	
-	num=poll(pollfd,nsock,0);
-	if(num){
-	  for(k=0;k<nsock;k++){
-	    if(pollfd[k].revents && (pollfd[k].fd !=0)){
-	      sockaddr_in r_addr;
-	      struct hostent *hehe;
-	      socklen_t len = sizeof(r_addr);
-	      getpeername(pollfd[k].fd, (sockaddr*)&r_addr, &len );
-	      hehe=gethostbyaddr((char *)&r_addr.sin_addr.s_addr,sizeof(r_addr.sin_addr), AF_INET);
-	      
-	      if(pollfd[k].revents&POLLIN){
-		pid=getpid();
-		read(pollfd[k].fd,&nl,sizeof(int));
-		error_code=ntohl(nl);
-		write(pollfd[k].fd,&nl,sizeof(int));
-		error("error occurred in %s\n\tsee %s:/tmp/octave_error-%s_%5d.log for detail",hehe->h_name,hehe->h_name,hehe->h_name,pid );
-	      }
-	      if(pollfd[k].revents&POLLERR){
-		error("Error condition - %s",hehe->h_name );
-	      }
-	      if(pollfd[k].revents&POLLHUP){
-		error("Hung up - %s",hehe->h_name );
-	      }
-	    }
-	  }
-	}
-      }
-
-      if(val.is_real_matrix() && !(val.is_char_matrix()))
-	{
-	  Matrix m=val.matrix_value();
-	  int row=m.rows();
-	  int col=m.columns();
-	  int length=0,count,r_len;
-	  
-	  const double *tmp=m.data();
-	  type_id=3;
-	  for (i=0;i<nsock;i++){
-	    sock=(int)sock_m.data()[i];
-	    if(sock!=0){
-	      nl=htonl(type_id);
-	      write(sock,&nl,sizeof(int));
-	      nl=htonl(row);
-	      write(sock,&nl,sizeof(int));
-	      nl=htonl(col);
-	      write(sock,&nl,sizeof(int));
-	      length=sizeof(double)*col*row;
-	      errno=0;
-	      count=0;
-	      r_len=BUFF_SIZE;
-	      while(count <length){
-		if((length-count) < BUFF_SIZE)
-		  r_len=length-count;
-		count +=write(sock,(double *)((int)tmp+count),r_len);
-	      }
-
-	    //	      write(sock,m.data(),length);
-	    }
-	  }
-	  
-	}
-      else if(val.is_real_scalar())
-	{
-	  double d=val.double_value();
-	  int length=sizeof(d);
-	  
-	  type_id=1;
-	  for (i=0;i<nsock;i++){
-	    sock=(int)sock_m.data()[i];
-	    if(sock!=0){
-	      nl=htonl(type_id);
-	      write(sock,&nl,sizeof(int));
-	      write(sock,&d,length);
-	    }
-	  }
-	}
-      else if(val.is_complex_matrix())
-	{
-	  ComplexMatrix m=val.complex_matrix_value();
-	  int row=m.rows();
-	  int col=m.columns();
-	  int length=0,count,r_len;
-	  
-	  type_id=4;
-	  const Complex *tmp=m.data();
-	  for (i=0;i<nsock;i++){
-	    sock=(int)sock_m.data()[i];
-	    if(sock!=0){
-	      nl=htonl(type_id);
-	      write(sock,&nl,sizeof(int));
-	      nl=htonl(row);
-	      write(sock,&nl,sizeof(int));
-	      nl=htonl(col);
-	      write(sock,&nl,sizeof(int));
-	      length=sizeof(Complex)*col*row;
-	      count=0;
-	      r_len=BUFF_SIZE;
-	      while(count <length){
-		if((length-count) < BUFF_SIZE)
-		  r_len=length-count;
-		count +=write(sock,(Complex *)((int)tmp+count),r_len);
-	      }
-	      //	      write(sock,m.data(),length);
-	    }
-	  }
-	}
-      else if(val.is_complex_scalar())
-	{
-	  Complex cx=val.complex_value();
-	  int length=sizeof(cx);
-	  
-	  type_id=2;
-	  for (i=0;i<nsock;i++){
-	    sock=(int)sock_m.data()[i];
-	    if(sock!=0){
-	      nl=htonl(type_id);
-	      write(sock,&nl,sizeof(int));
-	      write(sock,&cx,length);
-	    }
-	  }
-	}
-      else if(val.is_char_matrix())
-	{
-	  int row=val.rows();
-	  int col=val.columns();
-	  int length=sizeof(char)*row*col,count,r_len;
-	  charMatrix cmx=val.char_matrix_value();
-	  
-	  type_id=6;
-	  const char *tmp=cmx.data();
-	  for (i=0;i<nsock;i++){
-	    sock=(int)sock_m.data()[i];
-	    if(sock!=0){
-	      nl=htonl(type_id);
-	      write(sock,&nl,sizeof(int));
-	      nl=htonl(row);
-	      write(sock,&nl,sizeof(int));
-	      nl=htonl(col);
-	      write(sock,&nl,sizeof(int));
-	      count=0;
-	      r_len=BUFF_SIZE;
-	      while(count <length){
-		if((length-count) < BUFF_SIZE)
-		  r_len=length-count;
-		count +=write(sock,(char *)((int)tmp+count),r_len);
-	      }
-	      //	      write(sock,cmx.data(),length);
-	    }
-	  }
-	}
-      else if(val.is_map())
-	{
-	  Octave_map map=val.map_value();
-	  octave_value_list ov_list;
-	  Cell c;
-	  int i,length=map.length(),key_len=0;
-	  string_vector key=map.keys();
-	  
-  	  for (i=0;i<nsock;i++){
-  	    sock=(int)sock_m.data()[i];
-	    ov_list(1)=octave_value(sock_m.row(i));
-	    type_id=7;
-	    if(sock!=0){
-	      nl=htonl(type_id);
-	      write(sock,&nl,sizeof(int));
-	      nl=htonl(length);
-	      write(sock,&nl,sizeof(int));
-	      for(i=0;i<length;i++){
-		key_len=key[i].length();
-		nl=htonl(key_len);
-		write(sock,&nl,sizeof(int));
-		c=map.contents(key[i]);
-		ov_list(0)=c(0);
-		write(sock,key[i].c_str(), key_len);
-		Fsend(ov_list,0);
-	      }
-	    }
-	  }
-	}
-      else
-	error("unsupported type %d",type_id);
-    }
-  else
-    print_usage ();
-  
-  return retval;
-  
-}
-
-/*
-;;; Local Variables: ***
-;;; mode: C++ ***
-;;; End: ***
-*/
--- a/main/parallel/server.m	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-## Copyright (C) 2002 by Hayato Fujiwara
-##
-## This program is free software; you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 2 of the License, or
-## (at your option) any later version.
-## 
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-## GNU General Public License for more details.
-## 
-## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-%LOADPATH = [ "/home/fujiwara/work/pal_oct//:", LOADPATH ]
-pserver
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/src/Makefile	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,10 @@
+OCTS = sclose.oct  connect.oct pserver.oct  \
+	recv.oct  reval.oct  send.oct
+
+
+all: $(OCTS)
+
+%.oct: %.cc
+	mkoctfile -s $<
+
+clean: ; rm *.o core octave-core *.oct *~
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/src/connect.cc	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,262 @@
+/*
+
+Copyright (C) 2002 Hayato Fujiwara
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+*/
+
+#include <octave/oct.h>
+
+#include "defun-dld.h"
+#include "dirfns.h"
+#include "error.h"
+#include "help.h"
+#include "oct-map.h"
+#include "systime.h"
+#include "ov.h"
+#include "oct-obj.h"
+#include "utils.h"
+#include "oct-env.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <netinet/in.h>
+
+#define BUFF_SIZE SSIZE_MAX
+
+// COMM
+
+DEFUN_DLD (connect, args, ,
+  "connect (hosts)\n\
+\n\
+Connect hosts and return sockets.")
+{
+
+  int sock=0,col=0,row=0,i,j,len;
+  double *sock_v=0;
+  if (args.length () == 1)
+    {
+      int pid=0,nl;
+      struct sockaddr_in *addr;
+      struct hostent *he;
+      octave_value hosts=args(0);
+      charMatrix cm=hosts.char_matrix_value();
+      char *host,*pt,myname[16];
+      
+      errno=0;
+      gethostname(myname,15);
+      row= cm.rows();
+      col= cm.columns();
+      cm= cm.transpose(); 
+      
+      sock_v=(double *)calloc(3,row*sizeof(double));
+       
+
+      for(i=1;i<row;i++){
+	host=(char *)calloc(1,col+1);
+	strncpy(host,&cm.data()[col*i],col);
+	pt=strchr(host,' ');
+	if(pt==NULL)
+	  host[col]='\0';
+	else
+	  *pt='\0';
+	
+	sock=socket(PF_INET,SOCK_STREAM,0);
+	if(sock==-1){
+	  error("socket error ");
+	}
+	
+	addr=(struct sockaddr_in *) calloc(1,sizeof(struct sockaddr_in));
+	
+	addr->sin_family=AF_INET;
+	addr->sin_port=htons(12502);
+	he=gethostbyname(host);
+	if(he == NULL){
+	  error("Unknown host %s",host);
+	}
+	memcpy(&addr->sin_addr,he->h_addr_list[0],he->h_length);
+	
+	for(j=0;j<10;j++){
+	  if(connect(sock,(struct sockaddr *)addr,sizeof(*addr))==0){
+	    break;
+	  }else if(errno!=ECONNREFUSED){
+	    error("connect error ");
+	  }else {
+	    usleep(5000);
+	  }
+	}
+	if(!sock)
+	  error("Unable to connect to %s: Connection refused",host);
+	
+	sock_v[i+row]=sock;
+	
+	free(addr);
+	free(host);
+
+	int num_nodes=row-1;
+
+	pid=getpid();
+	nl=htonl(num_nodes);
+	write(sock,&nl,sizeof(int));
+	nl=htonl(i);
+	write(sock,&nl,sizeof(int));
+	nl=htonl(pid);
+	write(sock,&nl,sizeof(int));
+
+	host=(char *)calloc(128,sizeof(char));
+	for(j=0;j<row;j++){
+	  strncpy(host,&cm.data()[col*j],col);
+	  pt=strchr(host,' ');
+	  if(pt==NULL)
+	    host[col]='\0';
+	  else
+	    *pt='\0';
+	  len=strlen(host)+1;
+	  nl=htonl(len);
+	  write(sock,&nl,sizeof(int));
+	  write(sock,host,len);
+	}
+	free(host);
+	int comm_len;
+       	std::string directory = octave_env::getcwd ();
+	comm_len=directory.length();
+	nl=htonl(comm_len);
+	write(sock,&nl,sizeof(int));
+	write(sock,directory.c_str(),comm_len);
+      }      
+      usleep(100);
+
+      for(i=1;i<row;i++){
+	
+	host=(char *)calloc(1,col+1);
+	
+	strncpy(host,&cm.data()[col*i],col);
+	pt=strchr(host,' ');
+	if(pt==NULL)
+	  host[col]='\0';
+	else
+	  *pt='\0';
+	
+	sock=socket(PF_INET,SOCK_STREAM,0);
+	if(sock==-1){
+	  perror("socket : ");
+	  exit(-1);
+	}
+	
+	addr=(struct sockaddr_in *) calloc(1,sizeof(struct sockaddr_in));
+	
+	addr->sin_family=AF_INET;
+	addr->sin_port=htons(12501);
+	he=gethostbyname(host);
+	if(he == NULL){
+	  error("Unknown host %s",host);
+	}
+	memcpy(&addr->sin_addr,he->h_addr_list[0],he->h_length);
+	while(1){
+	  for(j=0;j<10;j++){
+	    if(connect(sock,(struct sockaddr *)addr,sizeof(*addr))==0){
+	      break;
+	    }else if(errno!=ECONNREFUSED){
+	      perror("connect : ");
+	      exit(-1);
+	    }else {
+	      usleep(5000);
+	    }
+	  }
+	  if(!sock)
+	    error("Unable to connect to %s: Connection refused",host);
+	  
+	  int bufsize=262144;
+	  socklen_t ol;
+	  ol=sizeof(bufsize);
+	  setsockopt(sock,SOL_SOCKET,SO_SNDBUF,&bufsize,ol);
+	  setsockopt(sock,SOL_SOCKET,SO_RCVBUF,&bufsize,ol);
+	  bufsize=1;
+	  ol=sizeof(bufsize);
+	  setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&bufsize,ol);
+	  
+
+	  int len=0,result=0;;
+	  //send pppid
+	  nl=htonl(pid);
+	  write(sock,&nl,sizeof(int));
+	  //send name size
+	  strncpy(myname,cm.data(),col);
+	  pt=strchr(myname,' ');
+	  if(pt==NULL)
+	    myname[col]='\0';
+	  else
+	    *pt='\0';
+	  len=strlen(myname);
+	  nl=htonl(len);
+	  write(sock,&nl,sizeof(int));
+	  //send name
+	  write(sock,myname,len+1);
+	  //recv result code
+	  read(sock,&nl,sizeof(int));
+	  result=ntohl(nl);
+	  if(result==0){
+	    sock_v[i]=sock;
+	    //recv endian
+	    read(sock,&nl,sizeof(int));
+	    sock_v[i+2*row]=ntohl(nl);
+	    //send endian
+	    nl=htonl(__BYTE_ORDER);
+	    write(sock,&nl,sizeof(int));
+	    break;
+	  }else{
+	    close(sock);
+	  }
+	}
+	
+	free(addr);
+	free(host);
+      }
+
+      char lf='\n';
+      for(i=1;i<row;i++){
+	write((int)sock_v[i+row],&lf,sizeof(char));
+	//	cout << i+row <<endl;
+      }
+    }
+  else
+    {
+      print_usage ();
+      octave_value retval;
+      return retval;
+    }
+      
+
+  Matrix mx(row,3);
+  double *tmp =mx.fortran_vec();
+  for (i=0;i<3*row;i++)
+    tmp[i]=sock_v[i];
+  octave_value retval(mx);
+
+  return retval;
+}
+
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/src/pserver.cc	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,599 @@
+/*
+
+Copyright (C) 2002 Hayato Fujiwara
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+*/
+
+#include <octave/oct.h>
+
+#include "defun-dld.h"
+#include "dirfns.h"
+#include "error.h"
+#include "help.h"
+#include "oct-map.h"
+#include "systime.h"
+#include "ov.h"
+#include "oct-obj.h"
+#include "utils.h"
+#include "oct-env.h"
+#include "file-io.h"
+#ifndef HAVE_OCTAVE_29
+#include "pt-plot.h"
+#endif
+#include "sighandlers.h"
+#include "parse.h"
+#include "cmd-edit.h"
+#include "variables.h"
+#include "toplev.h"
+#include "sysdep.h"
+#include "oct-prcstrm.h"
+#include "oct-stream.h"
+#include "oct-strstrm.h"
+#include "oct-iostrm.h"
+#include "unwind-prot.h"
+#include "input.h"
+
+#ifdef NEED_OCTAVE_QUIT
+#define OCTAVE_QUIT do {} while (0)
+#else
+#include "quit.h"
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/poll.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include <signal.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <setjmp.h>
+#include <netinet/in.h>
+
+#define BUFF_SIZE SSIZE_MAX
+
+static bool quitting_gracefully = false;
+
+// Handle server SIGTERM SIGQUIT
+
+static RETSIGTYPE
+sigterm_handler (int /* sig */)
+{
+  int len=118;
+  char hostname[120],pidname[128];
+  gethostname(hostname,len);
+  sprintf(pidname,"/tmp/.octave-%s.pid",hostname);
+  remove (pidname);
+  close_files ();
+
+  std::cerr << "exiting, " <<hostname <<std::endl;
+  cleanup_tmp_files ();
+  exit(0);
+
+}
+
+static RETSIGTYPE
+sigchld_handler(int /* sig */)
+{
+  int status;
+  /* Reap all childrens */
+  while (waitpid(-1, &status, WNOHANG) > 0)
+    ;
+  signal(SIGCHLD, sigchld_handler);
+}
+
+// XXX FIXME XXX -- this should really be static, but that causes
+// problems on some systems.
+std::stack<std::string> octave_atexit_functions;
+
+void
+do_octave_atexit_server (void)
+{
+  static bool deja_vu = false;
+
+  while (! octave_atexit_functions.empty ())
+    {
+      std::string fcn = octave_atexit_functions.top ();
+
+      octave_atexit_functions.pop ();
+
+      feval (fcn, octave_value_list (), 0);
+
+      flush_octave_stdout ();
+    }
+
+  if (! deja_vu)
+    {
+      deja_vu = true;
+
+      command_editor::restore_terminal_state ();
+
+      // XXX FIXME XXX -- is this needed?  Can it cause any trouble?
+      raw_mode (0);
+
+      close_files ();
+
+      cleanup_tmp_files ();
+
+      flush_octave_stdout ();
+
+      if (!quitting_gracefully && (interactive || forced_interactive))
+        std::cout << "\n";
+    }
+}
+
+void
+clean_up_and_exit_server (int retval)
+{
+  do_octave_atexit_server ();
+
+  exit (retval == EOF ? 0 : retval);
+}
+
+int
+reval_loop (int sock)
+{
+  // Allow the user to interrupt us without exiting.
+  int len=0;
+  char *ev_str;
+  std::string s;
+
+  octave_save_signal_mask ();
+
+  if (octave_set_current_context)
+    {
+#if defined (USE_EXCEPTIONS_FOR_INTERRUPTS)
+      panic_impossible ();
+#else
+      unwind_protect::run_all ();
+      raw_mode (0);
+      std::cout << "\n";
+      octave_restore_signal_mask ();
+#endif
+    }
+
+  can_interrupt = true;
+
+  octave_catch_interrupts ();
+
+  octave_initialized = true;
+
+  // The big loop.
+
+  char dummy;
+  read(sock,&dummy,sizeof(char));
+  int retval,count,r_len,num,fin,nl;
+  struct pollfd *pollfd;
+      
+  pollfd=(struct pollfd *)malloc(sizeof(struct pollfd));
+  pollfd[0].fd=sock;
+  pollfd[0].events=0;
+  pollfd[0].events=POLLIN|POLLERR|POLLHUP;
+
+  do
+    {
+      pollfd[0].revents=0;
+      num=poll(pollfd,1,-1);
+      if(num){
+	if(pollfd[0].revents && (pollfd[0].fd !=0)){
+	  if(pollfd[0].revents&POLLIN){
+	    fin=read(sock,&nl,sizeof(int));
+	    len=ntohl(nl);
+	    if(!fin)
+	      clean_up_and_exit_server (0);
+	  }
+	  if(pollfd[0].revents&POLLERR){
+	    std::cerr <<"Error condition "<<std::endl;
+	    clean_up_and_exit_server (POLLERR);
+	  }
+	  if(pollfd[0].revents&POLLHUP){
+	    std::cerr <<"Hung up "<<std::endl;
+	    clean_up_and_exit_server (POLLHUP);
+	  }
+        }
+      }
+      ev_str=new char[len+1];
+      count=0;
+      r_len=BUFF_SIZE;
+      while(count <len){
+	if((len-count) < BUFF_SIZE)
+	  r_len=len-count;
+	count +=read(sock,(char *)((int)ev_str+count),r_len);
+      }
+      //      read(sock,ev_str,len);
+      ev_str[len]='\0';
+
+      s=(std::string)ev_str;
+      eval_string(s,false,retval,0);
+
+      delete(ev_str);
+      if (error_state)
+        {
+	  nl=htonl(error_state);
+	  write(sock,&nl,sizeof(int));
+	  read(sock,&nl,sizeof(int));
+	  // clean_up_and_exit_server (retval);
+        }
+      else
+        {
+          if (octave_completion_matches_called)
+            octave_completion_matches_called = false;
+          else
+            command_editor::increment_current_command_number ();
+        }
+      // Blocking Execution
+      //      write(sock,&error_state,sizeof(error_state));
+    }
+  while (retval == 0);
+
+  return retval;
+}
+
+DEFUN_DLD (pserver,,,
+  "pserver\n\
+\n\
+Connect hosts and return sockets.")
+{
+      FILE *pidfile=0;
+      int ppid,len=118;
+      char hostname[120],pidname[128],errname[128],bakname[128];
+      struct stat fstat;
+      
+      gethostname(hostname,len);
+      sprintf(pidname,"/tmp/.octave-%s.pid",hostname);
+      if(stat(pidname,&fstat)==0){
+	std::cerr << "octave : "<<hostname<<": server already running"<<std::endl;
+	clean_up_and_exit (1);
+      }
+
+      if (fork())
+        clean_up_and_exit(0);
+      
+      /* Touch lock file. */
+      ppid=getpid();
+      pidfile = fopen (pidname, "w");
+      fprintf(pidfile,"%d\n",ppid);
+      fclose(pidfile);
+      std::cout <<pidname<<std::endl;
+
+      /* */
+      signal(SIGCHLD, sigchld_handler);
+      signal(SIGTERM,sigterm_handler);
+      signal(SIGQUIT,sigterm_handler);
+
+      /* Redirect stdin, stdout, and stderr to /dev/null. */
+      freopen("/dev/null", "r", stdin);
+      freopen("/dev/null", "w", stdout);
+
+      sprintf(errname,"/tmp/octave_error-%s.log",hostname);
+      if(stat(errname,&fstat)==0){
+	sprintf(bakname,"/tmp/octave_error-%s.bak",hostname);
+	rename(errname,bakname);
+      }
+      freopen(errname, "w", stderr);
+      
+
+      int sock=0,asock=0,dsock=0,dasock=0,pid=0;
+      struct sockaddr_in *addr,rem_addr;;
+
+      addr=(struct sockaddr_in *) calloc(1,sizeof(struct sockaddr_in));
+      
+      sock=socket(PF_INET,SOCK_STREAM,0);
+      if(sock==-1){
+	perror("socket ");
+	int len=118;
+	char hostname[120],pidname[128];
+	gethostname(hostname,len);
+	sprintf(pidname,".octave-%s.pid",hostname);
+	remove (pidname);
+	close_files ();
+	clean_up_and_exit (1);
+      }
+
+      addr->sin_family=AF_INET;
+      addr->sin_port=htons(12502);
+      addr->sin_addr.s_addr=INADDR_ANY;
+      
+      if(bind(sock,(struct sockaddr *) addr,sizeof(*addr))!=0){
+	perror("bind ");
+	int len=118;
+	char hostname[120],pidname[128];
+	gethostname(hostname,len);
+	sprintf(pidname,".octave-%s.pid",hostname);
+	remove (pidname);
+	close_files ();
+	clean_up_and_exit (1);
+      }
+      free(addr);
+
+      if(listen(sock,1)!=0){
+	perror("listen ");
+	clean_up_and_exit (1);
+      }
+
+
+      dsock=socket(PF_INET,SOCK_STREAM,0);
+      if(dsock==-1){
+	perror("socket : ");
+	exit(-1);
+      }
+      
+      addr=(struct sockaddr_in *) calloc(1,sizeof(struct sockaddr_in));
+      
+      addr->sin_family=AF_INET;
+      addr->sin_port=htons(12501);
+      addr->sin_addr.s_addr=INADDR_ANY;
+      
+      
+      if(bind(dsock,(struct sockaddr *) addr,sizeof(*addr))!=0){
+	perror("bind : ");
+	exit(-1);
+      }
+      if(listen(dsock,SOMAXCONN)!=0){
+	perror("listen : ");
+	exit(-1);
+      }
+      free(addr);
+      int param=1;
+      socklen_t ol=sizeof(param);
+      setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&param,ol);
+      setsockopt(dsock,SOL_SOCKET,SO_REUSEADDR,&param,ol);
+
+      int val=1,num_nodes,me,i,j=0,pppid=0,rpppid=0,result=0,nl;
+      int *sock_v;
+      char **host_list,rem_name[128];
+      struct hostent *he;      
+
+      ol=sizeof(val);
+
+      for(;;)
+	{
+	  asock=accept(sock,0,0);
+	  if(asock==-1){
+	    perror("accept com");
+	    clean_up_and_exit (1);
+	  }
+	  /* Normal production daemon.  Fork, and have the child process
+             the connection.  The parent continues listening. */
+	  
+	  if((pid=fork())==-1)
+	    {
+	      perror("fork ");
+	      clean_up_and_exit (1);
+	    }
+	  else if(pid==0) 
+	    {
+	      close(sock);
+	      signal(SIGCHLD,SIG_DFL);
+	      signal(SIGTERM,SIG_DFL);
+	      signal(SIGQUIT,SIG_DFL);
+
+	      val=1;
+	      ol=sizeof(val);
+	      setsockopt(asock,SOL_SOCKET,SO_REUSEADDR,&val,ol);
+	      
+	      read(asock,&nl,sizeof(int));
+	      num_nodes=ntohl(nl);
+	      read(asock,&nl,sizeof(int));
+	      me=ntohl(nl);
+	      read(asock,&nl,sizeof(int));
+	      pppid=ntohl(nl);
+	      sock_v=(int *)calloc((num_nodes+1)*3,sizeof(int));
+	      host_list=(char **)calloc(num_nodes,sizeof(char *));
+	      for(i=0;i<=num_nodes;i++){
+		read(asock,&nl,sizeof(int));
+		len=ntohl(nl);
+		host_list[i]=(char *)calloc(len,sizeof(char *));
+		read(asock,host_list[i],len);
+	      }
+
+	      sprintf(errname,"/tmp/octave_error-%s_%05d.log",hostname,pppid);
+	      if(stat(errname,&fstat)==0){
+		sprintf(bakname,"/tmp/octave_error-%s_%05d.bak",hostname,pppid);
+		rename(errname,bakname);
+	      }
+	      freopen(errname, "w", stderr);
+
+	      for(i=0;i<me;i++){
+		//      recv;
+		
+		len=sizeof(rem_addr);
+
+		while(1){
+		  dasock=accept(dsock,(sockaddr *)&rem_addr,(socklen_t *)&len);
+		  if(dasock==-1){
+		    perror("accept dat ");
+		    exit(-1);
+		  }
+		  int bufsize=BUFF_SIZE;
+		  socklen_t ol;
+		  ol=sizeof(bufsize);
+		  setsockopt(dasock,SOL_SOCKET,SO_SNDBUF,&bufsize,ol);
+		  setsockopt(dasock,SOL_SOCKET,SO_RCVBUF,&bufsize,ol);
+		  bufsize=1;
+		  ol=sizeof(bufsize);
+		  setsockopt(dasock,SOL_SOCKET,SO_REUSEADDR,&bufsize,ol);
+		  
+		  //recv pppid
+		  read(dasock,&nl,sizeof(int));
+		  rpppid=ntohl(nl);
+		  //recv name size
+		  read(dasock,&nl,sizeof(int));
+		  len=ntohl(nl);
+		  //recv name
+		  read(dasock,rem_name,len+1);
+		  rem_name[len]='\0';
+
+		  for(j=0;j<me;j++){
+		    if(strcmp(rem_name,host_list[j])==0){
+		      sock_v[j]=dasock;
+		      result=0;
+		      break;
+		    }else{
+		      result=-1;
+		    }
+		  }
+		  //send result code
+		  if(result==0){
+		    if(pppid==rpppid){
+		      result=0;
+		      nl=htonl(result);
+		      write(dasock,&nl,sizeof(int));
+		      //send endian
+		      nl=htonl(__BYTE_ORDER);
+		      write(dasock,&nl,sizeof(int));
+		      //recv endian
+		      read(sock,&nl,sizeof(int));
+		      sock_v[j+2*(num_nodes+1)]=ntohl(nl);
+		      break;
+		    }
+		  }else{
+		    result=-1;
+		    nl=htonl(result);
+		    write(dasock,&nl,sizeof(int));
+		    close(dasock);
+		    sleep(1);
+		  }
+		}
+	      }
+	      //	      close(dsock);
+	      //me
+	      errno=0;
+
+	      for(i=(me+1);i<=num_nodes;i++){
+		dsock=-1;
+		// connect;
+		dsock=socket(PF_INET,SOCK_STREAM,0);
+		if(dsock==-1){
+		  perror("socket : ");
+		  exit(-1);
+		}
+		addr=(struct sockaddr_in *) calloc(1,sizeof(struct sockaddr_in));
+		
+		addr->sin_family=AF_INET;
+		addr->sin_port=htons(12501);
+		he=gethostbyname(host_list[i]);
+		if(he == NULL){
+		  error("Unknown host %s",host_list[i]);
+		}
+		memcpy(&addr->sin_addr,he->h_addr_list[0],he->h_length);
+		while(1){
+		  for(j=0;j<10;j++){
+		    if(connect(dsock,(struct sockaddr *)addr,sizeof(*addr))==0){
+		      break;
+		    }else if(errno!=ECONNREFUSED){
+		      perror("connect : ");
+		      exit(-1);
+		    }else {
+		      usleep(5000);
+		    }
+		  }
+		  int bufsize=262144;
+		  socklen_t ol;
+		  ol=sizeof(bufsize);
+		  setsockopt(dsock,SOL_SOCKET,SO_SNDBUF,&bufsize,ol);
+		  setsockopt(dsock,SOL_SOCKET,SO_RCVBUF,&bufsize,ol);
+		  bufsize=1;
+		  ol=sizeof(bufsize);
+		  setsockopt(dsock,SOL_SOCKET,SO_REUSEADDR,&bufsize,ol);
+		  
+		  //send pppid
+		  write(dsock,&nl,sizeof(int));
+		  pppid=ntohl(nl);
+		  //send name size
+		  len=strlen(host_list[me]);
+		  nl=htonl(len);
+		  write(dsock,&nl,sizeof(int));
+		  //send name
+		  write(dsock,host_list[me],len+1);
+		  //recv result code
+		  read(dsock,&nl,sizeof(int));
+		  result=ntohl(nl);
+
+		  if(result==0){
+		    sock_v[i]=dsock;
+		    //recv endian
+		    read(sock,&nl,sizeof(int));
+		    sock_v[i+2*(num_nodes+1)]=ntohl(nl);
+		    //send endian
+		    nl=htonl(__BYTE_ORDER);
+		    write(sock,&nl,sizeof(int));
+		    break;
+		  }else{
+		    close(dsock);
+		  }
+		}
+		free(addr);
+	      }
+	      /*   for(i=0;i<=num_nodes;i++){
+		free(host_list[i]);
+	      }
+	      free(host_list);
+	      */
+ 	      //normal act
+	      install_signal_handlers ();
+      
+	      atexit (do_octave_atexit_server);
+	      
+	      char * s;
+	      int stat;
+
+	      s=(char *)calloc(32,sizeof(char));
+	      sprintf(s,"sockets=[%d,0,%d]",sock_v[0],sock_v[2*(num_nodes+1)]);
+	      eval_string(std::string(s),true,stat);
+	      for(i=1;i<=num_nodes;i++){
+		sprintf(s,"sockets=[sockets;%d,0,%d]",sock_v[i+2*(num_nodes+1)]);
+		eval_string(std::string(s),true,stat);
+	      }
+		
+	      interactive = false;
+	      
+	      line_editing = false;
+
+//	      int retval = main_loop ();
+
+	      char *newdir;
+	      int newdir_len;
+	      read(asock,&nl,sizeof(int));
+	      newdir_len=ntohl(nl);
+	      newdir=(char *)calloc(sizeof(char),newdir_len+1);
+	      read(asock,newdir,newdir_len);
+	      int cd_ok=octave_env::chdir (newdir);
+	      if(cd_ok != true){
+		octave_env::chdir ("/tmp");
+	      }
+	      int retval = reval_loop(asock);
+	      
+	      if (retval == 1 && ! error_state)
+		retval = 0;
+	      
+	      close(asock);
+
+	      clean_up_and_exit_server (retval);
+	      
+	    }
+	  
+	  close(asock);
+	  
+	}
+      close(sock);
+      exit(-1);
+      
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/src/recv.cc	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,254 @@
+/*
+
+Copyright (C) 2002 Hayato Fujiwara
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+*/
+
+#include <octave/oct.h>
+
+#include "defun-dld.h"
+#include "dirfns.h"
+#include "error.h"
+#include "help.h"
+#include "oct-map.h"
+#include "systime.h"
+#include "ov.h"
+#include "oct-obj.h"
+#include "utils.h"
+#include "oct-env.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/poll.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include <netdb.h>
+#include <unistd.h>
+
+#include "swab.h"
+
+#define BUFF_SIZE SSIZE_MAX
+
+// COMM
+
+DEFUN_DLD (recv, args, ,
+  "recv (socket)\n\
+\n\
+Receive a variable from the computer specified by the row vector 'socket'.")
+{
+  octave_value retval;
+  int type_id=0,sock;
+  
+  if(args.length () == 1)
+    {
+      Matrix m=args(0).matrix_value();
+      struct pollfd *pollfd,*pollfd_d;
+      int num,error_code,sock_c,num_d,nl,endian;
+      
+      sock=(int) m.data()[0];
+      sock_c=(int) m.data()[1];
+      endian=(int) m.data()[2];
+
+      pollfd=(struct pollfd *)malloc(sizeof(struct pollfd));
+      pollfd_d=(struct pollfd *)malloc(sizeof(struct pollfd));
+      pollfd[0].fd=sock_c;
+      pollfd_d[0].fd=sock;
+      pollfd[0].events=0;
+      pollfd[0].events=POLLIN|POLLERR|POLLHUP;
+      pollfd_d[0].events=pollfd[0].events;
+      pollfd_d[0].revents=0;
+
+      num_d=0;
+      while(!num_d){
+	if(sock_c){
+	  int pid;
+	  pollfd[0].revents=0;
+	  num=poll(pollfd,1,0);
+	  if(num){
+	    if(pollfd[0].revents && (pollfd[0].fd !=0)){
+	      sockaddr_in r_addr;
+	      struct hostent *hehe;
+	      socklen_t len = sizeof(r_addr);
+	      getpeername(pollfd[0].fd, (sockaddr*)&r_addr, &len );
+	      hehe=gethostbyaddr((char *)&r_addr.sin_addr.s_addr,sizeof(r_addr.sin_addr), AF_INET);
+	      if(pollfd[0].revents&POLLIN){
+		pid=getpid();
+		read(pollfd[0].fd,&nl,sizeof(int));
+		error_code=ntohl(nl);
+		write(pollfd[0].fd,&nl,sizeof(int));
+		error("error occurred in %s\n\tsee %s:/tmp/octave_error-%s_%5d.log for detail",hehe->h_name,hehe->h_name,hehe->h_name,pid );
+	      }
+	      if(pollfd[0].revents&POLLERR){
+		error("Error condition - %s",hehe->h_name );
+	      }
+	      if(pollfd[0].revents&POLLHUP){
+		error("Hung up - %s",hehe->h_name );
+	      }
+	    }
+	  }
+	}
+	num_d=poll(pollfd_d,1,1000);
+      }
+      if(pollfd_d[0].revents && (pollfd_d[0].fd !=0)){
+	if(pollfd_d[0].revents&POLLIN){
+	  read(sock,&nl,sizeof(int));
+	  type_id=ntohl(nl);
+	}
+	if(pollfd_d[0].revents&POLLERR){
+	  error("Error condition ");
+	}
+	if(pollfd_d[0].revents&POLLHUP){
+	  error("Hung up " );
+	}
+      }
+
+      if(type_id==3)
+	{
+	  int col=0,row=0,length=0,count=0,r_len=0;
+	  unsigned long long int *conv;
+	  double *p;
+	  read(sock,&nl,sizeof(int));
+	  row=ntohl(nl);
+	  read(sock,&nl,sizeof(int));
+	  col=ntohl(nl);
+	  length=sizeof(double)*row*col;
+	  Matrix m(row,col);
+	  double* tmp = m.fortran_vec();
+	  errno=0;
+	  r_len=BUFF_SIZE;
+	  while(count <length){
+	    p=(double *)((int)tmp+count);
+	    if((length-count) < BUFF_SIZE)
+	      r_len=length-count;
+	    count +=read(sock,p,r_len);
+	    if(endian != __BYTE_ORDER){
+	      conv=(unsigned long long int *)((u_int32_t)p&0xfffffff8);
+	      for(int i=0;i<count/8;i++)
+		*conv++=swab64(conv);
+	    }
+	  }
+	  retval= octave_value(m);
+	}
+      else if(type_id==1)
+	{
+	  double d;
+	  unsigned long long int *conv;
+	  read(sock,&d,sizeof(d));
+	  if(endian != __BYTE_ORDER){
+	    conv=(unsigned long long int *)&d;
+	    *conv=swab64(conv);
+	  }
+	  retval= octave_value(d);
+	}
+      else if(type_id==4)
+	{
+	  int col=0,row=0,length=0,count=0,r_len=0;
+	  Complex *p;
+	  unsigned long long int *conv;
+	  read(sock,&nl,sizeof(int));
+	  row=ntohl(nl);
+	  read(sock,&nl,sizeof(int));
+	  col=ntohl(nl);
+	  length=sizeof(Complex)*row*col;
+	  ComplexMatrix cm(row,col);
+	  Complex* tmp = cm.fortran_vec();
+	  errno=0;
+	  r_len=BUFF_SIZE;
+	  while(count <length){
+	    p=(Complex  *)((int)tmp+count);
+	    if((length-count) < BUFF_SIZE)
+	      r_len=length-count;
+	    count +=read(sock,p,r_len);
+	    if(endian != __BYTE_ORDER){
+	      conv=(unsigned long long int *)((u_int32_t)p&0xfffffff8);
+	      for(int i=0;i<count/8;i++){
+		*conv++=swab64(conv);
+	      }
+	    }
+	  }
+	  retval= octave_value(cm);
+	  
+	}
+      else if(type_id==2)
+	{
+	  Complex cx;
+	  
+	  read(sock,&cx,sizeof(cx));
+	  if(endian != __BYTE_ORDER){
+	    long long int *conv;
+	    conv=(long long int *)&cx;
+	    *conv++=swab64(conv);
+	    *conv=swab64(conv);
+	  }
+	  retval= octave_value(cx);
+	  
+	}
+      else if(type_id==6)
+	{
+	  int col=0,row=0,length=0,count=0,r_len=0;
+	  
+	  read(sock,&nl,sizeof(int));
+	  row=ntohl(nl);
+	  read(sock,&nl,sizeof(int));
+	  col=ntohl(nl);
+	  length=sizeof(char)*row*col;
+	  charMatrix cmx(row,col);
+	  char* str = cmx.fortran_vec();
+	  errno=0;
+	  r_len=BUFF_SIZE;
+	  while(count <length){
+	    if((length-count) < BUFF_SIZE)
+	      r_len=length-count;
+	    count +=read(sock,(char *)((int)str+count),r_len);
+	  }
+	  retval= octave_value(cmx,1);
+	  
+	}
+      else if(type_id==7)
+	{
+	  int i,length=0,key_len=0;
+	  Octave_map m;
+	  octave_value_list ov_list;
+	  char *key;
+	  
+	  read(sock,&nl,sizeof(nl));
+	  length=ntohl(nl);
+	  for(i=0;i<length;i++){
+	    read(sock,&nl,sizeof(int));
+	    key_len=ntohl(nl);
+	    key = (char *)calloc(sizeof(char),key_len+1);
+	    read(sock,key,key_len);
+	    ov_list=Frecv(args(0),0);
+	    m.assign(key,ov_list(0)); 
+	  }
+	  retval=octave_value(m);
+	}
+    }
+  else
+    print_usage ();
+
+  return retval;
+
+}
+
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/src/reval.cc	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,146 @@
+/*
+
+Copyright (C) 2002 Hayato Fujiwara
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+*/
+
+#include <octave/oct.h>
+
+#include "defun-dld.h"
+#include "dirfns.h"
+#include "error.h"
+#include "help.h"
+#include "oct-map.h"
+#include "systime.h"
+#include "ov.h"
+#include "oct-obj.h"
+#include "utils.h"
+#include "oct-env.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/poll.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <netdb.h>
+#include <unistd.h>
+
+#define BUFF_SIZE SSIZE_MAX
+
+// COMM
+
+DEFUN_DLD (reval, args, ,
+  "reval (commands,sockets)\n\
+\n\
+Evaluate 'commands' at the remote hosts specified by the matrix 'sockets'.")
+{
+  octave_value retval;
+
+  if(args.length () ==2)
+    {
+      int sock,row=0,col=0,nsock=0,i,j,k;
+      int error_code,count=0,r_len=0,nl;
+      octave_value val=args(0);
+      Matrix sock_m=args(1).matrix_value();
+      charMatrix cm=val.char_matrix_value();
+      char comm[256];
+      
+      nsock=sock_m.rows();
+
+      row=val.rows();
+      col=val.columns();
+
+      if(sock_m.data()[0]==0){
+	int num,pid;
+	struct pollfd *pollfd;
+	pollfd=(struct pollfd *)malloc(nsock*sizeof(struct pollfd));
+	for(i=0;i<nsock;i++){
+	  sock=(int)sock_m.data()[i+nsock];
+	  pollfd[i].fd=sock;
+	  pollfd[i].events=0;
+	  pollfd[i].events=POLLIN|POLLERR|POLLHUP;
+	}
+	
+	num=poll(pollfd,nsock,0);
+	if(num){
+	  for(k=0;k<nsock;k++){
+	    if(pollfd[k].revents && (pollfd[k].fd !=0)){
+	      sockaddr_in r_addr;
+	      struct hostent *hehe;
+	      socklen_t len = sizeof(r_addr);
+	      getpeername(pollfd[k].fd, (sockaddr*)&r_addr, &len );
+	      hehe=gethostbyaddr((char *)&r_addr.sin_addr.s_addr,sizeof(r_addr.sin_addr), AF_INET);
+	      
+	      if(pollfd[k].revents&POLLIN){
+		pid=getpid();
+		read(pollfd[k].fd,&nl,sizeof(int));
+		error_code=ntohl(nl);
+		write(pollfd[k].fd,&nl,sizeof(int));
+		error("error occurred in %s\n\tsee %s:/tmp/octave_error-%s_%5d.log for detail",hehe->h_name,hehe->h_name,hehe->h_name,pid );
+	      }
+	      if(pollfd[k].revents&POLLERR){
+		error("Error condition - %s",hehe->h_name );
+	      }
+	      if(pollfd[k].revents&POLLHUP){
+		error("Hung up - %s",hehe->h_name );
+	      }
+	    }
+	  }
+	}
+      }
+
+      for(i=0;i<nsock;i++){
+	sock=(int)sock_m.data()[i+nsock];
+	if(sock!=0){
+	  for(j=0;j<row;j++){
+	    strncpy(comm,(cm.extract(j,0,j,col-1).data()),col);
+	    comm[col]='\n';
+	    comm[col+1]='\0';
+	    nl=htonl(col);
+	    write(sock,&nl,sizeof(int));
+	    count=0;
+	    r_len=BUFF_SIZE;
+	    while(count <col){
+	      if((col-count) < BUFF_SIZE)
+		r_len=col-count;
+	      count +=write(sock,(char *)((int)comm+count),r_len);
+	    }
+
+	    // Blocking Execution
+//	    read(sock,&error_state,sizeof(int));
+//	    if(error_state){
+//	      error("Error occurred on %d" sock);
+//	    }
+
+	  }
+	}
+      }
+    }
+  else
+    print_usage ();
+
+  return retval;
+
+}
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/src/sclose.cc	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,123 @@
+/*
+
+Copyright (C) 2002 Hayato Fujiwara
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+*/
+
+#include <octave/oct.h>
+
+#include "defun-dld.h"
+#include "dirfns.h"
+#include "error.h"
+#include "help.h"
+#include "oct-map.h"
+#include "systime.h"
+#include "ov.h"
+#include "oct-obj.h"
+#include "utils.h"
+#include "oct-env.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/poll.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include <netdb.h>
+#include <unistd.h>
+
+#define BUFF_SIZE SSIZE_MAX
+
+// COMM
+
+DEFUN_DLD (sclose, args, ,
+  "sclose (sockets)\n\
+\n\
+Close sockets")
+{
+  octave_value retval;
+  errno=0;
+
+  if(args.length () == 1)
+    {
+      int i,nsock=0,sock,k,error_code,err=0,nl;
+
+      nsock=args(0).matrix_value().rows()*2;
+      
+      if((int)args(0).matrix_value().data()[0]==0){
+	int num,pid;
+	struct pollfd *pollfd;
+	pollfd=(struct pollfd *)malloc(nsock*sizeof(struct pollfd));
+	for(i=0;i<nsock;i++){
+	  sock=(int)args(0).matrix_value().data()[i+nsock];
+	  pollfd[i].fd=sock;
+	  pollfd[i].events=0;
+	  pollfd[i].events=POLLIN|POLLERR|POLLHUP;
+	}
+	
+	num=poll(pollfd,nsock,0);
+	if(num){
+	  for(k=0;k<nsock;k++){
+	    if(pollfd[k].revents && (pollfd[k].fd !=0)){
+	      sockaddr_in r_addr;
+	      struct hostent *hehe;
+	      socklen_t len = sizeof(r_addr);
+	      getpeername(pollfd[k].fd, (sockaddr*)&r_addr, &len );
+	      hehe=gethostbyaddr((char *)&r_addr.sin_addr.s_addr,sizeof(r_addr.sin_addr), AF_INET);
+	      
+	      if(pollfd[k].revents&POLLIN){
+		pid=getpid();
+		read(pollfd[k].fd,&nl,sizeof(int));
+		error_code=ntohl(nl);
+		write(pollfd[k].fd,&nl,sizeof(int));
+		error("error occurred in %s\n\tsee %s:/tmp/octave_error-%s_%5d.log for detail",hehe->h_name,hehe->h_name,hehe->h_name,pid );
+	      }
+	      if(pollfd[k].revents&POLLERR){
+		error("Error condition - %s",hehe->h_name );
+	      }
+	      if(pollfd[k].revents&POLLHUP){
+		error("Hung up - %s",hehe->h_name );
+	      }
+	    }
+	  }
+	}
+      }
+
+      for(i=nsock-1;i>=0;i--){
+	sock=(int)args(0).matrix_value().data()[i];
+	if(sock!=0){
+	  if(close(sock)!=0)
+	    err++;
+	}
+      }
+      if(err)
+	error("sclose error %d",err);
+      retval=(double)err;
+    }
+  else
+    print_usage ();
+
+  return retval;
+
+}
+
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/src/send.cc	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,270 @@
+/*
+
+Copyright (C) 2002 Hayato Fujiwara
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+*/
+
+#include <octave/oct.h>
+#include <map>
+
+#include "defun-dld.h"
+#include "dirfns.h"
+#include "error.h"
+#include "help.h"
+#include "oct-map.h"
+#include "systime.h"
+#include "ov.h"
+#include "oct-obj.h"
+#include "utils.h"
+#include "oct-env.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/poll.h>
+#include <netinet/in.h>
+#include <errno.h>
+#include <netdb.h>
+#include <unistd.h>
+
+#define BUFF_SIZE SSIZE_MAX
+
+// COMM
+
+DEFUN_DLD (send, args, ,
+  "send (X,sockets)\n\
+\n\
+Send the variable 'x' to the computers specified by matrix 'sockets'.")
+{
+  octave_value retval;
+  
+  typedef std::map<std::string, octave_value_list>::iterator iterator;
+  typedef std::map<std::string, octave_value_list>::const_iterator const_iterator;
+
+  if(args.length () ==2)
+    {
+      octave_value val=args(0);
+      Matrix sock_m=args(1).matrix_value();
+      int sock,i,k,error_code,nl;
+      int nsock=sock_m.rows();
+      int type_id=0; //=val.type_id();
+
+      if((int)sock_m.data()[0]==0){
+	int num,pid;
+	struct pollfd *pollfd;
+	pollfd=(struct pollfd *)malloc(nsock*sizeof(struct pollfd));
+	for(i=0;i<nsock;i++){
+	  sock=(int)sock_m.data()[i+nsock];
+	  pollfd[i].fd=sock;
+	  pollfd[i].events=0;
+	  pollfd[i].events=POLLIN|POLLERR|POLLHUP;
+	}
+	
+	num=poll(pollfd,nsock,0);
+	if(num){
+	  for(k=0;k<nsock;k++){
+	    if(pollfd[k].revents && (pollfd[k].fd !=0)){
+	      sockaddr_in r_addr;
+	      struct hostent *hehe;
+	      socklen_t len = sizeof(r_addr);
+	      getpeername(pollfd[k].fd, (sockaddr*)&r_addr, &len );
+	      hehe=gethostbyaddr((char *)&r_addr.sin_addr.s_addr,sizeof(r_addr.sin_addr), AF_INET);
+	      
+	      if(pollfd[k].revents&POLLIN){
+		pid=getpid();
+		read(pollfd[k].fd,&nl,sizeof(int));
+		error_code=ntohl(nl);
+		write(pollfd[k].fd,&nl,sizeof(int));
+		error("error occurred in %s\n\tsee %s:/tmp/octave_error-%s_%5d.log for detail",hehe->h_name,hehe->h_name,hehe->h_name,pid );
+	      }
+	      if(pollfd[k].revents&POLLERR){
+		error("Error condition - %s",hehe->h_name );
+	      }
+	      if(pollfd[k].revents&POLLHUP){
+		error("Hung up - %s",hehe->h_name );
+	      }
+	    }
+	  }
+	}
+      }
+
+      if(val.is_real_matrix() && !(val.is_char_matrix()))
+	{
+	  Matrix m=val.matrix_value();
+	  int row=m.rows();
+	  int col=m.columns();
+	  int length=0,count,r_len;
+	  
+	  const double *tmp=m.data();
+	  type_id=3;
+	  for (i=0;i<nsock;i++){
+	    sock=(int)sock_m.data()[i];
+	    if(sock!=0){
+	      nl=htonl(type_id);
+	      write(sock,&nl,sizeof(int));
+	      nl=htonl(row);
+	      write(sock,&nl,sizeof(int));
+	      nl=htonl(col);
+	      write(sock,&nl,sizeof(int));
+	      length=sizeof(double)*col*row;
+	      errno=0;
+	      count=0;
+	      r_len=BUFF_SIZE;
+	      while(count <length){
+		if((length-count) < BUFF_SIZE)
+		  r_len=length-count;
+		count +=write(sock,(double *)((int)tmp+count),r_len);
+	      }
+
+	    //	      write(sock,m.data(),length);
+	    }
+	  }
+	  
+	}
+      else if(val.is_real_scalar())
+	{
+	  double d=val.double_value();
+	  int length=sizeof(d);
+	  
+	  type_id=1;
+	  for (i=0;i<nsock;i++){
+	    sock=(int)sock_m.data()[i];
+	    if(sock!=0){
+	      nl=htonl(type_id);
+	      write(sock,&nl,sizeof(int));
+	      write(sock,&d,length);
+	    }
+	  }
+	}
+      else if(val.is_complex_matrix())
+	{
+	  ComplexMatrix m=val.complex_matrix_value();
+	  int row=m.rows();
+	  int col=m.columns();
+	  int length=0,count,r_len;
+	  
+	  type_id=4;
+	  const Complex *tmp=m.data();
+	  for (i=0;i<nsock;i++){
+	    sock=(int)sock_m.data()[i];
+	    if(sock!=0){
+	      nl=htonl(type_id);
+	      write(sock,&nl,sizeof(int));
+	      nl=htonl(row);
+	      write(sock,&nl,sizeof(int));
+	      nl=htonl(col);
+	      write(sock,&nl,sizeof(int));
+	      length=sizeof(Complex)*col*row;
+	      count=0;
+	      r_len=BUFF_SIZE;
+	      while(count <length){
+		if((length-count) < BUFF_SIZE)
+		  r_len=length-count;
+		count +=write(sock,(Complex *)((int)tmp+count),r_len);
+	      }
+	      //	      write(sock,m.data(),length);
+	    }
+	  }
+	}
+      else if(val.is_complex_scalar())
+	{
+	  Complex cx=val.complex_value();
+	  int length=sizeof(cx);
+	  
+	  type_id=2;
+	  for (i=0;i<nsock;i++){
+	    sock=(int)sock_m.data()[i];
+	    if(sock!=0){
+	      nl=htonl(type_id);
+	      write(sock,&nl,sizeof(int));
+	      write(sock,&cx,length);
+	    }
+	  }
+	}
+      else if(val.is_char_matrix())
+	{
+	  int row=val.rows();
+	  int col=val.columns();
+	  int length=sizeof(char)*row*col,count,r_len;
+	  charMatrix cmx=val.char_matrix_value();
+	  
+	  type_id=6;
+	  const char *tmp=cmx.data();
+	  for (i=0;i<nsock;i++){
+	    sock=(int)sock_m.data()[i];
+	    if(sock!=0){
+	      nl=htonl(type_id);
+	      write(sock,&nl,sizeof(int));
+	      nl=htonl(row);
+	      write(sock,&nl,sizeof(int));
+	      nl=htonl(col);
+	      write(sock,&nl,sizeof(int));
+	      count=0;
+	      r_len=BUFF_SIZE;
+	      while(count <length){
+		if((length-count) < BUFF_SIZE)
+		  r_len=length-count;
+		count +=write(sock,(char *)((int)tmp+count),r_len);
+	      }
+	      //	      write(sock,cmx.data(),length);
+	    }
+	  }
+	}
+      else if(val.is_map())
+	{
+	  Octave_map map=val.map_value();
+	  octave_value_list ov_list;
+	  Cell c;
+	  int i,length=map.length(),key_len=0;
+	  string_vector key=map.keys();
+	  
+  	  for (i=0;i<nsock;i++){
+  	    sock=(int)sock_m.data()[i];
+	    ov_list(1)=octave_value(sock_m.row(i));
+	    type_id=7;
+	    if(sock!=0){
+	      nl=htonl(type_id);
+	      write(sock,&nl,sizeof(int));
+	      nl=htonl(length);
+	      write(sock,&nl,sizeof(int));
+	      for(i=0;i<length;i++){
+		key_len=key[i].length();
+		nl=htonl(key_len);
+		write(sock,&nl,sizeof(int));
+		c=map.contents(key[i]);
+		ov_list(0)=c(0);
+		write(sock,key[i].c_str(), key_len);
+		Fsend(ov_list,0);
+	      }
+	    }
+	  }
+	}
+      else
+	error("unsupported type %d",type_id);
+    }
+  else
+    print_usage ();
+  
+  return retval;
+  
+}
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/parallel/src/swab.h	Sun Aug 20 13:45:44 2006 +0000
@@ -0,0 +1,23 @@
+#define swab32(x) \
+({ \
+        u_int32_t *__x = (u_int32_t *)(x); \
+        ((u_int32_t)( \
+                (((u_int32_t)(*__x) & (u_int32_t)0x000000ffUL) << 24) | \
+                (((u_int32_t)(*__x) & (u_int32_t)0x0000ff00UL) <<  8) | \
+                (((u_int32_t)(*__x) & (u_int32_t)0x00ff0000UL) >>  8) | \
+                (((u_int32_t)(*__x) & (u_int32_t)0xff000000UL) >> 24) )); \
+})
+
+#define swab64(x) \
+({ \
+        u_int64_t *__x = (u_int64_t *)(x); \
+        ((u_int64_t)( \
+                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x00000000000000ffULL) << 56) | \
+                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \
+                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \
+                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x00000000ff000000ULL) <<  8) | \
+                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x000000ff00000000ULL) >>  8) | \
+                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \
+                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \
+                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0xff00000000000000ULL) >> 56) )); \
+})
--- a/main/parallel/swab.h	Sun Aug 20 13:37:57 2006 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-#define swab32(x) \
-({ \
-        u_int32_t *__x = (u_int32_t *)(x); \
-        ((u_int32_t)( \
-                (((u_int32_t)(*__x) & (u_int32_t)0x000000ffUL) << 24) | \
-                (((u_int32_t)(*__x) & (u_int32_t)0x0000ff00UL) <<  8) | \
-                (((u_int32_t)(*__x) & (u_int32_t)0x00ff0000UL) >>  8) | \
-                (((u_int32_t)(*__x) & (u_int32_t)0xff000000UL) >> 24) )); \
-})
-
-#define swab64(x) \
-({ \
-        u_int64_t *__x = (u_int64_t *)(x); \
-        ((u_int64_t)( \
-                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x00000000000000ffULL) << 56) | \
-                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \
-                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \
-                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x00000000ff000000ULL) <<  8) | \
-                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x000000ff00000000ULL) >>  8) | \
-                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \
-                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \
-                (u_int64_t)(((u_int64_t)(*__x) & (u_int64_t)0xff00000000000000ULL) >> 56) )); \
-})