World-Wide Distributed Computing in the CH Language Environment

     )   
  ( ( (  
   ) ) ) 
  ------ 
  oooooo 
    ||   
    ||   

Table of Contents


Introduction

The CH language environment can be used for World-Wide Distributed Computing (WWDC). You can download CH programs located remotely in a server of the CH language environment and then execute them in the client, your host computer. Such a network-downloaded program is called applet. If you have installed the CH language environment according to its installation instructions, you can run this CH applet located remotely in our server of the CH language environment. The program will be downloaded through the Web and executed on your computer. Don't worry, this is a benign program and it will not do any harm to your system. Seeing is believing, take a look at the source code of this CH applet. You will find out that it is just a simple C program. Indeed, CH is designed to be a superset of C. When you click the above highlighted word "run", if the applet is not executed to produce the following output
      Hello, world!
      Today is (date)
and instead downloaded as a text file C1.sch, you should download the CH language environment. Unlike other language evnrionments, the CH language environment is very simple to setup. Check my Technical Support Notes on how to setup the client of the CH language environment for World-Wide Distributed Computing. If there is a system administrator in your organization, you may ask him to install the CH language environment for you. It shall take him less than 10 minuets to install it. If you are a Linuxer, install it by yourself.

When comparing different language environments, people often try to construct a simplest program to print out "Hello, world!" Here is a CH applet for such a beauty contest. It can be executed to print out this famous statement.

      Hello, world!
For your information, you may want to take a look at the equivalent hello-world applet written in Java by members of the Java development team. In CH, what you see is what you get. A CH applet is executed without compilation. In Java, that 9 lines hello-world Java program with object-oriented classes (not for average Joe to write and read) has to be compiled as a bytecode (like a machine code not for human being to read) before it can be treated as an applet for sophisticated integration with html files. Some differences between CH and Java from the internet computing point of view are highlighted.

Extensions to C for Writing Secure Applets

Many secure features have been built into the CH language environment to protect your system from hostile and accidental attack. For example, the C pointer declaration is disabled for applets obtained through the network for World-Wide Distributed Computing under a safe shell. If you run an applet with declaration of pointer, the execution of the network-downloaded program will fail. The following error message will be produced
      ERROR: pointer * is restricted in safe shell
For across-network computing, string is treated as a first-class object. You can run this applet with string data type to produce the following output
      Hello, world!
      I have just run the CH language environment.
      It is cool!
However, an applet can invoke other programs with C pointers located in a client computer. which will be described in the next section.

Fortran programmers without knowing C pointers will find that writing CH applets for World-Wide Distributed Computing is easy. This Fortran-style CH applet can be downloaded and executed on your local machine to produce the following output

      complex(26.117,-7.972)
Many people find computational arrays in CH are cool. Computational array is a first-class object in CH. Here is a CH program with computational arrays, the output
      A = 
      1.000 2.000 3.000 
      4.000 5.000 6.000 
      7.000 8.000 9.000 

      B = 
      1.000 2.000 3.000 

      transpose(A) = 
      1.000 4.000 7.000 
      2.000 5.000 8.000 
      3.000 6.000 9.000 

      A*B = 
      14.000 32.000 50.000 

      transpose(A)+2*inverse(A)*A = 
      3.000 4.000 7.000 
      2.000 22.000 8.000 
      3.000 6.000 11.000 
will be produced by executing it. All nice features in Fortran 90 will be available in the CH language environment. How can you pass results from a function without pointers in applets? Fortran programmers will say pass-by-reference. Yes! you can pass arguments of function by reference in CH. References in CH are C++ compatible. Try to run this C++ style applet with reference data type. The following output will be produced
      x=4,y=5
      x=5,y=4
The equivalent C version of the above C++ style applet cannot be executed across the network because of declaration of pointers.

Using Resources in a Client


Integration of CGI Scripts and Applets

To demonstrate the difference between the World-Wide Distributed Computing and Common Gateway Interface, run this CGI program written in CH. In Common Gateway Interface, when you click the highlighted word "run", the CH program is executed on the Web server, not on your client computer. But, in World-Wide Distributed Computing, when you click the highlighted word "run", the program is executed on your local machine. Take a look at the source code of this CGI program written in CH to see the difference. This simple example shows how an applet is created in the server and executed in a client machine.

Many interesting and exciting applications can be created using CGI and WWDC features in the CH language environment. Here is my Web Calculator. In this example, your input is processed by this CH CGI script with less than 50 lines of C code executed in the CH language envrionment. The CGI program dynamically creates a CH applet in the fly. This applet is then executed in your machine. Such an applet that is created and delivered on demand is called dynamic applet. The creation of dynamic applet is easy. In this Web Calculator example, the error message produced by the CGI script is sent as a html file, which is realized by producing the first line of output

     content-type: text/html
followed by a blank line. The first line of output from the CGI script
     content-type: application/x-ch
