CS542200 – Solved

$ 29.99


GCC family
– gcc
– g++
LLVM/Clang family
– clang
– clang++
GCC vs Clang
– They have mostly the same usage
– Flags (options) supported on one should mostly work out-of-the-box on the other
– Initially Clang put a lot of effort on providing better error messages, and but now GCC has catched on
– We suggest trying to use Clang if you cannot understand GCC’s error messages, and vice versa.
– Also they sometimes produce faster executables than each other.
MPI Compiler Wrapper
mpicc calls gcc under the hood mpicxx calls g++ under the hood
To use mpicc with clang, call mpicc -cc=clang
To use mpicxx with clang++, call mpicxx -cxx=clang++
GCC/Clang optimization flags
● -O2
Turns on most optimizations
● -O3
Turns on all optimizations in -O2, plus optimizations that trade off code size for execution time https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
GCC/Clang other flags
● -lXXX
Link the XXX library.
For example, -lm links the math library libm.so mpicc automatically adds -lmpi for you
● -o XXX
Set the output executable filename to XXX
● -g
Generate debug information

Makefile: a very brief introduction
Used to tell the make command how to build executables from sources.
– We acknowledge make is not a good build system
– But it’s most commonly used / known
– So as an unfortunate outcome, we still use Makefiles
– We ask you to submit Makefiles in homeworks because we encourage you to try different compiler options

– Makefile rule formattarget: requirements command
– .PHONY : specify phony target
$ make (= make all) gcc -o hello -O3 hello.c gcc -o world -O3 world.c
$ make clean rm -f hello world
.PHONY: all all: hello world
hello: hello.c gcc -o hello -O3 hello.c
world: world.c gcc -o world -O3 world.c
.PHONY: clean clean:
rm -f hello world
– Variable
– % : stem part
– $@ : the target
– $^ : all requirements
– $< : the first requirement
TARGETS = hello world
.PHONY: all all: $(TARGETS)
%: %.c gcc -o $@ -O3 $<
.PHONY: clean clean:
rm -f $(TARGETS)

CC = gcc
TARGETS = hello world
.PHONY: all all: $(TARGETS)
%: %.c
$(CC) -o $@ $(CFLAGS) $<
.PHONY: clean clean:
rm -f $(TARGETS)
CC = gcc
TARGETS = hello world
.PHONY: all all: $(TARGETS)
.PHONY: clean clean:
rm -f $(TARGETS)

Debugging Tools
– Turn on compiler warnings
– AddressSanitizer
– Clang static analyzer
– Study by yourself
– gdb
– Using this in parallel environments is super complex so we’re not going to cover it
Turn on compiler warnings
Just add -Wall to the list of compiler flags
Compiler warnings off vs on

Asks the compiler to inject code to check memory access during execution.
Add -fsanitize=address -g to the compiler. Then run your code as usual. Asan will crash your program if something wrong happened.
AddressSanitizer works with either GCC or Clang.
Enabling Asan would harm performance! Only use it for debugging, don’t submit your code with Asan enabled.

Study by yourself
Clang static analyzer
Perform more complex compile-time static analysis than -Wall
Clang static analyzer: usage
Use one of the following 1. Compile with clang –analyze
2. Use scan-build -o outputpath make instead of make Then, you can either:
1. Run scan-view –host –allow-all-host outputpath/XXX
2. Or download outputpath/XXX and view locally


There are no reviews yet.

Be the first to review “CS542200 – Solved”

Your email address will not be published. Required fields are marked *