Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Sunday, 11 November 2012

How To Become A Programmer!

I know that this is a topic that has been covered in quite a few blogs, forums, books etc. etc. but it's a topic that I have been repeatedly asked this question via message on my youtube channel and I've decided that I'm sick of rewriting my answer every time. Wouldn't it be nice to have a list of recommendations on how to start programming? I know that I was very unsure when I started programming, in terms of what language, what IDE, should I learn from a book or the internet and so on. I've been programming for around 9 years now and I like to think that I'm pretty decent at it. I'm also a teaching assistant at QUB so I have some experience with helping beginning programmers. This is a set of recommendations about how to become a competent programmer. Enjoy!!

Pick a language

This is easier said than done and sometimes depends on what you hope to accomplish. The most common languages that are used in the software development industry are C# and Java. In QUB they use Java as a teaching language, I don't personally think that this is the best way to become a good programmer. The problem  with Java (and C# for that matter) as a learning language is that it comes with a huge standard library, when you start programming you do not need these libraries as they are essentially non-transferable skills, they are specific to that language. I always follow the tenant that structure is the most important part of learning programming not the syntax of a specific language. For these reasons I think the best language to learn in is C, since many modern programming languages are based on C the syntax is transferable. Since C is a language with a very basic standard library it forces you to learn more about the implementation of very useful algorithms (searching, sorting, etc.).

In my opinion the best book for learning C is:
The C Programming Language by Brian W. Kernighan and Dennis Ritchie - This is not a book that will teach you programming methodology but it is the definitive guide for the C language syntax

Pick a development environment (IDE)

Integrated development environments (IDEs) are the easiest way to begin programming, they're generally composed of a text editor and a set of tools for developing programs. The IDE that you will use is really dependent on what language you want to learn but I've included a list of common and popular IDEs and the languages they are used for.
  • Netbeans - Free IDE that can be used for a variety of languages but mainly for Java but I've also used it for C and C++. This is available for all popular operating systems.
  • Eclipse - Probably the most popular Java IDE freely available, can also be used for other languages. Includes very good refactoring tools. Available on all popular operating systems.
  • Visual Studio - This is Microsoft's IDE, it's pretty much the best choice if you plan to do any C# development. Although its a commercial package there is a free option available i.e. Visual C# Express Edition. This is only available on Windows operating systems.
  • Xcode - Apples IDE for C/C++/Objective C programming. It is freely available but can only be used on Mac OS X.
  • Code::Blocks - Good cross-platform IDE for C and C++ development. It lacks some features of the other IDEs but is still a very good option.

Join a development forum

I think it is very important for starting programmers to have a place that they can go to if they get stuck. Lots of people get discouraged from programming because they get up to a point and get stuck. One of the best communities around is on http://stackoverflow.com/, they have a huge amount of information and very experienced developers that are always willing to help out.

Start Programming Now!!!

If you want to be a good programmer there is no substitute for experience, you need to immerse yourself in programming. Pick a project that you think would be interesting or useful, e.g. calculator, text editor, pong game… then begin working, you need something that you are interested in or you will most likely lose motivation. I've done very well at university in my computer science course and this is not because of any particular advantage over the other students, but since I started programming I have thrown myself into the subject. Once you do this you will find that you pick up programming very quickly and will have a good time doing it!!

Thursday, 1 November 2012

Setting up OpenCL in Visual Studio

Introduction

As a relatively new OpenCL user I was looking online for a guide to setting up OpenCL in visual studio. I have about 9 years development experience, so I thought this wouldn’t be much of an issue but I did have a little trouble due to a few details of the setup not being common knowledge. In this article I’m going to provide step by step instructions on setting up OpenCL for both nVidia and ATI graphics cards in Visual Studio 2010. I assume that you have an OpenCL capable graphics card, if you are unsure please check your manufacturers website or leave a comment and I’ll check for you. In this tutorial I will be using an nVidia card but I will provide text instructions for AMD cards.

1.       Installing OpenCL

For nVidia graphics cards you need to install the CUDA toolkit and development drivers. As of the time of writing the current CUDA toolkit version was 5.0, this version includes the development drivers in the toolkit. It can be downloaded here:

For ATI graphics cards you will need to install the AMD APP SDK (formerly the AMD Stream SDK). This can be downloaded from:

2.       Setting up the Project

First thing to do is set up an empty VS project by choosing
  • ‘New Project->Visual C++->Win32 Console Application'
  • Enter a name for the project and choose OK
  • In the application creation wizard choose ‘Next’
  • Under ‘Additional options’ check the ‘Empty project’ box and click ‘Finish’

3.       Including OpenCL in the Project

The first step in including OpenCL is to create a C++ file, this enables the configuration options we will need.
  • Right click on the ‘Source Files’ folder in the solution explorer and select ‘Add-> New Item’
  • Select C++ File and give the file a name
  • Click the ‘Add’ button in the bottom right hand corner of the dialog box
  • Now we are ready to point the project to the include directories for OpenCL
  • Right click on the project name in the solution explorer and select ‘Properties’
  • From the ‘Configuration’ drop down box choose ‘All Configurations’
  • Navigate to ‘Configuration Properties-> C/C++ -> General’
  •  In the ‘Additional Include Directories’ field add the following information depending on your graphics card
    •  nVidia   -“$(CUDA_INC_PATH)”
    • AMD    -“$(AMDAPPSDKROOT)\include”

include path image

4.       Linking OpenCL

Now we are going to tell the project where to find the actual library file which contains OpenCL. This is where the actual implementation of OpenCL is contained.

Without closing the dialog box used above:
  • Choose ‘Linker-> General’
  • In  the ‘Additional Dependencies’ field enter the following, again this is based on your card vendor
    •  nVidia   - “$(CUDA_LIB_PATH)”
    • AMD      - “$(AMDAPPSDKROOT)\lib\x86” (for 64 bit users you may need to change the x86 to x86_64, I have no machine to test this on)

library path image
  • Still in the ‘Linker’ submenu, select ‘Input’
  • In the ‘Additional Dependencies’ field click on the arrow that appears at the end of the field and choose Edit…
  • In the dialog that appears enter “OpenCL.lib” (without the quotes obviously J)

library link image

  • Click OK in the dialog box
  • Click OK in the Properties dialog to bring you back to the main IDE
If you are a 32-bit user then your project is now set up for OpenCL (skip to the” Test Your Project” section), if you’re a 64-bit user then continue on to the next section.

5.       A Note for 64-Bit users

If you are using a 64-bit machine then you will need to add an x64 target to your project to be able to build it.
  • Again open the properties page of your project by right clicking on it and selecting ‘Properties’
  • Select ‘Configuration Manager…’ from the top right hand corner of the dialog (if it is greyed out expand ‘Configuration Properties’ on the left hand side to enable it)
  • Under ‘Active solution platforms’ select New...
  • Under ‘Type or select the new platform’ select x64 and click OK
  • Click Close
  • Click OK to get back to the main IDE


Your project should now be set up for OpenCL!! Wasn’t that a breeze ;)

6.       Testing your project

Below is the simplest OpenCL application to test that the install and configuration have worked. Copy this code into the C++ class that you created at the start of the tutorial:

Click the run button. If you get a console window that opens and then closes again, then congratulations!!! You have just taken the first step on your OpenCL/world domination journey. Happy coding guys! If I have made any errors please leave me a comment and I will correct it ASAP.