0

This is with ref to the code http://wind.d.umn.edu/acmclub/sites/default/files/summation.cu provided at http://wind.d.umn.edu/acmclub/?q=node/12 Im a beginner programmer but still I could follow the code and explanation except for few things.

1.] What is the meaning of "new" in this line taken from summation.cu

sum_h = new unsigned long();

2.]Also I really couldnt understand this code. What purpuse does strtoul serve ? I'd be thankful if you could point to some beginners resource on "new" & "strtoul"

n = strtoul(argv[1], NULL, 0);

3.] Is the code "summation.cu" written completely in C++. So inorder to code CUDA programs do I need to learn C++ instead of C? Or do I need to learn both C & C++ ?

vinita
  • 595
  • 1
  • 9
  • 24

2 Answers2

2

To make it short:

  1. new allocates memory (e.g. for the sum) (see details)
  2. strtoul converts a string to a long (see details)
  3. I think you should start with a good C++ book (e.g. C++ Primer) and learn some C later (e.g. from this book). After that I would start with CUDA.

Keep your chin up.

Community
  • 1
  • 1
Jost
  • 1,549
  • 12
  • 18
  • Thanks!!! BTW I already have finished python, so can I code for CUDA in python rather than going for C/C++. If not ,then as suggested by you I'll start with C++ rather than C . – vinita Aug 27 '13 at 06:04
  • @vinita CUDA in python - never thought about that - sounds cool, I'll have a look at it - thx – Jost Aug 27 '13 at 06:13
  • Yeah there's something called PYCUDA. – vinita Aug 27 '13 at 11:06
1
  1. As Saviour Self pointed out in the comments - new means dynamic memory allocation on the heap at runtime. More information here.
  2. I think this is pretty much similar to the C-function atoi that converts a number stored as a char into a integer. In you case this should convert the number (stored as char) in argv[1] into a unsigned long int. Check it here.
  3. The language used in CUDA is called "C for CUDA" and as long as I've been reading and learning you can code in C but there are many features of C++ that are also supported. You can start taking a look at CUDA DOCUMENTATION.

Hope this helps.

BRabbit27
  • 6,333
  • 17
  • 90
  • 161
  • 1
    `new` meaning dynamic memory allocation on the heap at runtime. More information here: http://www.tutorialspoint.com/cplusplus/cpp_dynamic_memory.htm – Clark Kent Aug 22 '13 at 12:27
  • @SaviourSelf that's more than correct. I'll edit the post. Thanks for the reference. – BRabbit27 Aug 22 '13 at 12:32