Why C++? Why not Java?
Because
Java has become the standard teaching language, it would
seem sensible that this introductory text would write code in
Java.
However, there is no Java-MPI standard, so most people do not use Java
when running programs under MPI.
Although C and C++ have their share of teaching barriers, simple C/C++
programs, when compared to Java, are pleasantly
similar.
This is particularly true when, as in Supercomputing
Simplified, the housekeeping aspects of C/C++ are already laid out and
can be copied by the beginning programmer.
Java vs. C++: A Comparison
Below are two programs comparing C/C++ to Java:
Hello World
These programs screen print the string: "Hello world!" and give a carriage return
| In Java | In C++ |
|
public class Hello { public
static void main(String [] args) { |
int
main() |
Factorial Generation
These programs generate and print, one value per line, the factorials of 1 through 7.
| In Java | In C++ |
public
class Factorial { |
#include
<iostream.h> |
Summing Variable Number of Addends
These programs prompt the user for number of entries to be summed.
| In Java | In C++ |
import java.util.*; public
class SumFun { System.out.print( "How many numbers are there? " ); Scanner
keyboard = new Scanner( System.in );
for (int i=0; i
< n; i++ ) { |
#include <iostream.h>
int main() { printf("Enter %i numbers : \n",n); sum = sum + currentNum;
printf("The sum of your numbers is %i \n",sum); |