From charlesreid1

No edit summary
No edit summary
Line 11: Line 11:


To run it:
To run it:
<syntaxhighlight lang="bash">
<source lang="bash">
$ chmod +x HelloWorld.sh
$ chmod +x HelloWorld.sh
$ ./HelloWorld.sh
$ ./HelloWorld.sh
</syntaxhighlight>
</source>
 
=C=
 
=C with MPI=
 
<source>
#include <stdio.h>
#include <mpi.h>
 
 
int main (argc, argv)
    int argc;
    char *argv[];
{
  int rank, size;
 
  MPI_Init (&argc, &argv); /* starts MPI */
  MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */
  MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */
  printf( "Hello world from process %d of %d\n", rank, size );
  MPI_Finalize();
  return 0;
}
</source>
 
And to compile:
 
<source lang="bash">
$ mpicc hello.c -o hello.o
 
$ ./hello.o
</source>


= C++ =
= C++ =
Line 21: Line 53:


HelloWorld.cc:
HelloWorld.cc:
<syntaxhighlight lang="cpp">
<source lang="cpp">
#include <iostream>
#include <iostream>
   
   
Line 28: Line 60:
     std::cout << "Hello, world! This is C++.\n";
     std::cout << "Hello, world! This is C++.\n";
}
}
</syntaxhighlight>
</source>


To run it:
To run it:
<syntaxhighlight lang="bash">
<source lang="bash">
$ g++ HelloWorld.cc -o hello.x
$ g++ HelloWorld.cc -o hello.x
$ ./hello.x
$ ./hello.x
</syntaxhighlight>
</source>
 
=C++ with MPI=
 
A simple hello world example in [[C++]] with [[MPI]]:
 
<source lang="cpp">
#include <iostream>
#include <cstdlib> // has exit(), etc.
#include <mpi++.h> // MPI header file
 
int main(int argc, char *argv[]) {
 
  // initialize for MPI (should come before any other calls to
  //    MPI routines)
  MPI::Init(argc, argv);
 
  // get number of processes
  int nprocs = MPI::COMM_WORLD.Get_size();
 
  // get this process's number (ranges from 0 to nprocs - 1)
  int myid = MPI::COMM_WORLD.Get_rank();
 
  // print a greeting
  cout << "hello from process " << myid << " of " << nprocs << endl;
 
  // clean up for MPI
  MPI::Finalize();
 
  return EXIT_SUCCESS;
}
 
</source>
 
To compile and run it:
 
<source lang="bash">
$ mpic++ hello.cpp -o hello.o
 
$ ./hello.o
</source>
 
* http://www.cs.trinity.edu/~bmassing/Classes/CS3366_2002spring/SamplePrograms/index.html


= PHP =
= PHP =
Line 41: Line 115:


HelloWorld.php:
HelloWorld.php:
<syntaxhighlight lang="php">
<source lang="php">
<html>
<html>
<body>
<body>
Line 54: Line 128:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
$ php HelloWorld.php
$ php HelloWorld.php
</syntaxhighlight>
</source>


Alternatively, if you are running a local apache server and have PHP enabled, you can put HelloWorld.php into your web documents directory, and then point you web browser to <code>http://localhost/HelloWorld.php</code>.
Alternatively, if you are running a local apache server and have PHP enabled, you can put HelloWorld.php into your web documents directory, and then point you web browser to <code>http://localhost/HelloWorld.php</code>.

Revision as of 16:20, 28 May 2011

Bash

A simple hello world example using Bash.

HelloWorld.sh:

#!bin/sh

echo "Hello world!"

To run it:

$ chmod +x HelloWorld.sh
$ ./HelloWorld.sh

C

C with MPI

#include <stdio.h>
#include <mpi.h>


int main (argc, argv)
     int argc;
     char *argv[];
{
  int rank, size;

  MPI_Init (&argc, &argv);	/* starts MPI */
  MPI_Comm_rank (MPI_COMM_WORLD, &rank);	/* get current process id */
  MPI_Comm_size (MPI_COMM_WORLD, &size);	/* get number of processes */
  printf( "Hello world from process %d of %d\n", rank, size );
  MPI_Finalize();
  return 0;
}

And to compile:

$ mpicc hello.c -o hello.o

$ ./hello.o

C++

A simple hello world example in C++.

HelloWorld.cc:

#include <iostream>
 
int main()
{
     std::cout << "Hello, world! This is C++.\n";
}

To run it:

$ g++ HelloWorld.cc -o hello.x
$ ./hello.x

C++ with MPI

A simple hello world example in C++ with MPI:

#include <iostream>
#include <cstdlib>		// has exit(), etc.
#include <mpi++.h>		// MPI header file

int main(int argc, char *argv[]) {

  // initialize for MPI (should come before any other calls to
  //     MPI routines)
  MPI::Init(argc, argv);

  // get number of processes
  int nprocs = MPI::COMM_WORLD.Get_size();

  // get this process's number (ranges from 0 to nprocs - 1)
  int myid = MPI::COMM_WORLD.Get_rank();

  // print a greeting
  cout << "hello from process " << myid << " of " << nprocs << endl;

  // clean up for MPI 
  MPI::Finalize();

  return EXIT_SUCCESS;
}

To compile and run it:

$ mpic++ hello.cpp -o hello.o

$ ./hello.o

PHP

A simple hello world example using PHP.

HelloWorld.php:

<html>
<body>
<?php
echo "Hello world!";
?>
</body>
</html>
</syntaxhighlight>

To run HelloWorld.php:
<syntaxhighlight lang="bash">
$ php HelloWorld.php

Alternatively, if you are running a local apache server and have PHP enabled, you can put HelloWorld.php into your web documents directory, and then point you web browser to http://localhost/HelloWorld.php.

Python

A simple hello world example using Python.

HelloWorld.py:

 print "Hello, World!"

To run it:

$ python HelloWorld.py

Alternatively:

$ python -c "print 'Hello World! \n'"