Virginia Tech
Advanced Research Computing
  • Home
  • About ARC@VT
    • Leadership & Staff
    • Events
    • Press Room
    • Featured Links
    • Contact Us
  • Research
  • Services & Support
    • User Accounts
    • Training
    • Documentation
    • Facility Tours
    • Help - Support Requests
  • Systems & Resources
    • System X
    • SGI Systems
    • Sun Systems
    • Visualization
  • Application Software
  • Web Site Map


C Programs
Hello_World_C.c

Fortran Programs
Hello_World_Fortran.f90

"Hello World!" Code Examples

Hello_World_C.c

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

main (int argc, char **argv)
{
 int node;

 MPI_Init(&argc, &argv);
 MPI_Comm_rank(MPI_COMM_WORLD, &node);

 if (node == 0) {
 printf("Rank 0 is present in C version of Hello World.\n");
 } else {
 printf("  Rank %d of C version says: Hello world!\n", node);
 }

 MPI_Finalize();
}

Hello_World_Fortran.f90

PROGRAM Hello_World_Fortran

IMPLICIT NONE
INCLUDE 'mpif.h'

INTEGER :: ierr_p, rank_p, size_p
INTEGER :: status_p(MPI_STATUS_SIZE)

CALL MPI_INIT(ierr_p)
CALL MPI_COMM_RANK(MPI_COMM_WORLD, rank_p, ierr_p)
CALL MPI_COMM_SIZE(MPI_COMM_WORLD, size_p, ierr_p)

IF (rank_p==0) THEN
WRITE(*,*) 'Rank 0 is present in Fortran version of Hello World.'
ELSE
WRITE(*,*) 'Fortran version of Hello World, rank ', rank_p
END IF

CALL MPI_FINALIZE(ierr_p)

END PROGRAM Hello_World_Fortran



VT-ARC Privacy Statement | Contact Us
VT-ARC is a Unit within the Office of the Vice President of Information Technology
© 2007-2008 Virginia Polytechnic Institute and State University
Principles of Community | Acceptable Use Policy | Accessibility | Equal Opportunity
Website Feedback   -   Page Last Updated:  January 28th, 2008