home *** CD-ROM | disk | FTP | other *** search
- From: csimmons@jewel.oracle.com (Charles Simmons)
- Newsgroups: alt.sources
- Subject: Interactive Mandelbrots on a Heterogeneous Network (2 of 2)
- Message-ID: <1990Apr3.073107.5582@oracle.com>
- Date: 3 Apr 90 07:31:07 GMT
-
-
- # This is a shell archive. Remove anything before this line, then
- # unpack it by saving it in a file and typing "sh file". (Files
- # unpacked will be owned by you and have default permissions.)
- #
- # This archive contains:
- # LICENSE hostfile mandel.h mserver.c net.c net.h client.h colormap.data
- compute.c README
-
- : =-=-=-=-=-=-= first line of shar 1 of 1 =-=-=-=-=-=-=-=-=-
- echo x - LICENSE
- sed -e 's/^X//' > "LICENSE" << '//E*O*F LICENSE//'
- X GNU GENERAL PUBLIC LICENSE
- X Version 1, February 1989
- X
- X Copyright (C) 1989 Free Software Foundation, Inc.
- X 675 Mass Ave, Cambridge, MA 02139, USA
- X Everyone is permitted to copy and distribute verbatim copies
- X of this license document, but changing it is not allowed.
- X
- X Preamble
- X
- X The license agreements of most software companies try to keep users
- Xat the mercy of those companies. By contrast, our General Public
- XLicense is intended to guarantee your freedom to share and change free
- Xsoftware--to make sure the software is free for all its users. The
- XGeneral Public License applies to the Free Software Foundation's
- Xsoftware and to any other program whose authors commit to using it.
- XYou can use it for your programs, too.
- X
- X When we speak of free software, we are referring to freedom, not
- Xprice. Specifically, the General Public License is designed to make
- Xsure that you have the freedom to give away or sell copies of free
- Xsoftware, that you receive source code or can get it if you want it,
- Xthat you can change the software or use pieces of it in new free
- Xprograms; and that you know you can do these things.
- X
- X To protect your rights, we need to make restrictions that forbid
- Xanyone to deny you these rights or to ask you to surrender the rights.
- XThese restrictions translate to certain responsibilities for you if you
- Xdistribute copies of the software, or if you modify it.
- X
- X For example, if you distribute copies of a such a program, whether
- Xgratis or for a fee, you must give the recipients all the rights that
- Xyou have. You must make sure that they, too, receive or can get the
- Xsource code. And you must tell them their rights.
- X
- X We protect your rights with two steps: (1) copyright the software, and
- X(2) offer you this license which gives you legal permission to copy,
- Xdistribute and/or modify the software.
- X
- X Also, for each author's protection and ours, we want to make certain
- Xthat everyone understands that there is no warranty for this free
- Xsoftware. If the software is modified by someone else and passed on, we
- Xwant its recipients to know that what they have is not the original, so
- Xthat any problems introduced by others will not reflect on the original
- Xauthors' reputations.
- X
- X The precise terms and conditions for copying, distribution and
- Xmodification follow.
- X
- X GNU GENERAL PUBLIC LICENSE
- X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- X
- X 0. This License Agreement applies to any program or other work which
- Xcontains a notice placed by the copyright holder saying it may be
- Xdistributed under the terms of this General Public License. The
- X"Program", below, refers to any such program or work, and a "work based
- Xon the Program" means either the Program or any work containing the
- XProgram or a portion of it, either verbatim or with modifications. Each
- Xlicensee is addressed as "you".
- X
- X 1. You may copy and distribute verbatim copies of the Program's source
- Xcode as you receive it, in any medium, provided that you conspicuously and
- Xappropriately publish on each copy an appropriate copyright notice and
- Xdisclaimer of warranty; keep intact all the notices that refer to this
- XGeneral Public License and to the absence of any warranty; and give any
- Xother recipients of the Program a copy of this General Public License
- Xalong with the Program. You may charge a fee for the physical act of
- Xtransferring a copy.
- X
- X 2. You may modify your copy or copies of the Program or any portion of
- Xit, and copy and distribute such modifications under the terms of Paragraph
- X1 above, provided that you also do the following:
- X
- X a) cause the modified files to carry prominent notices stating that
- X you changed the files and the date of any change; and
- X
- X b) cause the whole of any work that you distribute or publish, that
- X in whole or in part contains the Program or any part thereof, either
- X with or without modifications, to be licensed at no charge to all
- X third parties under the terms of this General Public License (except
- X that you may choose to grant warranty protection to some or all
- X third parties, at your option).
- X
- X c) If the modified program normally reads commands interactively when
- X run, you must cause it, when started running for such interactive use
- X in the simplest and most usual way, to print or display an
- X announcement including an appropriate copyright notice and a notice
- X that there is no warranty (or else, saying that you provide a
- X warranty) and that users may redistribute the program under these
- X conditions, and telling the user how to view a copy of this General
- X Public License.
- X
- X d) You may charge a fee for the physical act of transferring a
- X copy, and you may at your option offer warranty protection in
- X exchange for a fee.
- X
- XMere aggregation of another independent work with the Program (or its
- Xderivative) on a volume of a storage or distribution medium does not bring
- Xthe other work under the scope of these terms.
- X
- X 3. You may copy and distribute the Program (or a portion or derivative of
- Xit, under Paragraph 2) in object code or executable form under the terms of
- XParagraphs 1 and 2 above provided that you also do one of the following:
- X
- X a) accompany it with the complete corresponding machine-readable
- X source code, which must be distributed under the terms of
- X Paragraphs 1 and 2 above; or,
- X
- X b) accompany it with a written offer, valid for at least three
- X years, to give any third party free (except for a nominal charge
- X for the cost of distribution) a complete machine-readable copy of the
- X corresponding source code, to be distributed under the terms of
- X Paragraphs 1 and 2 above; or,
- X
- X c) accompany it with the information you received as to where the
- X corresponding source code may be obtained. (This alternative is
- X allowed only for noncommercial distribution and only if you
- X received the program in object code or executable form alone.)
- X
- XSource code for a work means the preferred form of the work for making
- Xmodifications to it. For an executable file, complete source code means
- Xall the source code for all modules it contains; but, as a special
- Xexception, it need not include source code for modules which are standard
- Xlibraries that accompany the operating system on which the executable
- Xfile runs, or for standard header files or definitions files that
- Xaccompany that operating system.
- X
- X 4. You may not copy, modify, sublicense, distribute or transfer the
- XProgram except as expressly provided under this General Public License.
- XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
- Xthe Program is void, and will automatically terminate your rights to use
- Xthe Program under this License. However, parties who have received
- Xcopies, or rights to use copies, from you under this General Public
- XLicense will not have their licenses terminated so long as such parties
- Xremain in full compliance.
- X
- X 5. By copying, distributing or modifying the Program (or any work based
- Xon the Program) you indicate your acceptance of this license to do so,
- Xand all its terms and conditions.
- X
- X 6. Each time you redistribute the Program (or any work based on the
- XProgram), the recipient automatically receives a license from the original
- Xlicensor to copy, distribute or modify the Program subject to these
- Xterms and conditions. You may not impose any further restrictions on the
- Xrecipients' exercise of the rights granted herein.
- X
- X 7. The Free Software Foundation may publish revised and/or new versions
- Xof the General Public License from time to time. Such new versions will
- Xbe similar in spirit to the present version, but may differ in detail to
- Xaddress new problems or concerns.
- X
- XEach version is given a distinguishing version number. If the Program
- Xspecifies a version number of the license which applies to it and "any
- Xlater version", you have the option of following the terms and conditions
- Xeither of that version or of any later version published by the Free
- XSoftware Foundation. If the Program does not specify a version number of
- Xthe license, you may choose any version ever published by the Free Software
- XFoundation.
- X
- X 8. If you wish to incorporate parts of the Program into other free
- Xprograms whose distribution conditions are different, write to the author
- Xto ask for permission. For software which is copyrighted by the Free
- XSoftware Foundation, write to the Free Software Foundation; we sometimes
- Xmake exceptions for this. Our decision will be guided by the two goals
- Xof preserving the free status of all derivatives of our free software and
- Xof promoting the sharing and reuse of software generally.
- X
- X NO WARRANTY
- X
- X 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
- XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
- XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
- XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
- XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
- XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
- XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
- XREPAIR OR CORRECTION.
- X
- X 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
- XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
- XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
- XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
- XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
- XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
- XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
- XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
- XPOSSIBILITY OF SUCH DAMAGES.
- X
- X END OF TERMS AND CONDITIONS
- //E*O*F LICENSE//
-
- echo x - hostfile
- sed -e 's/^X//' > "hostfile" << '//E*O*F hostfile//'
- Xhqsun7 9993 16
- //E*O*F hostfile//
-
- echo x - mandel.h
- sed -e 's/^X//' > "mandel.h" << '//E*O*F mandel.h//'
- X/*
- X * Mandel by Rob Swiston and Chuck Simmons
- X * Copyright (C) 1989, 1990 by Rob Swiston and Chuck Simmons
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of version 1 of the GNU General Public License as
- X * published by the Free Software Foundation.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * Widely used definitions.
- X */
- X
- X/* Random defaults. */
- X#define HOSTFILE "hostfile"
- X#define HPIXELS 256 /* default screen width in pixels */
- X#define VPIXELS 256 /* default screen height in pixels */
- X
- Xtypedef struct color_x {
- X short color;
- X short x;
- X} color_x_t;
- X
- X#ifndef TRUE
- X# define TRUE 1
- X# define FALSE 0
- X#endif
- X
- //E*O*F mandel.h//
-
- echo x - mserver.c
- sed -e 's/^X//' > "mserver.c" << '//E*O*F mserver.c//'
- X/*
- X * Mandel by Rob Swiston and Chuck Simmons
- X * Copyright (C) 1989, 1990 by Rob Swiston and Chuck Simmons
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of version 1 of the GNU General Public License as
- X * published by the Free Software Foundation.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * This is the glue that holds the server side of the mandelbrot
- X * program together. We set up a listener process that will listen
- X * for connections. In response to a connection, we fork off a child
- X * process that will service the client.
- X */
- X
- X#include <signal.h>
- X#include <stdio.h>
- X#include "mandel.h"
- X#include "net.h"
- X
- X#ifndef SIGCLD
- X# define SIGCLD SIGCHLD /* make the sequent happy */
- X#endif
- X
- Xvoid
- Xusage (name)
- Xchar *name;
- X{
- X (void) fprintf (stderr, "%s: Usage %s port\n", name, name);
- X exit (1);
- X}
- X
- X/*
- X * Clean up after a dead child.
- X */
- X
- Xvoid
- Xcleanup ()
- X{
- X int stat;
- X
- X wait (&stat);
- X}
- X
- Xint
- Xmain (argc, argv)
- Xint argc;
- Xchar **argv;
- X{
- X int port;
- X int sock;
- X
- X if (argc != 2) usage (argv[0]);
- X
- X port = atoi (argv[1]);
- X if (port <= 0) usage (argv[0]);
- X
- X /* Set up a signal handler to clean up after dead children. */
- X (void) signal (SIGCLD, cleanup);
- X
- X /* Start up the listener process, which will fork in
- X * response to each new connection, returning the socket
- X * that was created.
- X */
- X sock = net_slisten (port);
- X if (sock == -1) {
- X perror ("mserver: net_slisten failed");
- X exit (1);
- X }
- X
- X net_server (sock); /* service the client */
- X return 0;
- X}
- X
- X
- //E*O*F mserver.c//
-
- echo x - net.c
- sed -e 's/^X//' > "net.c" << '//E*O*F net.c//'
- X/*
- X * Mandel by Rob Swiston and Chuck Simmons
- X * Copyright (C) 1989, 1990 by Rob Swiston and Chuck Simmons
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of version 1 of the GNU General Public License as
- X * published by the Free Software Foundation.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * This file handles the code to implement a remote procedure call
- X * for the mandelbrot set. There are two portions to this package:
- X * the portion linked into the client side (the side initiating the
- X * rpc), and the portion linked into the server side (the side implementing
- X * the procedure call).
- X *
- X * This 'rpc' is a bit wierd in that on the client side, the 'rpc'
- X * executes asynchronously. That is, the client side will call a
- X * routine to initiate the rpc, passing arguments to the remote procedure
- X * and passing a special value that identifies this call. Later, the
- X * client will notice that the 'rpc' has finished and will call another
- X * routine to pick up the results of the call.
- X *
- X * Since the special identifer value used on the client side is used
- X * purely to identify a packet, this identifier is not passed to the
- X * subroutine on the server side.
- X *
- X * We handle all necessary byte swapping in this routine.
- X */
- X
- X#include <sys/types.h>
- X#include <sys/socket.h>
- X#include <netinet/in.h>
- X#include <netdb.h>
- X#include <errno.h>
- X#include <stdio.h>
- X#include "mandel.h"
- X
- Xextern int errno; /* not defined in errno.h on pyramid */
- X
- X/*
- X * Routines to perform floating point conversion. Our standard format
- X * is that used by the MIPS R2000, Sun, and Sequent systems.
- X */
- X
- X#ifdef VAX_BYTE_ORDER
- X/*
- X * Swap bytes for IEEE floating point.
- X */
- Xdouble
- Xhtond (x)
- Xdouble x;
- X{
- X char *p, *q;
- X double y;
- X int i;
- X
- X p = (char *) &x;
- X q = (char *) &y;
- X
- X for (i = 0; i < sizeof (double); i++) {
- X q[sizeof (double) - i - 1] = p[i];
- X }
- X
- X return y;
- X}
- X
- X# define ntohd(x) htond (x)
- X# define double_done
- X#endif
- X
- X#ifdef CONVEX
- X/*
- X * Convert between Convex floating point format and IEEE floating point.
- X * We need to subtract two from the exponent of the Convex format.
- X *
- X * These routines aren't real robust for very small or very large numbers.
- X */
- X
- Xdouble
- Xhtond (x)
- Xdouble x;
- X{
- X long *l1, *l2;
- X double y;
- X
- X l1 = (long *) &x;
- X l2 = (long *) &y;
- X
- X y = x; /* init result */
- X l2[0] = l1[0] - 0x200000; /* fix up exponent */
- X return y;
- X}
- X
- X/* Add two going the other way. */
- X
- Xdouble
- Xntohd (x)
- Xdouble x;
- X{
- X long *l1, *l2;
- X double y;
- X
- X l1 = (long *) &x;
- X l2 = (long *) &y;
- X
- X y = x; /* init result */
- X l2[0] = l1[0] + 0x200000; /* fix up exponent */
- X return y;
- X}
- X
- X# define double_done
- X#endif
- X
- X#ifdef IS_370
- X/*
- X * Convert between IBM 370 floating point format and IEEE floating point
- X * format.
- X */
- X
- Xdouble
- Xhtond (x)
- Xdouble x;
- X{
- X int exp;
- X int sign;
- X long long frac;
- X double y;
- X long *l;
- X long long *ll;
- X
- X ll = (long long *) &x;
- X frac = *ll; /* fraction and other stuff */
- X exp = (frac >> 56) & 0x7f; /* extract exponent */
- X sign = (frac >> 32) & 0x80000000; /* extract sign */
- X
- X /* build IEEE format */
- X frac = (frac >> 4) & 0xfffffffffffff;
- X
- X /*
- X * Convert the exponent. In IBM land, this is a signed
- X * exponent used as a power of 16. We want a power of
- X * 2, so we make the exponent signed, multiply by 4,
- X * and then add on the bias of 1023.
- X */
- X exp = (exp << 25) >> 25; /* make signed */
- X exp *= 4; /* go from base 16 to base 2 */
- X exp += 1023; /* add on the bias */
- X
- X exp = (exp & 0x7ff) << 20;
- X
- X ll = (long long *) &y;
- X *ll = frac;
- X
- X l = (long *) &y;
- X *l |= sign | exp;
- X
- X(void) printf ("htond: converted (%f) 0x%x 0x%x to 0x%x 0x%x\n",
- X %f, ((long *)(&x))[0], ((long *)(&x))[1],
- X ((long *)(&y))[0], ((long *)(&y))[1]);
- X
- X return y;
- X}
- X
- X/* Go the other way. */
- X
- Xdouble
- Xntohd (x)
- Xdouble x;
- X{
- X int exp;
- X int sign;
- X long long frac;
- X double y;
- X long *l;
- X long *ll;
- X int i;
- X
- X ll = (long long *) &x;
- X frac = *ll; /* fraction and other stuff */
- X exp = (frac >> 52) & 0x7ff; /* extract exponent */
- X sign = (frac >> 32) & 0x80000000; /* extract sign */
- X
- X /* build IEEE format */
- X frac = frac << 4;
- X
- X /*
- X * Convert the exponent. First we subtract off the IEEE bias.
- X * Then, we need to divide by four. If exp is not a multiple
- X * of four, then we shift the fraction one to the right and
- X * increment the exponent until the exponent is a multiple of
- X * four.
- X */
- X exp -= 1023; /* add on the bias */
- X
- X i = 4 - (exp & 3);
- X exp += i;
- X frac >>= i;
- X
- X exp /= 2;
- X exp = (exp << 24) & 0x7f000000;
- X
- X ll = (long long *) &y;
- X *ll = frac & 0xfffffffffffff;
- X
- X l = (long *) &y;
- X *l |= sign | exp;
- X
- X(void) printf ("ntohd: converted 0x%x 0x%x to 0x%x 0x%x (%f)\n",
- X ((long *)(&x))[0], ((long *)(&x))[1],
- X ((long *)(&y))[0], ((long *)(&y))[1], y);
- X
- X return y;
- X}
- X
- X# define double_done
- X#endif
- X
- X#ifndef double_done
- X/*
- X * Use this for IEEE floating point when VAX byte ordering is not
- X * present.
- X */
- X# define htond(x) (x) /* host-to-network double */
- X# define ntohd(x) (x) /* network-to-host double */
- X#endif
- X
- X/*
- X * Define the structure we use for passing information between client
- X * and server.
- X */
- Xtypedef struct net_parms {
- X double x_start, y_start; /* starting coords of line */
- X double x_end; /* ending coord of line */
- X short npixels; /* number of pixels in line */
- X short max_color; /* maximum colors per pixel */
- X long unused; /* pad this out to a multiple of 8 bytes */
- X} net_parms_t;
- X
- X/*
- X * Define the structure used for passing the response.
- X */
- X/* The following doesn't work very well because the pyramid pads this
- X * out to be four bytes instead of the desired two bytes:
- X *
- X * typedef struct net_response {
- X * short buflen; / * number of elements following this header * /
- X * } net_response_t;
- X */
- Xtypedef short net_response_t;
- X
- X#ifdef CLIENT
- X/*
- X * Provide an interface to the remote routine for the client.
- X * Return 0 on success, -1 on error. If an error occurs, 'errno'
- X * will be set.
- X */
- X
- Xint
- Xnet_csend (sock, x_start, y_start, x_end, npixels, max_color)
- Xint sock;
- Xdouble x_start, y_start;
- Xdouble x_end;
- Xint npixels, max_color;
- X{
- X net_parms_t parms;
- X int len;
- X
- X /* package the parameters */
- X parms.x_start = htond (x_start);
- X parms.y_start = htond (y_start);
- X parms.x_end = htond (x_end);
- X parms.npixels = htons (npixels);
- X parms.max_color = htons (max_color);
- X
- X len = write (sock, &parms, sizeof (parms));
- X if (len == -1) return -1; /* return any error */
- X
- X if (len < sizeof (parms)) { /* partial write? */
- X errno = EIO;
- X return -1;
- X }
- X
- X return 0; /* success */
- X}
- X#endif
- X
- X/*
- X * Experience shows that when we issue a read, we may not read all
- X * of the requested bytes, probably because of packetizing on the
- X * network. Here, we will issue multiple reads, if necessary, to
- X * read all desired bytes.
- X */
- X
- Xstatic int
- Xnet_read (sock, buf, buflen)
- Xint sock; /* socket to read */
- Xchar *buf; /* buffer to fill */
- Xint buflen; /* length to read */
- X{
- X int left;
- X int len;
- X char *p;
- X
- X left = buflen;
- X p = buf;
- X while (left > 0) {
- X len = read (sock, p, left);
- X if (len == -1) return -1; /* error occured */
- X if (len == 0) break; /* can't read any more */
- X
- X left -= len;
- X p += len;
- X }
- X
- X return buflen - left;
- X}
- X
- X#ifdef CLIENT
- X/*
- X * Provide a routine to return values to the client. The client gives
- X * us an array that we fill, and we return a length to the client.
- X */
- X
- Xint
- Xnet_crecv (sock, buf)
- Xint sock; /* socket to read */
- Xcolor_x_t *buf; /* buffer to fill */
- X{
- X net_response_t response;
- X int len;
- X int buflen;
- X
- X /* read the response header */
- X len = net_read (sock, (char *) &response, sizeof (response));
- X if (len == -1) return -1; /* oops */
- X if (len < sizeof (response)) {
- X (void) fprintf (stderr,
- X "net_crecv: reading header received %d of %d bytes\n",
- X len, sizeof (response));
- X errno = EIO;
- X return -1;
- X }
- X
- X /* read buffer */
- X buflen = ntohs (response);
- X len = net_read (sock, (char *) buf, sizeof (*buf) * buflen);
- X if (len == -1) return -1;
- X if (len < sizeof (*buf) * buflen) {
- X (void) fprintf (stderr,
- X "net_crecv: reading buffer received %d of %d bytes\n",
- X len, sizeof (*buf) * buflen);
- X errno = EIO;
- X return -1;
- X }
- X
- X /* byteswap the buffer contents */
- X for (len = 0; len < buflen; len++) {
- X buf[len].x = ntohs (buf[len].x);
- X buf[len].color = ntohs (buf[len].color);
- X }
- X return buflen;
- X}
- X#endif
- X
- X/*
- X * The server routine. This routine loops reading requests from the
- X * client and sending back responses.
- X */
- X
- X#ifdef SERVER
- Xvoid
- Xnet_server (sock)
- Xint sock;
- X{
- X net_parms_t parms;
- X net_response_t *response;
- X int len, wlen, i;
- X color_x_t *buf;
- X
- X for (;;) { /* until an error occurs */
- X /* read a request */
- X len = net_read (sock, &parms, sizeof (parms));
- X if (len == -1) {
- X perror ("net_server: cannot read socket");
- X exit (1);
- X }
- X if (len != sizeof (parms)) {
- X if (len == 0) exit (0); /* client went away */
- X (void) fprintf (stderr,
- X "net_server: read %d of %d bytes.\n",
- X len, sizeof (parms));
- X exit (1);
- X }
- X
- X /* Byte swap the request. */
- X parms.x_start = ntohd (parms.x_start);
- X parms.y_start = ntohd (parms.y_start);
- X parms.x_end = ntohd (parms.x_end);
- X parms.npixels = ntohs (parms.npixels);
- X parms.max_color = ntohs (parms.max_color);
- X
- X /* Allocate storage for the response. */
- X len = sizeof (*response) + parms.npixels * sizeof (color_x_t);
- X response = (net_response_t *) malloc (len);
- X if (!response) {
- X (void) fprintf (stderr, "net_server: Out of memory.\n");
- X exit (1);
- X }
- X buf = (color_x_t *) (response + 1);
- X
- X /* Call the remote procedure. */
- X len = mandel_line (parms.x_start, parms.y_start, parms.x_end,
- X parms.npixels, parms.max_color, buf);
- X
- X /* byteswap the buffer contents */
- X for (i = 0; i < len; i++) {
- X buf[i].x = htons (buf[i].x);
- X buf[i].color = htons (buf[i].color);
- X }
- X
- X /* Send the response to the client. */
- X *response = htons (len);
- X
- X wlen = sizeof (*response) + len * sizeof (color_x_t);
- X len = write (sock, (char *) response, wlen);
- X if (len == -1) {
- X perror ("net_server: cannot write socket");
- X exit (1);
- X }
- X if (len != wlen) {
- X (void) fprintf (stderr,
- X "net_server: wrote %d of %d bytes.\n",
- X len, wlen);
- X exit (1);
- X }
- X
- X free ((char *) response);
- X }
- X}
- X
- X/*
- X * Server routine to listen for a connection. In response, we fork
- X * and return the created connection. The parent routine continues
- X * to listen. Return -1 and set errno if we fail at some point.
- X */
- X
- Xint
- Xnet_slisten (port)
- Xint port; /* port on which to listen */
- X{
- X int sock, new_sock;
- X struct sockaddr_in sin, from;
- X int len;
- X
- X bzero ((char *) &sin, sizeof (sin));
- X sin.sin_family = AF_INET;
- X sin.sin_port = port;
- X
- X sock = socket (AF_INET, SOCK_STREAM, 0);
- X if (sock < 0) return -1;
- X
- X if (bind (sock, &sin, sizeof (sin)) < 0) return -1;
- X
- X listen (sock, 1);
- X for (;;) {
- X len = sizeof (from);
- X new_sock = accept (sock, &from, &len);
- X if (new_sock < 0) {
- X if (errno == EINTR) continue;
- X return -1;
- X }
- X
- X switch (fork ()) {
- X case -1: /* error? */
- X return -1;
- X
- X case 0: /* child */
- X (void) close (sock);
- X return new_sock;
- X
- X default: /* parent */
- X (void) close (new_sock);
- X break;
- X }
- X }
- X /* NOTREACHED */
- X}
- X#endif
- X
- X/*
- X * On the client side, open a connection to a server process. Return
- X * the socket for the connection. If something goes wrong, return -1
- X * with 'errno' set.
- X */
- X
- X#ifdef CLIENT
- Xint
- Xnet_copen (host, port)
- Xchar *host;
- Xint port;
- X{
- X int sock;
- X struct sockaddr_in sin;
- X struct hostent *hp;
- X
- X hp = gethostbyname (host);
- X if (!hp) return -1;
- X
- X bzero ((char *) &sin, sizeof (sin));
- X bcopy (hp->h_addr, (char *) &(sin.sin_addr), hp->h_length);
- X sin.sin_family = hp->h_addrtype;
- X sin.sin_port = port;
- X
- X sock = socket (AF_INET, SOCK_STREAM, 0);
- X if (sock < 0) return -1;
- X
- X if (connect (sock, (char *) &sin, sizeof (sin)) < 0) return -1;
- X
- X return sock;
- X}
- X#endif
- X
- //E*O*F net.c//
-
- echo x - net.h
- sed -e 's/^X//' > "net.h" << '//E*O*F net.h//'
- X/*
- X * Mandel by Rob Swiston and Chuck Simmons
- X * Copyright (C) 1989, 1990 by Rob Swiston and Chuck Simmons
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of version 1 of the GNU General Public License as
- X * published by the Free Software Foundation.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * Definitions needed when using the 'net' package.
- X */
- X
- X/* Client routine to initiate an asynchronous rpc. */
- Xint net_csend (/*_ int sock, double x_start, double y_start,
- X double x_end, int npixels, int max_color _*/);
- X
- X/* Client routine to get result of an asynchronous rpc. */
- Xint net_crecv (/*_ int sock, color_x_t *buf _*/);
- X
- X/* Client routine to open a connection. */
- Xint net_copen (/*_ char *host, int port _*/);
- X
- X/* Server routine to handle requests and respond. */
- Xvoid net_server (/*_ int sock _*/);
- X
- X/* Server routine to listen for a client and fork. */
- Xint net_slisten (/*_ int port _*/);
- X
- //E*O*F net.h//
-
- echo x - client.h
- sed -e 's/^X//' > "client.h" << '//E*O*F client.h//'
- X/*
- X * Mandel by Rob Swiston and Chuck Simmons
- X * Copyright (C) 1989, 1990 by Rob Swiston and Chuck Simmons
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of version 1 of the GNU General Public License as
- X * published by the Free Software Foundation.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * Definitions for calling client routines.
- X */
- X
- Xchar *client_init (/* win_info_t *winp */);
- Xint client_reset (/* char *clientp, win_info_t *winp */);
- Xint client_resume (/* char *clientp, win_info_t *winp */);
- X
- //E*O*F client.h//
-
- echo x - colormap.data
- sed -e 's/^X//' > "colormap.data" << '//E*O*F colormap.data//'
- X#bf0000 ; 0.000000 1.000000 0.375000
- X#cc0000 ; 0.000000 1.000000 0.400000
- X#d90000 ; 0.000000 1.000000 0.425000
- X#e60000 ; 0.000000 1.000000 0.450000
- X#f20000 ; 0.000000 1.000000 0.475000
- X#ff0000 ; 0.000000 1.000000 0.500000
- X#ff1a1a ; 0.000000 1.000000 0.550000
- X#ff2e2e ; 0.000000 1.000000 0.590000
- X#ff4242 ; 0.000000 1.000000 0.630000
- X#ff5757 ; 0.000000 1.000000 0.670000
- X#ff6b6b ; 0.000000 1.000000 0.710000
- X#ff8080 ; 0.000000 1.000000 0.750000
- X#ff8c8c ; 0.000000 1.000000 0.775000
- X#ff9999 ; 0.000000 1.000000 0.800000
- X#ffa6a6 ; 0.000000 1.000000 0.825000
- X#ffcba6 ; 0.070000 1.000000 0.825000
- X#ffc499 ; 0.070000 1.000000 0.800000
- X#ffbc8c ; 0.070000 1.000000 0.775000
- X#ffb580 ; 0.070000 1.000000 0.750000
- X#ffa96b ; 0.070000 1.000000 0.710000
- X#ff9d57 ; 0.070000 1.000000 0.670000
- X#ff9242 ; 0.070000 1.000000 0.630000
- X#ff862e ; 0.070000 1.000000 0.590000
- X#ff7a1a ; 0.070000 1.000000 0.550000
- X#ff6b00 ; 0.070000 1.000000 0.500000
- X#f26600 ; 0.070000 1.000000 0.475000
- X#e66000 ; 0.070000 1.000000 0.450000
- X#d95b00 ; 0.070000 1.000000 0.425000
- X#cc5600 ; 0.070000 1.000000 0.400000
- X#bf5000 ; 0.070000 1.000000 0.375000
- X#bf7e00 ; 0.110000 1.000000 0.375000
- X#cc8700 ; 0.110000 1.000000 0.400000
- X#d98f00 ; 0.110000 1.000000 0.425000
- X#e69700 ; 0.110000 1.000000 0.450000
- X#f2a000 ; 0.110000 1.000000 0.475000
- X#ffa800 ; 0.110000 1.000000 0.500000
- X#ffb11a ; 0.110000 1.000000 0.550000
- X#ffb82e ; 0.110000 1.000000 0.590000
- X#ffbf42 ; 0.110000 1.000000 0.630000
- X#ffc657 ; 0.110000 1.000000 0.670000
- X#ffcd6b ; 0.110000 1.000000 0.710000
- X#ffd480 ; 0.110000 1.000000 0.750000
- X#ffd88c ; 0.110000 1.000000 0.775000
- X#ffdc99 ; 0.110000 1.000000 0.800000
- X#ffe1a6 ; 0.110000 1.000000 0.825000
- X#fff1a6 ; 0.140000 1.000000 0.825000
- X#ffef99 ; 0.140000 1.000000 0.800000
- X#ffed8c ; 0.140000 1.000000 0.775000
- X#ffeb80 ; 0.140000 1.000000 0.750000
- X#ffe76b ; 0.140000 1.000000 0.710000
- X#ffe457 ; 0.140000 1.000000 0.670000
- X#ffe142 ; 0.140000 1.000000 0.630000
- X#ffde2e ; 0.140000 1.000000 0.590000
- X#ffda1a ; 0.140000 1.000000 0.550000
- X#ffd600 ; 0.140000 1.000000 0.500000
- X#f2cb00 ; 0.140000 1.000000 0.475000
- X#e6c100 ; 0.140000 1.000000 0.450000
- X#d9b600 ; 0.140000 1.000000 0.425000
- X#ccab00 ; 0.140000 1.000000 0.400000
- X#bfa100 ; 0.140000 1.000000 0.375000
- X#b0bf00 ; 0.180000 1.000000 0.375000
- X#bccc00 ; 0.180000 1.000000 0.400000
- X#c7d900 ; 0.180000 1.000000 0.425000
- X#d3e600 ; 0.180000 1.000000 0.450000
- X#dff200 ; 0.180000 1.000000 0.475000
- X#ebff00 ; 0.180000 1.000000 0.500000
- X#edff1a ; 0.180000 1.000000 0.550000
- X#eeff2e ; 0.180000 1.000000 0.590000
- X#f0ff42 ; 0.180000 1.000000 0.630000
- X#f2ff57 ; 0.180000 1.000000 0.670000
- X#f3ff6b ; 0.180000 1.000000 0.710000
- X#f5ff80 ; 0.180000 1.000000 0.750000
- X#f6ff8c ; 0.180000 1.000000 0.775000
- X#f7ff99 ; 0.180000 1.000000 0.800000
- X#f8ffa6 ; 0.180000 1.000000 0.825000
- X#ddffa6 ; 0.230000 1.000000 0.825000
- X#d8ff99 ; 0.230000 1.000000 0.800000
- X#d3ff8c ; 0.230000 1.000000 0.775000
- X#cfff80 ; 0.230000 1.000000 0.750000
- X#c7ff6b ; 0.230000 1.000000 0.710000
- X#bfff57 ; 0.230000 1.000000 0.670000
- X#b7ff42 ; 0.230000 1.000000 0.630000
- X#b0ff2e ; 0.230000 1.000000 0.590000
- X#a8ff1a ; 0.230000 1.000000 0.550000
- X#9eff00 ; 0.230000 1.000000 0.500000
- X#96f200 ; 0.230000 1.000000 0.475000
- X#8ee600 ; 0.230000 1.000000 0.450000
- X#86d900 ; 0.230000 1.000000 0.425000
- X#7ecc00 ; 0.230000 1.000000 0.400000
- X#77bf00 ; 0.230000 1.000000 0.375000
- X#04bf00 ; 0.330000 1.000000 0.375000
- X#04cc00 ; 0.330000 1.000000 0.400000
- X#04d900 ; 0.330000 1.000000 0.425000
- X#05e600 ; 0.330000 1.000000 0.450000
- X#05f200 ; 0.330000 1.000000 0.475000
- X#05ff00 ; 0.330000 1.000000 0.500000
- X#1eff1a ; 0.330000 1.000000 0.550000
- X#32ff2e ; 0.330000 1.000000 0.590000
- X#46ff42 ; 0.330000 1.000000 0.630000
- X#5aff57 ; 0.330000 1.000000 0.670000
- X#6eff6b ; 0.330000 1.000000 0.710000
- X#82ff80 ; 0.330000 1.000000 0.750000
- X#8fff8c ; 0.330000 1.000000 0.775000
- X#9bff99 ; 0.330000 1.000000 0.800000
- X#a8ffa6 ; 0.330000 1.000000 0.825000
- X#a6ffe4 ; 0.450000 1.000000 0.825000
- X#99ffe0 ; 0.450000 1.000000 0.800000
- X#8cffdd ; 0.450000 1.000000 0.775000
- X#80ffd9 ; 0.450000 1.000000 0.750000
- X#6bffd3 ; 0.450000 1.000000 0.710000
- X#57ffcd ; 0.450000 1.000000 0.670000
- X#42ffc6 ; 0.450000 1.000000 0.630000
- X#2effc0 ; 0.450000 1.000000 0.590000
- X#1affba ; 0.450000 1.000000 0.550000
- X#00ffb3 ; 0.450000 1.000000 0.500000
- X#00f2aa ; 0.450000 1.000000 0.475000
- X#00e6a1 ; 0.450000 1.000000 0.450000
- X#00d998 ; 0.450000 1.000000 0.425000
- X#00cc8f ; 0.450000 1.000000 0.400000
- X#00bf86 ; 0.450000 1.000000 0.375000
- X#00a8bf ; 0.520000 1.000000 0.375000
- X#00b4cc ; 0.520000 1.000000 0.400000
- X#00bfd9 ; 0.520000 1.000000 0.425000
- X#00cae6 ; 0.520000 1.000000 0.450000
- X#00d5f2 ; 0.520000 1.000000 0.475000
- X#00e0ff ; 0.520000 1.000000 0.500000
- X#1ae3ff ; 0.520000 1.000000 0.550000
- X#2ee6ff ; 0.520000 1.000000 0.590000
- X#42e8ff ; 0.520000 1.000000 0.630000
- X#57ebff ; 0.520000 1.000000 0.670000
- X#6bedff ; 0.520000 1.000000 0.710000
- X#80f0ff ; 0.520000 1.000000 0.750000
- X#8cf1ff ; 0.520000 1.000000 0.775000
- X#99f3ff ; 0.520000 1.000000 0.800000
- X#a6f4ff ; 0.520000 1.000000 0.825000
- X#a6d4ff ; 0.580000 1.000000 0.825000
- X#99ceff ; 0.580000 1.000000 0.800000
- X#8cc8ff ; 0.580000 1.000000 0.775000
- X#80c2ff ; 0.580000 1.000000 0.750000
- X#6bb8ff ; 0.580000 1.000000 0.710000
- X#57aeff ; 0.580000 1.000000 0.670000
- X#42a4ff ; 0.580000 1.000000 0.630000
- X#2e9bff ; 0.580000 1.000000 0.590000
- X#1a91ff ; 0.580000 1.000000 0.550000
- X#0085ff ; 0.580000 1.000000 0.500000
- X#007ef2 ; 0.580000 1.000000 0.475000
- X#0077e6 ; 0.580000 1.000000 0.450000
- X#0071d9 ; 0.580000 1.000000 0.425000
- X#006acc ; 0.580000 1.000000 0.400000
- X#0063bf ; 0.580000 1.000000 0.375000
- X#0008bf ; 0.660000 1.000000 0.375000
- X#0008cc ; 0.660000 1.000000 0.400000
- X#0009d9 ; 0.660000 1.000000 0.425000
- X#0009e6 ; 0.660000 1.000000 0.450000
- X#000af2 ; 0.660000 1.000000 0.475000
- X#000aff ; 0.660000 1.000000 0.500000
- X#1a23ff ; 0.660000 1.000000 0.550000
- X#2e36ff ; 0.660000 1.000000 0.590000
- X#424aff ; 0.660000 1.000000 0.630000
- X#575dff ; 0.660000 1.000000 0.670000
- X#6b71ff ; 0.660000 1.000000 0.710000
- X#8085ff ; 0.660000 1.000000 0.750000
- X#8c91ff ; 0.660000 1.000000 0.775000
- X#999dff ; 0.660000 1.000000 0.800000
- X#a6a9ff ; 0.660000 1.000000 0.825000
- X#d2a6ff ; 0.750000 1.000000 0.825000
- X#cc99ff ; 0.750000 1.000000 0.800000
- X#c68cff ; 0.750000 1.000000 0.775000
- X#bf80ff ; 0.750000 1.000000 0.750000
- X#b56bff ; 0.750000 1.000000 0.710000
- X#ab57ff ; 0.750000 1.000000 0.670000
- X#a142ff ; 0.750000 1.000000 0.630000
- X#962eff ; 0.750000 1.000000 0.590000
- X#8c1aff ; 0.750000 1.000000 0.550000
- X#8000ff ; 0.750000 1.000000 0.500000
- X#7900f2 ; 0.750000 1.000000 0.475000
- X#7300e6 ; 0.750000 1.000000 0.450000
- X#6c00d9 ; 0.750000 1.000000 0.425000
- X#6600cc ; 0.750000 1.000000 0.400000
- X#6000bf ; 0.750000 1.000000 0.375000
- X#9900bf ; 0.800000 1.000000 0.375000
- X#a300cc ; 0.800000 1.000000 0.400000
- X#ad00d9 ; 0.800000 1.000000 0.425000
- X#b800e6 ; 0.800000 1.000000 0.450000
- X#c200f2 ; 0.800000 1.000000 0.475000
- X#cc00ff ; 0.800000 1.000000 0.500000
- X#d11aff ; 0.800000 1.000000 0.550000
- X#d52eff ; 0.800000 1.000000 0.590000
- X#d942ff ; 0.800000 1.000000 0.630000
- X#dd57ff ; 0.800000 1.000000 0.670000
- X#e16bff ; 0.800000 1.000000 0.710000
- X#e680ff ; 0.800000 1.000000 0.750000
- X#e88cff ; 0.800000 1.000000 0.775000
- X#eb99ff ; 0.800000 1.000000 0.800000
- X#eda6ff ; 0.800000 1.000000 0.825000
- X#ffa6fb ; 0.840000 1.000000 0.825000
- X#ff99fb ; 0.840000 1.000000 0.800000
- X#ff8cfa ; 0.840000 1.000000 0.775000
- X#ff80fa ; 0.840000 1.000000 0.750000
- X#ff6bf9 ; 0.840000 1.000000 0.710000
- X#ff57f8 ; 0.840000 1.000000 0.670000
- X#ff42f7 ; 0.840000 1.000000 0.630000
- X#ff2ef7 ; 0.840000 1.000000 0.590000
- X#ff1af6 ; 0.840000 1.000000 0.550000
- X#ff00f5 ; 0.840000 1.000000 0.500000
- X#f200e9 ; 0.840000 1.000000 0.475000
- X#e600dc ; 0.840000 1.000000 0.450000
- X#d900d0 ; 0.840000 1.000000 0.425000
- X#cc00c4 ; 0.840000 1.000000 0.400000
- X#bf00b8 ; 0.840000 1.000000 0.375000
- X#bf007e ; 0.890000 1.000000 0.375000
- X#cc0087 ; 0.890000 1.000000 0.400000
- X#d9008f ; 0.890000 1.000000 0.425000
- X#e60097 ; 0.890000 1.000000 0.450000
- X#f200a0 ; 0.890000 1.000000 0.475000
- X#ff00a8 ; 0.890000 1.000000 0.500000
- X#ff1ab1 ; 0.890000 1.000000 0.550000
- X#ff2eb8 ; 0.890000 1.000000 0.590000
- X#ff42bf ; 0.890000 1.000000 0.630000
- X#ff57c6 ; 0.890000 1.000000 0.670000
- X#ff6bcd ; 0.890000 1.000000 0.710000
- X#ff80d4 ; 0.890000 1.000000 0.750000
- X#ff8cd8 ; 0.890000 1.000000 0.775000
- X#ff99dc ; 0.890000 1.000000 0.800000
- X#ffa6e1 ; 0.890000 1.000000 0.825000
- X#ffa6c6 ; 0.940000 1.000000 0.825000
- X#ff99be ; 0.940000 1.000000 0.800000
- X#ff8cb6 ; 0.940000 1.000000 0.775000
- X#ff80ad ; 0.940000 1.000000 0.750000
- X#ff6ba0 ; 0.940000 1.000000 0.710000
- X#ff5793 ; 0.940000 1.000000 0.670000
- X#ff4286 ; 0.940000 1.000000 0.630000
- X#ff2e79 ; 0.940000 1.000000 0.590000
- X#ff1a6c ; 0.940000 1.000000 0.550000
- X#ff005c ; 0.940000 1.000000 0.500000
- X#f20057 ; 0.940000 1.000000 0.475000
- X#e60053 ; 0.940000 1.000000 0.450000
- X#d9004e ; 0.940000 1.000000 0.425000
- X#cc0049 ; 0.940000 1.000000 0.400000
- X#bf0045 ; 0.940000 1.000000 0.375000
- //E*O*F colormap.data//
-
- echo x - compute.c
- sed -e 's/^X//' > "compute.c" << '//E*O*F compute.c//'
- X/*
- X * Mandel by Rob Swiston and Chuck Simmons
- X * Copyright (C) 1989, 1990 by Rob Swiston and Chuck Simmons
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of version 1 of the GNU General Public License as
- X * published by the Free Software Foundation.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * This file contains the code to perform mandelbrot calculations.
- X * We are given a description of the line segment on the real plane
- X * and the number of pixels that will be used to display that line
- X * segment. For each pixel, we compute a color to be used for drawing
- X * that segment. The resulting pixels are run-length encoded and
- X * stored into a passed buffer.
- X */
- X
- X#include "mandel.h"
- X
- X/* Return the number of elements we put in the buffer. */
- X
- Xint
- Xmandel_line (x_start, y_start, x_end, npixels, max_color, buf)
- Xdouble x_start, y_start; /* starting co-ordinates of line segment */
- Xdouble x_end; /* ending co-ordinate of line segment */
- Xint npixels; /* number of pixels to compute */
- Xint max_color; /* maximum color we should use */
- Xcolor_x_t *buf; /* output -- buffer of 'npixels' elements that we fill */
- X{
- X double x, x_inc;
- X int buflen;
- X int i, color, old_color;
- X
- X buflen = 0; /* nothing in buffer yet */
- X x = x_start;
- X x_inc = (x_end - x_start) / (double) npixels;
- X for (i = 0; i < npixels; i++) {
- X color = get_color (x, y_start, max_color);
- X
- X if (i == 0) old_color = color;
- X else if (color != old_color) {
- X buf[buflen].x = i-1;
- X buf[buflen].color = old_color;
- X buflen += 1;
- X old_color = color;
- X }
- X
- X x += x_inc;
- X }
- X
- X /* save the last color */
- X buf[buflen].x = i-1;
- X buf[buflen].color = old_color;
- X buflen += 1;
- X
- X return buflen;
- X}
- X
- X/*
- X * Given a location on a plane, perform up to N iterations on that point
- X * in order to figure out whether or not the point is in the Mandelbrot
- X * Set.
- X *
- X * We return a value in the range 0..ncolors. If 'ncolors' is returned,
- X * the point is probably in the set. Lower values indicate how "close" the
- X * point is to the set. The lower the value, the farther away the point is.
- X *
- X * We loop computing "z = z*z + c", where 'c' is the initial complex
- X * number 'x + i*y', and 'z' is a complex variable. 'c' is in the mandelbrot
- X * set if, as N goes to infinity, the values assigned to 'z' converge.
- X * Basically, if |z| > 4, then we know that the value won't converge.
- X *
- X * This version is written so as to encourage compilers to overlap
- X * instructions and perform other optimizations.
- X */
- X
- X#ifndef NCUBE
- Xint
- Xget_color (cx, cy, ncolors)
- Xregister double cx, cy;
- Xregister int ncolors;
- X{
- X register int i;
- X register double zx, zy, xx, xy, yy, t, xy2, four;
- X
- X zx = cx;
- X zy = cy;
- X four = 4.0;
- X i = 0;
- X
- X for (;;) {
- X xy = zx * zy;
- X xx = zx * zx;
- X xy2 = xy + xy;
- X yy = zy * zy;
- X
- X zy = xy2 + cy;
- X t = xx + yy;
- X zx = xx - yy + cx;
- X
- X if (t > four) break;
- X i += 1;
- X if (i == ncolors) break;
- X }
- X
- X return i;
- X}
- X#endif
- //E*O*F compute.c//
-
- echo x - README
- sed -e 's/^X//' > "README" << '//E*O*F README//'
- X/*
- X * Mandel by Rob Swiston and Chuck Simmons
- X * Copyright (C) 1989, 1990 by Rob Swiston and Chuck Simmons
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of version 1 of the GNU General Public License as
- X * published by the Free Software Foundation.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- XThis file contains all the documentation there is on this Mandelbrot program.
- XIt provides porting hints and usage instructions. If there isn't enough
- Xinformation in here, you'll probably have to (*gasp*) read the source code.
- X
- XThis document contains the following sections:
- X
- X Background -- gives a real brief history and the motivation for
- X the structure of the program.
- X
- X Porting Hints -- talks about the program structure and gives
- X warnings about some problems that you might
- X encounter.
- X
- X Installation -- describes how to install the program with the
- X assumption that no portability problems will
- X arise.
- X
- X Use -- describes how to start up and run the program.
- X
- X Options -- briefly describes command line options to the
- X program.
- X
- X Commands -- briefly describes various mouse and keyboard
- X commands you can give to the program.
- X
- X
- XBackground
- X----------
- X
- XThis was one of the more interesting projects I've ever been involved in.
- XIt all started when Lei Tung decided he wanted to draw pictures of the
- XMandelbrot set on his HP machine. After a week or two, Rob Swiston took
- XLei's code and modified it to run over a network. I think I then slapped
- Xon an X windows interface.
- X
- XOne of the really nice things about working for Oracle is that they have
- Xa fairly nice internal network, and they have *lots* of different kinds
- Xof hardware. We wanted a program where we could have a client running on
- Xone machine which would make use of multiple compute servers running on
- Xother machines. And we wanted things to run in very heterogeneous
- Xenvironments. For the most part, I think we met these goals.
- X
- X
- XPorting Hints
- X-------------
- X
- XUnfortunately, it's impossible for me to verify this release of the code
- Xon all the machines that it has run on in the past. Additionally, there
- Xwill probably be minor differences between your machine and my machine
- Xwhich will keep things from working. And I'll probably break something
- Xwhen I package things up, if I haven't broken them already. Hopefully,
- Xthe porting process will be trivial, but if not, this section contains
- Xvarious hints that may be useful. If you find any bugs, I'll be interested
- Xin hearing about them.
- X
- XLet's start with the program structure. The program is fairly cleanly
- Xseparated into a few different layers. First, there's the user interface
- Xlayer (gui.c). All of the X specific code is in this layer. In theory,
- Xyou could rewrite this layer to use a different windowing system. Next,
- Xthere is the "client" layer (client.c). This layer is responsible for
- Xinitializing the network connections and subdividing the computation of
- Xan image among multiple compute servers.
- X
- XThe next layer is the network layer (net.c). The network layer
- Xbasically implements a simple Remote Procedure Call (RPC) interface.
- XCurrently, this layer uses TCP/IP as the underlying communications mechanism.
- XIn theory, this layer could be rewritten to use an alternative communications
- Xmechanism. There are actually two parts to the network layer: the
- Xclient side, and the server side. These are bundled into a single file
- Xwhich leads to some wierdnesses in the makefile, but nothing real important.
- X
- X[For all of you out there just dying to use your NCube as a compute server,
- XI have a version of the network layer that acts as a gateway between TCP/IP
- Xand the NCube communications links.]
- X
- XFinally, there is the "compute" layer (compute.c). This is a very simple
- Xlayer where all the real work gets done.
- X
- XWhen you build the program, you will actually create two binaries. One
- Xbinary is the "client" program. This program gets linked with the X libraries
- Xand will need to run on a machine which can communicate with an X server.
- XThe other binary is the "server" program. This program requires TCP/IP
- Xand libm.a but not much else.
- X
- XBecause we wanted the program to be portable and to run in a heterogeneous
- Xnetwork, there are certain modifications you will need to make to the
- Xmakefile, and possibly to the network layer. When the network layer
- Xtransmits data across the network, it first translates the data into
- Xa network canonical format. When reading data from the net, the data
- Xis then translated into a local host format. The network canonical format
- Xis defined so as to be compatible with a Sun. This means that integers
- Xare transmitted so that they have the same byte order as on a Sun and
- Xfloating point numbers are converted to IEEE representation.
- X
- XTransmitting the integers is real easy. The TCP/IP package generally
- Xprovides routines named 'ntohs', 'htons', etc. [These stand for
- Xnetwork-to-host-short and host-to-network-short.] Floating point numbers
- Xare somewhat more complex. While it is rare to find a machine that
- Xdoes not have 8-bit bytes, 16-bit words, 32-bit long words, etc; it
- Xis fairly common to find machines that don't use IEEE floating point.
- XTherefore, the network layer contains some routines that attempt to
- Xperform conversions from certain types of formats to certain other types.
- X
- XWhat does the above mean to you as a porter? First, if you are on
- Xa machine that has the same byte order as the VAX, 80x86, NCube, or
- XDecStation 3100, then you must define -DVAX_BYTE_ORDER when compiling
- Xcode to run on that machine. This will cause the network layer to
- Xcorrectly convert integers when transmitting across the network.
- X
- XNext, you may need to define a flag to describe the floating point
- Xformat of your machine. Even worse, you may need to implement a
- Xfloating point conversion routine. The following flags currently exist:
- X
- X -DCONVEX should be defined if you are runnong on the Convex
- X machine. This was actually tested at one point.
- X
- X -DIS_370 should be defined if you are running on an IBM 370
- X compatible machine such as an Amdahl 5990. (Other IBM 370
- X machines probably don't have sufficient compute power for this
- X extremely demanding application. :-) Now, I went off and wrote
- X code to perform floating point conversions between IBM 370
- X format and IEEE format, but... I NEVER TESTED THE CODE!!!
- X I can virtually guarantee that it won't work. But if you get
- X it working, I'd be interested in any changes you make.
- X
- XIf you are on some other type of non-IEEE machine, you'll need to
- Xdefine your own floating point conversion routines in net.c. [Also,
- Xif you don't care about heterogeneous networks, then you can just
- Xpretend you are on an IEEE type of machine.]
- X
- XOne problem cropped up when I ported the code to the Pyramid. The
- Xstructures that I use for passing information across the network were
- Xpadded by the Pyramid compiler in strange and wonderful ways. I just
- Xadded the extra padding to my structure. However, if you are on some
- Xstrange machine, you may run into a similar problem. If so, do whatever
- Xyou think is best to fix the problem.
- X
- XOh yeah... Color... This program is designed to use color. There are
- Xactually hooks sitting around that allow you to run the program on a
- Xblack and white terminal, but it's not as visually exciting. We got
- Xlucky on one Sun sparcstation and the colormap happened to be initialized
- Xto reasonable values, and we got a recognizable black and white image.
- XOn my Sparcstation we didn't get so lucky and we got a big black image.
- XTweak the code in 'gui.c' or find an X guru to help you tweak the code.
- X
- X
- XInstallation
- X------------
- X
- X1) Unpack the sources. Presumably you have saved the sources in
- Xsome file, say 'mandel.shar'. Type
- X
- X sh mandel.shar
- X
- XThis should leave a bunch of files lying around in your current directory.
- X
- X2) Edit the makefile, "mandel.mk".
- X
- X 2a) If you are on a machine that has the same byte
- X order as a Vax, 80x86, NCube, or DecStation 3100, then uncomment the line
- X that contains "-DVAX_BYTE_ORDER".
- X
- X 2b) If you are on a Convex, uncomment the line that contains "-DCONVEX".
- X
- X If you are on a 370 compatible machine, uncomment the line that contains
- X "-DIS_370", and then go read the porting notes above if you haven't
- X already done so.
- X
- X3) Run the makefile. Type
- X
- X make -f mandel.mk
- X
- XThis should create a binary named 'mandel' and a binary named 'mserver'.
- XIf any problems arise, fix them as you see fit. The porting notes above
- Xmight be useful.
- X
- X
- XUse
- X---
- X
- XThe user interface is not real wonderful. First, let's talk about starting
- Xup the program.
- X
- X1) Edit the file named 'hostfile'. [Note that this must be contained
- Xin the directory from which you plan on running the mandelbrot program.
- XSounds like a bug to me, too.] This file needs to contain a list of
- X"listener" processes. This file contains a number of lines that look like:
- X
- X fred 9993 4
- X
- XThe first word is the name of a machine on which you will run a compute
- Xserver. The next number is the TCP/IP socket address on which the compute
- Xserver will listen for connections. The final number is the number of
- Xserver processes that the client should attempt to use on this machine.
- XTypically, this number is equal to the number of processors available on
- Xthat machine. There will be examples below.
- X
- X2) Generate an 'mserver' binary for each machine on which you plan on
- Xrunning a compute server. This will require probably require editing the
- Xmakefile if you're really going to use more than one type of machine. It's
- Xsomething of a pain, but relatively easy.
- X
- X3) Copy an appropriate 'mserver' binary to each machine on which you
- Xwant to run a compute server.
- X
- X4) Start up 'mserver' on each machine where you want to run a compute
- Xserver. Give a command like:
- X
- X mserver 9993 &
- X
- XThis tells the server the port on which it should listen for connections
- Xand puts the process in the background.
- X
- X5) Go to the machine on which you want to run the client. Make sure
- Xyour DISPLAY environment variable is set correctly and that you are
- X'xhost'ed on the machine which is running the X-Server for your display.
- XGive the command "mandel". [There are numerous options here which will
- Xbe discussed below.]
- X
- X
- XExample 1
- X---------
- X
- XLet's suppose you want to do something real simple. You have a workstation
- Xnamed 'fred'. You want to run both the client and the server on this
- Xworkstation, with display output going to the workstation's screen.
- X
- X1) If your DISPLAY variable is not set, set it. Under the c-shell, this
- Xwould look like:
- X
- X setenv DISPLAY :0
- X
- X(or somesuch).
- X
- X2) Edit the 'hostfile' to contain the line:
- X
- X fred 9993 1
- X
- X3) Start up the server listener process:
- X
- X mserver 9993 &
- X
- X4) Start up the mandelbrot program:
- X
- X mandel
- X
- XAt this point, if all goes well, a window should appear on your
- Xscreen and it should begin to fill with colors, and hopefully a
- Xrecognizable mandelbrot set will form.
- X
- X
- XExample 2
- X---------
- X
- XLet's suppose it's the middle of the night and you talked some of
- Xyour co-workers into lending you the use of their workstation's cpu's.
- XYou have a dumb X terminal (but a dumb *color* X terminal), so you want
- Xto run your client on the local fileserver. So you will run programs
- Xon the following machines:
- X
- X fred -- a Sparcstation
- X mary -- a Sparcstation
- X jane -- a 4 processor Apollo DN10000
- X fs -- a Sun 4 fileserver
- X
- X1) Build the mandelbrot programs using the installation instructions above.
- X
- X2) Install the mandelbrot program on 'jane' (the Apollo machine) and just
- Xbuild the 'mserver'. (That way you don't have to worry about having X lying
- Xaround.)
- X
- X3) Edit the 'hostfile' in one of your Sparcstation filesystems so it
- Xlooks like:
- X
- X fred 9993 1
- X mary 9993 1
- X jane 9993 4
- X
- X4) On 'jane' (the Apollo), run the listener process:
- X
- X mserver 9993 &
- X
- X5) On each of 'fred' and 'mary' (the Sparcstations) run the listener process:
- X
- X mserver 9993 &
- X
- X6) On 'fs' (the fileserver) make sure your DISPLAY environment variable
- Xis set correctly. If necessary, tell your X terminal to 'xhost fs'. Make
- Xsure you are in the directory which contains the 'hostfile'.
- X
- X7) Run the mandelbrot program:
- X
- X mandel
- X
- X
- XOptions
- X-------
- X
- XWe tried to give 'mandel' as many options as 'ls'. But this is
- Xdifficult to do. Here is a brief description of each of the options:
- X
- X -help
- X
- X This isn't really an option, but it will generate
- X an error message and cause the program to print out
- X a list of available options.
- X
- X -c colorfile
- X
- X I've shipped the mandelbrot program with a file named
- X 'colormap.data'. You can create your own colormap file.
- X Basically, this file contains the list of colors to
- X which the colormap should be initialized. 'colormap.data'
- X contains a list of colors that I particularly like.
- X
- X -d host:display
- X
- X If you haven't set your DISPLAY environment variable,
- X this argument should allow you to specify the same information.
- X I never use it, so maybe it doesn't work.
- X
- X -g geometry
- X
- X This specifies the geometry of the initial window to
- X create. I believe the argument is in standard X syntax.
- X Again, I probably never use this option, so it might not
- X work.
- X
- X -i count
- X
- X This specifies the number of iterations that a compute
- X server will perform on a pixel before deciding that the
- X pixel is not in the mandelbrot set. The larger the
- X value, the slower the program runs. The network interface
- X imposes a limit of 32K on this value, and the program will
- X probably break silently if this value is exceeded.
- X
- X -m mud_max
- X -n mud_num
- X
- X These two variables provide another mechanism for
- X initializing the colormap. I haven't used these since
- X I implemented the '-c' option above. Experiment with
- X these if you want. The arguments are relatively small
- X integers. Something like "-m 10 -n 3" might be reasonable.
- X
- X -p pixel_size
- X
- X Basically, this specifies how much of the set you want
- X to appear in your window. The argument should be a
- X real number less than 1.0. Experiment with this if you
- X want, but it isn't all that useful. (See -x and -y below.)
- X
- X -r
- X
- X This causes the program to use the root window as
- X its output window. When this option is given, the
- X user interface is disabled and the program will
- X move around in the set selecting locations it wants
- X to look at. Mildly interesting, but needs additional
- X work to select fun places to look at.
- X
- X -s show_time
- X
- X This causes the initial color map to be displayed on
- X your screen. 'show_time' specifies a sleep interval.
- X 30 is a reasonable value. This is primarily useful
- X for debugging a colormap file.
- X
- X -x x
- X -y y
- X
- X These two options are used to set the initial co-ordinates
- X of the screen. These are only useful if you know the
- X co-ordinates of an area you want to look at. Typically,
- X the -p option is used in conjunction with these two options.
- X
- XThe only options that I really use are "-i", "-c", and "-r". I recommend:
- X
- X mandel -c colormap.data -i 1000
- X
- Xfor starters.
- X
- X
- XCommands
- X--------
- X
- XOnce you've gotten mandelbrot up and running, you can give commands
- Xto the user interface. Commands are as follows:
- X
- X resize the window
- X
- X This is generally done by grabbing a handle on the
- X upper-right corner of the window and stretching the
- X window to be the desired shape.
- X
- X click and drag
- X
- X You can select a rectangular area of your window and
- X have that area of the screen blown up. (er, expanded).
- X To do this, move the mouse to one corner of the rectangle.
- X
- X Press and hold down a mouse buton. (I always use the
- X left mouse button, but the code looks as if it will
- X work for any mouse button.)
- X
- X Drag the mouse to the diagonally opposite corner of the
- X rectangle. (While you are doing this, the program is
- X supposed to be drawing an outline around the box that
- X you are moving. However, when I wrote the code, I didn't
- X understand the way the various bitblt operations worked
- X in X, and I screwed this up. So you probably won't see
- X the box displayed on the screen.)
- X
- X Release the mouse button.
- X
- X At this point, a new window will be created which has
- X the shape of the rectangle you selected, but which has
- X the same area as the original window. The contents of
- X the original window that lie within the selected rectangle
- X will expand to fill the new window.
- X
- X 'q'
- X
- X Typing "q" in the window will quit the program.
- X
- X 'z'
- X
- X Typing "z" in the window will "zoom out". The current
- X image will be redrawn in the center 1/9th of the window,
- X while the remainder of the window will be filled with
- X the surrounding area.
- X
- X 'e'
- X
- X Expands the window. The width and height of the current
- X window will be doubled.
- X
- X 's'
- X Shrinks the window. The width and height of the current
- X window will be halved.
- X
- X
- XChuck Simmons
- Xcsimmons@oracle.oracle.com
- X29 March 1989
- XFoster City, California
- //E*O*F README//
-
- exit 0
-