C programming basics

Gain prerequisite C skills for CUDA

Description

CUDA is available on C and Fortran. We select C. And so we need to brush up on our C skills.

Audience

You already know basic C. You need to gain advanced skills such as malloc().

Big Array - no pointers - no malloc

We allocate big arrays, intialize them, and print them out:

File link: ./prog01/prog01.c

We dial up the array size up to 6 before noticing the program crashed reporting the error: segmentation fault. Our limit is 100k.

Let's change the code to use pointers and see how far we can dial up our limit.

File link: ./prog02/prog02.c

With pointers there are no limits. It takes seconds to initialize and minutes to print out. We are being limited by processing speed power.

Actually, we do get limited by pointers but not by memory traversal, but by the buffer size of int itself. An int itself can only hold upto 1e9. At 1e10 the compiler returns the error: buffer overflow.

We can use a long instead of an int. That would overcome our buffer overflow error limiting factor. Then we find yes, even with pointers, there is a limit, we get error - segmentation fault with e10.

Summary

Our C programming big data limit is 1e9.