CS 370 Homework 1
1. Homework 1: Programming Multiprocessors to Perform Massive Complex Math Fast
Your company is interested in entering a business that requires a lot of fast mathematical operations. The operations need to be done VERY FAST. You purchased a multiprocessor machine. You want to take advantage of the multiple processors when calculating complex operations. To accomplish this, you need to use multiple threads and have them run simultaneously.
You suspect that some programming languages may be faster than others. You know that C# has a nice user interface, but frankly, the speed is most important. You have been asked to compare processing time using Threads for Java and C#, and processes with C++. Which language can do this better, faster?
Your boss has asked you to write up a lab report that he will disperse to a number of senior and junior technical staff members. This is your chance to be noticed by some people who you have never met but hope to. Be sure to write it well AND professionally. First impressions are extremely important to keep getting the interesting jobs flowing your way.
Calculating root values is an excellent example of lengthy math operations. Start with the root of 1 and proceed upwards until you have successfully understood all issues. You need to be able to print 4 root values per line. Below I show an example with 3 per line, since 3 fit on this page. The T0 or T2 indicate that Thread 0 or Thread 2 did the calculation, respectively. V5546 indicates that the root of 5546 is = 74.464…
T0:V5545=74.4647567645259 T0:V5546=74.4714710476435 T0:V5547=74.4781847254617
T0:V5548=74.4848977981443 T1:V5549=74.4916102658548 T1:V5550=74.4983221287567
T0:V5551=74.5050333870135 T1:V5552=74.5117440407886 T1:V5553=74.5184540902453
T0:V5554=74.5251635355468 T1:V5555=74.5318723768563 T0:V5556=74.5385806143369
…
T2:V9745=98.7167665596883 T2:V9746=98.7218314254755 T2:V9747=98.726896031426
T2:V9748=98.7319603775799 T2:V9749=98.737024463977 T2:V9750=98.7420882906575
T2:V9751=98.7471518576612 T2:V9752=98.7522151650281 T2:V9753=98.7572782127981
You have heard that a ‘job jar’ approach can allocate jobs to different threads/processes. With the ‘job jar’ approach, each thread grabs a job out of the job jar, completes it, and grabs for the next job. Meanwhile, other threads are simultaneously grabbing numbers from the same job jar. For example, with this program an incrementing count will serve as a job jar. Threads grab a number and increment a count and calculate a root number. But you wonder whether threads may grab the same number from the job jar simultaneously.
The questions that you need to answer in your lab report include:
1) Which programming language is the fastest to run?
2) Implementation details: How can you successfully program this? What do you need to do to get exactly 4 operations printer per row, with each root number printed exactly once? Why did other approaches not work? Which languages didn’t work and why (given the information provided in class)?
3) If you calculate all roots but only print out the last, is there a difference in speeds of the compilers? Why do you think this happens?
The senior staff members are interested in the first question, while the junior staff members are interested in the second question. (Your boss/instructor is interested in both.)
Write up your report in Lab Report format (shown on another web page.)
Hints:
For C++, use the function:
#include <math.h>
double result = sqrt(doubleVar);
Probably the easiest way to calculate time would be to execute a file:
$ time <C++executable>
$ time java <file.java>
The output should specify:
Real: Total wall-clock time
User: Application Program time
System: Time spent in operating system
For C#, use the function:
double root = Math.Sqrt(double);
For timing use the Syntax:
Console.WriteLine(“Start Time: “+DateTime.Now+“:”+DateTime.Now.Millisecond);
Console.WriteLine(“End Time: “+DateTime.Now+“:”+DateTime.Now.Millisecond);
View Console printing by running using Debug->Start Debugging.
If you have problems, come see me!