From charlesreid1

(Created page with "= C++ = <syntaxhighlight lang="c++"> #include <iostream> int main() { std::cout << "Hello, world! This is C++.\n"; } </syntaxhighlight>")
 
 
(27 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Bash =
A simple hello world example using [[Bash]].
HelloWorld.sh:
<pre>
#!bin/sh
echo "Hello world!"
</pre>
To run it:
<pre>
$ chmod +x HelloWorld.sh
$ ./HelloWorld.sh
</pre>
=C=
=C with MPI=
<pre>
#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
$ mpirun -np 4 ./hello.o # or whatever your MPI's command line cup of tea is
</pre>
= C++ =
= C++ =


<syntaxhighlight lang="c++">
A simple hello world example in [[C++]].
 
HelloWorld.cc:
 
<pre>
#include <iostream>
#include <iostream>
   
   
Line 8: Line 64:
     std::cout << "Hello, world! This is C++.\n";
     std::cout << "Hello, world! This is C++.\n";
}
}
</syntaxhighlight>
</pre>
 
To run it:
 
<pre>
$ g++ HelloWorld.cc -o hello.x
$ ./hello.x
</pre>
 
=C++ with MPI=
 
A simple hello world example in [[C++]] with [[MPI]]:
 
<pre>
#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;
}
 
</pre>
 
To compile and run it:
 
<pre>
$ mpic++ hello.cpp -o hello.o
 
$ mpirun -np 4 ./hello.o
</pre>
 
* http://www.cs.trinity.edu/~bmassing/Classes/CS3366_2002spring/SamplePrograms/index.html
 
= PHP =
 
A simple hello world example using [[PHP]].
 
HelloWorld.php:
 
<pre>
<html>
<body>
<?php
echo "Hello world!";
?>
</body>
</html>
</pre>
 
To run HelloWorld.php:
 
<pre>
$ php HelloWorld.php
</pre>
 
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>.
 
If you need help understanding how to do that, check out [[Apache|my page on building and running Apache]]. If you need help translating that into human-speak, [http://lifehacker.com/124212/geek-to-live--how-to-set-up-a-personal-home-web-server Lifehacker has a really great article explaining how to set up a web server on your machine].
 
= Python =
 
A simple hello world example using [[Python]].
 
HelloWorld.py:
 
<pre>
print "Hello, World!"
</pre>
 
To run it:
 
<pre>
$ python HelloWorld.py
</pre>
 
Alternatively:
 
<pre>
$ python -c "print 'Hello World! \n'"
</pre>
 
 
 
 
{{Languages}}
[[Category:MPI]]
[[Category:C++]]
[[Category:Python]]

Latest revision as of 01:00, 10 October 2017

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;
}
</source>

And to compile:

<source lang="bash">
$ mpicc hello.c -o hello.o

$ mpirun -np 4 ./hello.o # or whatever your MPI's command line cup of tea is

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

$ mpirun -np 4 ./hello.o

PHP

A simple hello world example using PHP.

HelloWorld.php:

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

To run HelloWorld.php:

$ 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.

If you need help understanding how to do that, check out my page on building and running Apache. If you need help translating that into human-speak, Lifehacker has a really great article explaining how to set up a web server on your machine.

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'"