CS 214 Project 12 (Extra Credit): Multicore Computing


The ability to process triangles quickly is important in computer graphics, since complex 3D objects are typically drawn as a collection of small triangles. The surface area of a 3D object can be approximated by summing the surface areas of all the triangles used to define it.

For a triangle with edge-lengths a, b, and c, the area of the triangle can be computed using Heron's Formula:

   area = sqrt(p * (p-a) * (p-b) * (p-c) )
where p is half the triangle's perimeter: (a+b+c)/2.

The directory

   /home/cs/214/projects/12/numbers/
contains input files (e.g., 5triangles.txt, 1000000triangles.txt) that have the following format: This exercise is to write programs that behave as follows:
  1. Check the command-line to make certain the user specified at least one argument.
  2. Open up an input file whose name is given on the command-line.
  3. Read the first line from the file to determine N, the number of triangles.
  4. Allocate 3 arrays--a, b, and c--each with space for N real values.
  5. Fill the a, b, and c arrays with values from the input file, such that for a given index i, a[i], b[i], and c[i] contain the edge-lengths for triangle i.
  6. Close the input file.
  7. Start timing.
  8. Compute totalArea, the sum of the areas of the triangles defined by the a, b, and c arrays. To do this, for each of the N triangles defined by a[i], b[i], c[i], you will need to compute the area of that triangle and then add it to totalArea.
  9. Stop timing.
  10. Display totalArea and how long it took to compute.

This exercise is to solve this problem in each of our four languages, using multithreading to compute totalArea as quickly as you can in each language, using your programs from Lab 12 as models.

Start by writing a version of each program that solves the problem sequentially. When you have it debugged, "parallelize" step 8 of that program using an approach similar to what we did in the lab.

Testing. The directory /home/cs/214/projects/12/numbers/ contains a file 5triangles.txt that you can use to test your programs.

Due Date: April 20. Turn in as much as you have completed by 11:59pm. No submissions of any labs or projects will be accepted after that, to give the graders time to grade before final exams begin.

Turn in. Using an approach like what we did in the lab, make a single script file named proj12-results, in which you list each program, show that it builds without any syntax errors or warnings, and demonstrate that it correctly processes the 'triangles' in the file /home/cs/214/projects/12/numbers/1000000triangles.txt, using 1 thread and 4 threads. Then submit your project by copying that single script file into your personal folder in /home/cs/214/current/:

   cp proj12-results /home/cs/214/current/yourUserName
replacing yourUserName with your login name. The grader will access and grade your project results from there, using the criteria from this grade sheet.


Calvin > CS > 214 > Projects > 12


This page maintained by Joel Adams.