indicates that the output is the MIME type of CH dynamic applet. For example, when you input x with value 3 and expression of x*sin(2*x) into this Web Calculator, the following dynamic applet will be created by the CH CGI script and then executed in your local machine.
     #include<stdio.h>
     int main() {
       double x = 3;
       printf("x = %f, ", x);
       printf("x*sin(2*x) = %f\n", x*sin(2*x));
     }
The output from the above program is
     x = 3.000000, x*sin(2*x) = -0.838246
A program with similar functionalities may be implemented in C and X-Window alone with thousands lines of code. That is why CH is a very high-level language environment. Many applications can be accomplished in the CH language environment with a fraction of C code.

This Web Matrix Calculator will demonstrate the power of computational arrays in the CH language environment. For example, if you type in mathematical expression inverse(A)+2*tranpose(A), the Matrix Calculator will compute the sum of inverse of matrix A and produt of 2 by transpose of matrix A. Here is the CGI script that generates dynamic applet for this Web Matrix Calculator.

As another example, this Web Plotter can plot 2-dimensional and 3-dimensional graphs according to your input function. By default, the following dynamic applet will be executed in the fly in your local machine for a 3-dimensional graph. This picture will appear on your screen.

     #include<stdio.h>
     int main() {
        float data[1600][3], StepX, StepY, MinX, MaxX, MinY, MaxY, x, y, z;
        int pointsX, pointsY, i, j, k=0;
        MinX = 0.000000;
        MaxX = 6.283000;
        MinY = 0.000000;
        MaxY = 6.283000;
        pointsX = 40;
        pointsY = 40;
        StepX = (MaxX - MinX)/(pointsX-1);
        StepY = (MaxY - MinY)/(pointsY-1);
        for(i=0;i<pointsX;i++) {
           for(j=0;j<pointsY;j++,k++) {
              x = MinX + (i*StepX);
              y = MinY + (j*StepY);
              z = cos(x)*cos(y);
              data[k][0] = x;
              data[k][1] = y;
              data[k][2] = z;
           }
        }
        plotxyz(data, "Plot of z = cos(x)*cos(y)", "X", "Y", "Z");
     }

Integration of CCI Scripts and Applets

Common Client Interface (CCI) is a new experimental feature. This new feature allows the CH language environment to communicate with a Web browser such as Mosaic. In this scenario the Web browser is treated as a server, whereas the CH language environment for CCI is a client. As shown in the previous section, an applet can be created in the fly through Common Gateway Interface in a server and sent to a client and then executed. This applet can incorporate Common Client Interface. This allows the server to communicate with the Web browser which initiated the original request to the server. This can be demonstrated by an example of presentation of a slide show in your Web browser. To perform this demo, you have to start a Mosaic of version 2.5 or higher first. You may request slide show from Netscape Web browser, but, slide show will be presented in a Mosaic Web browser. Use the CCI option under the File menu in the upper left corner of Mosaic to instruct Mosaic to listen for CCI communication on a specified port number. A port number may be any number 1024 through 65535. Change the port number in the entry field below to agree with what Mosaic Web browser on your machine is listening for, if necessary.
Port #:
After you have started Mosaic(V2.5 or higher) in your local machine and set the port number that CCI is listening for, then click Start Slide Show, three slides will be presented in your Mosaic Web browser. The slide show applet is created by a CGI script running in a restricted mode. For example, if the port number that Mosaic is listening for is 8822 and your host name is local.host.ucdavis.edu, the following CH applet will be generated by this CGI script and executed in your local machine.
     int main() {
       string  slide[4] = {
         "http://iel.ucdavis.edu/",
         "http://iel.ucdavis.edu/CH/",
         "http://iel.ucdavis.edu/CH/tutor/wwdc/wwdc.html",
         NULL
       };
       string host_name = "local.host.ucdavis.edu";
       int port_num = 8822; 
       int show_time = 1;
       slides(slide, host_name, port_num, show_time);
     }
Function slides() is a function file distributed along with the CH language environment. You can find this function by typing
     which slides
in the CH shell.


Collection of CGI/CCI Scripts and Applets Presented in this Page

Applets

  1. Hello, world!
  2. Hello, world! and date.
  3. Applet with string data type.
  4. Fortran-style applet.
  5. Applet with computational array.
  6. C++-style applet with function pass by reference.
  7. Applet with declaration of pointer (failed).
  8. Applet with function pass by value of pointer (failed).

CGI Scripts

  1. Hello, world!

CGI/CCI Dynamic Applets

  1. "Hello, world" applet from CGI.
  2. Web Calculator.
  3. Web Matrix Calculator.
  4. Web Plotter.
  5. Slide Show.
    Port #:

NOTE: If you cannot run the applets described in this page, please come back to try these demos again after you have downloaded and installed the CH language environment, it will be much more fun. All programs for these demos are distributed along with the CH language environment. The potential and numerous exciting applications of World-Wide Distributed Computing in different fields are still to be explored. You can be one of pioneers in this information superhighway.


The CH language Ennvironment
Integration Engineering Laboratory
Created by Harry H. Cheng, 2/3/1996
Last modification by Harry H. Cheng, 3/10/1996