CPS615 - Fall 96 project -- Parallel Ray Tracing using HPF

Kayasidh Kasyapanun

Ray Tracing

In the real world, a point on a surface can be seen by an observer as a result of the interaction of the surface at that point with rays. There are many surface reflection model to simulate the illumination- reflection model in computer graphics. The Ray Tracing model is currently the most complete one. The difference of Ray Tracing from other model is the 'depth' to which interaction between light rays and objects in the scene is examined. There are also many disadvantages in Ray Tracing model. One of them is the processing overheads. Ray-traced images may take many minutes, hours or even days to cumpute. The significant advantage is that it combines several solutions for the global illumination problem.

Algorithm

At a given point in the image, the color and intensity are obtained by tracing the ray backward form the eye (viewpoint) of an observer through the point into the scene. If the ray intersects an object, then local color calculations will determine the color that is the result of direct illumination at that point. This is light from a light source. If the object is partially reflective, the color of the point should include a contribution from reflected rays. (There is also a transmitted ray but I did not implemented it) Determining a color of each ray may require the tracing furthur at other intersections. The number of the tracings can be limited by a specified number of recursion depth in recursive Ray Tracing algorithm. There are 3 main parts of the model that must be specified for the processing.
  1. Objects model, specified as quadratic coefficients and surface characteristics.
  2. Image plane, the plane that each ray will trace through.
  3. Eye, the observer view point.

Object model (data.image file)

The model must be specified in the file 'data.image' prior to the computation. There are some topics you must know to be able to specify the model correctly:

Using the program

This program takes a large amount of memory, the more number of objects and more recursion depth, the bigger the image size: these might take away all the memory from the machine. You will face the problem like 'core dump' or the program terminated when you run it because at that moment the system doesn't have enough memory to perform the computation. I recommend you to run and test on 32x32 or 64x64 subimage pixel size. If you run it from /scratch/kayasidh there will be the problem that you have to find where the output is put among 8 kestrels. I've tried to be specific on the directory where to put the output file but the system can not do it. Another problem for running on /scratch/kayasidh is you have to put the same copy of 'data.image' file on every nodes too.

The data (data.image)

32 32
256 256
300
0.0 0.0 300.0
1.0 1.0 1.0
0.0 0.0 2000.0
3
1.0 0.0 0.0 0.0 1.0 0.0 -50.0 1.0 0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 0.99 
5   
1.0 0.0 0.0 0.0 1.0 0.0 50.0 1.0 0.0 0.0 1.0 0.05 0.05 1.0 0.05 0.05 1.0 2
1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 -200.0 0.0 1.0 1.0 0.0 1.0 1.0 0.99 5
2 0.001 0.007

