User Tools

Site Tools


guide:compiling

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
guide:compiling [2012/11/01 19:28]
kevin
guide:compiling [2021/12/09 16:42] (current)
Line 1: Line 1:
 ======Compiling====== ======Compiling======
 =====Compilers===== =====Compilers=====
-The following is a list of C, C++ and Fortran compilers available on the SUN cluster and the M9000+The following is a list of C, C++ and Fortran compilers available on the CHPC cluster: 
-====Sun Studio==== +====Intel==== 
-  * cc +  * ''icc'' (for C and C++) 
-  * CC +  * ''ifort'' 
-  * f90/f95 +====GNU Compiler Collection==== 
-====GNU==== +  * ''gcc'' 
-  * gcc +  * ''g++'' 
-  * g++ +  * ''gfortran''
-  * gfortran+
  
 =====Environment===== =====Environment=====
Line 16: Line 15:
   * Check which modules are available <code>module avail</code>   * Check which modules are available <code>module avail</code>
   * Add a module to the current environment <code>module add <module></code>   * Add a module to the current environment <code>module add <module></code>
-  * Remove a module from the environment <code>module remove <module></code>+  * Show loaded modules <code>module list</code> 
 +  * Remove a module from the environment <code>module remove <module></code> or <code>module rm <module></code> 
  
 =====Compiling===== =====Compiling=====
Line 28: Line 29:
     printf("Hello World");     printf("Hello World");
     return 0;     return 0;
 +}
 +</code>
 +===C with MPI===
 +<code c>
 +#include <stdlib.h>
 +#include <stdio.h>
 +#include <mpi.h>
 +
 +int
 +main(argc, argv)
 +
 +int                     argc;
 +char                    *argv[];
 +
 +{
 +        int             rank, size, len;
 +        char            name[MPI_MAX_PROCESSOR_NAME];
 +
 +        MPI_Init(&argc, &argv);
 +        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 +        MPI_Comm_size(MPI_COMM_WORLD, &size);
 +
 +        MPI_Get_processor_name(name, &len);
 +        printf ("Hello world! I'm %d of %d on %s\n", rank, size, name);
 +
 +        MPI_Finalize();
 +        exit(0);
 } }
 </code> </code>
Line 40: Line 68:
 ===C=== ===C===
 <code>gcc -o hello hello.c</code> <code>gcc -o hello hello.c</code>
 +===C with MPI===
 +<code>mpicc -o hello hello.c</code>
 +
 ===Fortran=== ===Fortran===
 <code>gfortran -o hello hello.f90</code> <code>gfortran -o hello hello.f90</code>
-====Sun Studio==== 
-The following code snippets demonstrate how to compile the above code examples use the Sun Studio compiler suite: 
-===C=== 
-<code>cc -fast -o hello hello.c</code> 
-===Fortran=== 
-<code>f90 -fast -o hello hello.f90</code> 
  
 =====OpenMP===== =====OpenMP=====
 The above compilers include support for OpenMP.  To compile an OpenMP code add the ''-fopenmp'' option.  For example: The above compilers include support for OpenMP.  To compile an OpenMP code add the ''-fopenmp'' option.  For example:
 <code>gcc -o mp_hello -fopenmp mp_hello.c</code> <code>gcc -o mp_hello -fopenmp mp_hello.c</code>
 +
 +code from https://computing.llnl.gov/tutorials/openMP/samples/C/omp_hello.c
 ====Intel Compilers==== ====Intel Compilers====
-The following code snippets demonstrate how to compile the OpenMP examples use the Intel compilers:+The following code snippets demonstrate how to compile OpenMP examples with the Intel compilers:
 ===C=== ===C===
-<code></code>+<code>icc -openmp omp_hello.c -o hello</code>
 ===Fortran=== ===Fortran===
-<code>f90 -fast -o hello hello.f90</code>+<code>ifort -openmp omp_hello.f -o hello</code>
  
 +===Java===
 +
 +An example of compiling and executing a simple Java program:
 +====MyFirstJavaProgram.java====
 +<code> 
 +public class MyFirstJavaProgram {
 +  public static void main(String []args) {
 +    System.out.println("Hello World"); // prints Hello World
 +  }
 +}
 +</code>
 +
 +To compile this, make sure you have the java module loaded, then:
 +<code>
 +javac MyFirstJavaProgram.java</code>
 +
 +A bytecode-compiled file should be created, named MyFirstJavaProgram.class
 +
 +To execute it, run as follows:
 +<code>
 +java MyFirstJavaProgram
 +</code>
 =====MPI===== =====MPI=====
-MPI is provided using the OpenMPI libraries.  To compile MPI code use the ''mpicc'' or ''mpif90'' compilers.+MPI (Message Passing Interface -- [[http://www.open-mpi.org]]) is provided using the OpenMPI libraries.  To compile MPI code use the ''mpicc'' or ''mpif90'' compilers.
  
-To run an MPI job see the [[guide:moab|Moab guide]].+To run an MPI job see the man pages for PBS ProOn the login node, type "man qsub". To obtain an interactive node, 
 +use ''qsub -I'' The login node prevents long-running processes therefore an interactive node is useful for compilations and builds. To test your code, load the module you want to use first, and then compile your code with it:
  
 +''$mpicc -o bin/test src/hello_world.c''
 +
 +To test it:
 +
 +<code>mpirun -np 8 bin/test</code>
 +
 +You should see something similar to:
 +<code>
 +Hello world! I'm 7 of 8 on cnode-2-6
 +Hello world! I'm 6 of 8 on cnode-2-6
 +Hello world! I'm 5 of 8 on cnode-2-6
 +Hello world! I'm 1 of 8 on cnode-2-6
 +Hello world! I'm 0 of 8 on cnode-2-6
 +Hello world! I'm 3 of 8 on cnode-2-6
 +Hello world! I'm 2 of 8 on cnode-2-6
 +Hello world! I'm 4 of 8 on cnode-2-6
 +</code>
/app/dokuwiki/data/attic/guide/compiling.1351790890.txt.gz · Last modified: 2021/12/09 16:42 (external edit)