| | 1 | = C Codes = |
| | 2 | |
| | 3 | == Hello World == |
| | 4 | {{{ |
| | 5 | /* hello.c: display a message on the screen */ |
| | 6 | |
| | 7 | #include <stdio.h> |
| | 8 | |
| | 9 | int main(){ |
| | 10 | printf("hello, C world\n"); |
| | 11 | return 0; |
| | 12 | } |
| | 13 | |
| | 14 | }}} |
| | 15 | * Text between /* and */ are comments. |
| | 16 | * '''#include <stdio.h>''' to load the header file. |
| | 17 | * There are many header files in the standard C library. http://en.wikipedia.org/wiki/C_standard_library |
| | 18 | * Program always begins with '''main()''' function. |
| | 19 | * '''main()''' returns a integer. |
| | 20 | |
| | 21 | === Compile with GNU C === |
| | 22 | {{{[tulaneID@cypress1 ~]$ gcc hello.c}}} |
| | 23 | |
| | 24 | === Compile with Intel C === |
| | 25 | {{{[tulaneID@cypress1 ~]$ icc hello.c}}} |
| | 26 | |
| | 27 | == Links for Tutorial == |
| | 28 | * [[http://en.wikibooks.org/wiki/C_Programming | wikibooks ]] |
| | 29 | |
| | 30 | == Examples of Jobscript == |
| | 31 | |
| | 32 | {{{#!sh |
| | 33 | #!/bin/bash |
| | 34 | #SBATCH --job-name=HelloC |
| | 35 | #SBATCH --qos=normal |
| | 36 | #SBATCH --time=0-00:10:00 ### Wall clock time limit in Days-HH:MM:SS |
| | 37 | #SBATCH --nodes=1 ### Node count required for the job |
| | 38 | #SBATCH --ntasks-per-node=1 ### Nuber of tasks to be launched per Node |
| | 39 | |
| | 40 | echo Start Job |
| | 41 | pwd |
| | 42 | |
| | 43 | cat $SLURM_JOB_NODELIST |
| | 44 | |
| | 45 | ./a.out |
| | 46 | |
| | 47 | echo End job |
| | 48 | }}} |
| | 49 | |
| | 50 | == Parallel C == |
| | 51 | * [[cypress/Programming/Cexamples/OpenMp|OpenMP examples in C]] |
| | 52 | * [[cypress/Programming/Cexamples/Mpi|MPI examples in C]] |
| | 53 | |
| | 54 | == More Examples == |
| | 55 | * Approximate Pi |
| | 56 | * !Heat/Mass Transfer |
| | 57 | * Stokes Flow In a Cavity |
| | 58 | * Particle Strength Exchange Method |