The first line is the size in pixel of the subimage, 32 by 32, must be integers. The second line is the size of the whole image (image plane), here I use 256 by 256, they must be integers too. The third line, the location of the image plane in z-axis. The image plane is parallel to the X-Y plane only. It must be an integer. The forth line, the location of the light source (this program can work with single light source only). They must be of type real. The fifth line, the color of the light source, here is white. The color must be specified in r g b with the range 0.0 - 1.0 The sixth line, the view point (an observer's eye). Type real. The seventh line, the number of objects following this line. Integer. The eight line and so on, each line for each object only and must not be wrapped up to another line.

    1.0 0.0 0.0 0.0 1.0 0.0 -50.0 1.0 0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 
0.99 5
    ^---------------------------------------^
      These 10 real numbers are coefficients of the quadratic formula
      representing the object.

    1.0 0.0 0.0 0.0 1.0 0.0 -50.0 1.0 0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 
0.99 5
                                              ^---------^
      These 3 real numbers are r g b components of ambient color.

    1.0 0.0 0.0 0.0 1.0 0.0 -50.0 1.0 0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 
0.99 5
                                                          ^---------^
      These 3 real numbers are r g b components of diffuse color.
    
    1.0 0.0 0.0 0.0 1.0 0.0 -50.0 1.0 0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 
0.99 5
                                                                      ^----^
      These 2 real numbers are specularity and power-of-cosine value
      for specular color.
The last line must not be changed. The 2 values are for the computation. They are a minimum value of dot product and minimum value of threshhold for the intersection. MUST NOT BE CHANGED. for experiment.

Performance and efficiency

TESTING FROM ~kayasidh/HPF_RAYTRACE/hpf_raytrace.exe. On kestrel, with one node, the biggest subimage to be able to compute at a time is about 32 by 32 to avoid the memory problem. So, if you want a 640 by 640 pixels image, the program has to do at least 20x20 = 400 loops. I've tested on multiple nodes, the biggest subimage is 64 by 64 (the next power-of-two size is 128 by 128 which is too much to be computed). The more number of nodes will give better performance for big image because if the image is small, some internal communication will take down the speedup of multiple nodes. This is why for some subimage size the computation times are fluctuated. I've tested with a 256 by 256 pixels running at 64 by 64 pixels subimage with 6 objects and 1 recursion, the result is as follow.
        1 node  : can not run because of not enough memory
        2 nodes : 119.5024 secs.        3rd
        4 nodes : 76.13430 secs.        2nd
        8 nodes : 56.33170 secs.        1st

    For the same problem with 32 by 32 subimage.

        1 node  : 94.88480 secs.        4th
        2 nodes : 63.19810 secs.        1st
        4 nodes : 84.13950 secs.        3rd
        8 nodes : 68.67850 secs.        2nd
    
    For 200 x 200 image, 50 x 50 subimage, 2 objects, 1 recursion.

        1 node  : 28.81670 secs         2nd
        2 nodes : 43.87050 secs.        4th
        4 nodes : 30.70290 secs.        3rd
        8 nodes : 25.88000 secs.        1st
        
    For 50 x 50 image, 50 x 50 subimage, 2 objects, 1 recursion.
        
        1 node  : 2.654500 secs.        4th
        2 nodes : 1.813900 secs.        3rd
        4 nodes : 1.797400 secs.        2nd
        8 nodes : 1.676900 secs.        1st
        
    For 64 x 64 image, 64 x 64 subimage, 2 objects, 1 recursion.
        
        1 node  : can not run
        2 nodes : 5.725200 secs.        3rd
        4 nodes : 3.429400 secs.        2nd
        8 nodes : 2.557300 secs.        1st.
These time are computation time only. I didn't include the time to read the 'data.image' input file and the time to write the output file because the more number of nodes, the slower the writing output file. I/O operations are inefficient on the parallel environment.

Instructions for compiling and running the code

I put all the files in subdirectory /scratch/kayasidh on every kestrel nodes but the most completed one is on kestrel1. The code MUST NOT be compiled from VPL.
  1. Compile the hpf_raytrace_type.f90 first (the module)
           f90 -wsf -c hpf_raytrace_type.f90
            this should take 15 seconds.
    
  2. Compile the hpf_raytrace.f90
            f90 -wsf -c hpf_raytrace.f90
            this will take around 15 minutes.
    
  3. Link both object files together
            f90 -o hpf_raytrace.exe hpf_raytrace.o hpf_raytrace_type.o
    
  4. Make sure the file 'data.image' is in the same directory as the executable file 'hpf_raytrace.exe'.
  5. Run:
            hpf_raytrace.exe -farm alphafarm -peers 8
                            or
            hpf_raytrace.exe -farm alphafarm -peers 4
                            or
            hpf_raytrace.exe -farm alphafarm -peers 2
                            or
            hpf_raytrace.exe -farm alphafarm -peers 1
    
            !!! beware of the size of the subimage !!!
            !!! The bigger subimage, the more memory is required.
            !!! WHEN you try to run it from /scratch/kayasidh/
            !!! directory, the 'data.image' file must be the same on 
            !!! every nodes.
    
  6. More instructions on running the code:

    The file 'data.image' contains the object models to be read by hpf_raytrace.exe program. It can be changed to make different ray traced image but make sure that you understand each value in that file. PLEASE READ THEM IN the file REPORT.raytrace.

    Output

    The output file is 'pic.raw' which is in raw format. You can convert this file to ppm format by rawtoppm pic.raw > pic.ppm where x and y are sizes in x and y dimension of the image 'pic.raw' Ex. rawtoppm 256 256 pic.raw > pic.ppm

    To view the ppm file (the quality of the image depends on the color depth of your system) xv pic.ppm If you run my program from /scratch/kayasidh the output file might be created on any kestrel machines depending on which nodes are selected to run.

    Source code and data