Compiling and Running C Code on Odyssey
There are a number of C compilers on Odyssey. The default GNU compiler are the of the version 4.1.2. To use these simply type gcc.
[hptc@iliadaccess02 simplehello]$ gcc --version
gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
In addition Odyssey has the GNU compiler suite version 4.3.3
[hptc@iliadaccess02 simplehello]$ module load hpc/gcc-4.3.3
Loading module hpc/gcc-4.3.3.
[hptc@iliadaccess02 simplehello]$ gcc --version
gcc (GCC) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Additionally Odyssey has a number of Intel compiler versions:
- hpc/intel-10.1.018
- hpc/intel-11.0.081
- hpc/intel-11.0.083
- devel/intel-11.1.046
Please read the documentation on modules for more information.
Take the following simple C example:
[hptc@iliadaccess02 simplehello]$ cat simplehello.c
#include#include #include int main(int argc, char *argv[])
{
char hostname[HOST_NAME_MAX];
gethostname(hostname, HOST_NAME_MAX);
fprintf(stdout, "Hello from %sn", hostname);
return 0;
}
This can be compiled using the following Makefile:
[hptc@iliadaccess02 simplehello]$ cat Makefile
CC=gcc
CFLAGS=-g
LIBS=-lm
RM=/bin/rm
EXECS = simplehello
OBJS = simplehello.o
all: $(EXECS)
$(EXECS): $(OBJS) Makefile
$(CC) $(CFLAGS) -o $(EXECS) $(OBJS) $(LIBS)
$(OBJS): Makefile
.c.o:
$(CC) $(CFLAGS) -o $*.o -c $*.c
clean:
$(RM) -f $(EXECS) $(OBJS) gmon.out *~ *.o *.oo
Replace gcc above with icc (after loading the appropriate Intel module) to use Intel C compilers.
Submit the job using the LSF script:
[hptc@iliadaccess02 simplehello]$ cat hello.bsub
#!/bin/sh
#BSUB -u hptc@harvard.edu
#BSUB -J hello_world
#BSUB -o hello_lsf.out
#BSUB -e hello_lsf.err
#BSUB -n 1
#BSUB -q short_serial
./simplehello
To debug this code using GDB use:
[hptc@iliadaccess02 simplehello]$ bsub -Is -q interact /bin/bash
Job <599650> is submitted to queue.
<< Waiting for dispatch ... >> << Starting on heroint1 >> [hptc@heroint1 simplehello]$ gdb simplehello
GNU gdb Red Hat Linux (6.5-25.el5rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu"...Using host libthread_db library "/lib64/libthread_db.so.1".
(gdb) r
Starting program: /n/home12/hptc/simplehello/simplehello
Hello from heroint1.rc.fas.harvard.edu
Program exited normally.
(gdb) quit
[hptc@heroint1 simplehello]$ exit
exit
[hptc@iliadaccess02 simplehello]$
Please read the documentation on LSF for more information.
