Basic example: Creating and running “Hello World”

  1. Create the following C program and name the source file hello.c:
    #include <stdio.h>
    int main(void)
    {
       printf("Hello World!\n");
       return 0;
    }
  2. Compile the program:

    • If Blue Gene/L™ short invocation commands have been set up, enter the following command:
       blrts_xlc hello.c -o hello
      If short invocation commands have not been set up, enter the following command:
       /opt/ibmcmp/vacpp/bg/9.0/bin/blrts_xlc hello.c -o hello
    • If Blue Gene/P™ short invocation commands have been set up, enter the following command:
       bgxlc hello.c -o hello
      If short invocation commands have not been set up, enter the following command:
       /opt/ibmcmp/vacpp/bg/9.0/bin/bgxlc hello.c -o hello
  3. Run the program by entering the following command:
      ./hello

    The result should be "Hello World!".

  4. Check the exit code of the program by entering the following command:
      echo $?

    The result should be 0.

  5. Create the following C++ program and name the source file hello.cpp:
    #include <iostream>
    int main()
    {
       std::cout << "Hello World!" << std::endl;
       return 0;
    }
  6. Compile the program:

    • If Blue Gene/L short invocation commands have been set up, enter the following command:
       blrts_xlc++ hello.cpp -o hello
      If short invocation commands have not been set up, enter the following command:
       /opt/ibmcmp/vacpp/bg/9.0/bin/blrts_xlc++ hello.cpp -o hello
    • If Blue Gene/P short invocation commands have been set up, enter the following command:
       bgxlc++ hello.cpp -o hello
      If short invocation commands have not been set up, enter the following command:
       /opt/ibmcmp/vacpp/bg/9.0/bin/bgxlc++ hello.cpp -o hello
  7. Run the program:
      ./hello

    The result should be "Hello World!".

  8. Check the exit code of the program:
      echo $?

    The result should be “0”.