Posts Tagged: C


31
Dec 11

Ringing in the New Year by seeing out the old

2011 has been a great year for me;

  • Graduated with a 1st MEng in Electronics & Software Engineering @QUB,
  • Got Job offer to a major financial house, which I turned down,
  • Got Job offer to a C|EH company in England, which I turned down,
  • Got DELNI Funded PhD offer (x4) from CSIT/ECIT, which I turned down,
  • Got selected to be one of the two UK projects within a Joint UK/FR Defence PhD Programme, which I accepted,
  • Saw fantastic growth in QUESTS and the Hacker^H^H^H^H^H^HMakerspace, including the beginning of a Major project, which we got EEECS Funding for and are also hoping to get QAF funding for QUESTS in general,
  • We are on track to get a actual space for the Makerspace circa Summer 2012,
  • Had the fantastic experience of living and working in Zurich for the summer with IAESTE / Pc Engines Gmbh, which gave me the opportunity to visit all over Europe, which was great for my confidence and self-belief, and also gave me a great many new friends all over the world,
  • Started (re-)learning French,
  • Came second in the UK Nationals of the IET’s Present Around the World Competition in Liverpool for my talk on Privacy in the Modern world (I keep meaning to screen-cast this but keep forgetting…)
  • Had a great time making an interesting site with Matt Campbell, Alastair McKinley, and the Sisk Brothers (was live for a few days over the summer, and we didn’t want to pay for it so let it die; may go back to it this year!)
  • Was asked to speak at the QUB EEECS RS Colloquium, representing Digital Communications within QUB/ECIT.
  • Travelled over 6,000 Miles, visiting at least 12 cities in 7 countries.
  • Lost a phone and a bike,
  • Went on 12 ‘dates’, 5 of which were worth while, 3 of which I’m still in touch with,
  • Taught at least 5 first years that C++ isn’t magic, it’s just poorly taught,
  • Sat on 5 committees, only one of which made me feel productive,
  • Had a pretty awesome time.

Going forward, I’m not going to make a load of promises I won’t keep. Thanks to all my friends, family, colleagues, competitors, enemies, bureaucrats, pencil-pushers, and random-folk who made my year what it was.

I plan on only two things;  KISS, and…


18
Apr 11

LU Decomposition in C (and under CUDA)

As part of any major project, it occasionally happens that you assume something is a ‘solved problem’ when its really not.

Continue reading →


14
Apr 11

CUDA Compute 20 Error and other issues

There’s a quirk of using older CUDA drivers is that  the latest NVIDIA SDK code examples are not backward compatible, i.e compiling the 3.0 SDK against the 2.3 toolkit (that I’ve spent the last day doing) is a fools errand (Thanks very much to @thebaron on #cuda on freenode and tkerwin on StackOverflow.)

Basically, the 3.x drivers reclassify newer cards based on the; previously, the ‘compute’ value (a measure of OpenCL adherence) would max out at 1.3, but now the range is extended up to 2.0, but the 2.3 toolkit does not recognise this value, so craps out.

nvcc fatal   : Unsupported gpu architecture 'compute_20'

The first solution is to try to use the 2.3 SDK instead, and thankfully, NVIDIA keeps a tidy library of back-releases. But upon installation of the 2.3 SDK, a new problem appeared. Lack of OpenGL Libraries… Unfortunately the machine I’m working on isn’t exactly standard issue so I’ll be asking the maintenance team to check it out on my behalf.

The secondary fix is to force nvcc to to use the older 1_3 capabilities in the makefile of the problematic kernels;

# CUDA source files (compiled with cudacc)
CUFILES_sm_13 := *.cu

There are a variety of these CUFILES_sm_XX clauses for different capabilities. Dig around the ../sdk/C/common/common.mk file for more hints.

PS This is a really old draft I found disgarded in my queue, so excuse me if this is very out of date.


28
Apr 10

SEE, Programming Abstractions, Assignment 1

SEE, or, Stanford Engineering Everywhere, has turned out to be my favourite E-learning resource; I’ve dipped into it a few times over the past few years but in light of my recent investment into a CUDA enabled Graphics Card, I thought that it was coming high time to brush up on my C++ programming, which I’ve basically left stagnant for two years after advancing no further than function pointers, structures, and templates.

So, in the spirit of openness that SEE tries to foster, I’ll be blogging my work through their CS106B course, Programming Abstractions, the second of three programming courses. (I passed on CS106A, Programming Methodology, since I’ve had enough Java shoved down my throat to last a lifetime…).

Continue reading →


13
May 08

Another Uni Project

If anyone is interested in Erlang B Calculations, very relevent to any communications or engineering students, I’ve written a little quick piece of code to calculate them.

There are several levels of functionality in the code.
Erlang B itself only has 2 variables, System load in Erlangs, and the number of “trunks” (read: servers/call center operators/phone lines), and its output is a blocking probability from 0 to 1

All three of these variables or none atall can be defined at runtime;

  • The desired blocking probability can be input to stop the calculation at that point. (default 0)
  • The Load can be defined (See Erlang A) (default 1)
  • The maximum trunks to be calculated (default 100)

The code uses the unistd.h library for argument parsing so is more or less unix only (or cygwin alternativly) and long doubles for more or less everything inside the code.

Having tested the limits, it kinda conks out then calculating large (read 1000 erlangs) on large trunks (got as far as 1234 trunks, then died)

When i get a bit of time i might optimise the factorial part so it doesnt run thru the entire factorial sequence for each number.

Anyway, the code is here. I’m not wasting my time laying out code on blogger.


12
May 08

Folding Code

I’ve been folding for a while now, and I’d previously written a really very cobbled together way of parsing my unitinfo.txt files, but, searching for something to do other than revise, I’ve written a similarly cobbled together but much shorter way of parsing my folding progress and telling me (as in speech) how far its going.

Required: Espeak, basic bash knowledge to adjust.

note: the espeak adjustments are just personal preference, so change them at will.

Its kinda a cheat cus it calls itself but isnt recursive. I’m just lazy


#!/usr/bin/env bash
case "$1" in
"-v")
points | espeak --stdin -s200 -v en+f4
exit
;;
"-w")
points | espeak --stdin -s200 -v en+f4 -w $2
exit
;;
*)
echo "Folding Stats at "&& date +%H:%M
echo "CPU1:" && cat /var/folding/foldingathome/CPU1/unitinfo.txt | grep Progress | cut -d'[' -f1 | cut -d' ' -f2
echo "CPU2:" && cat /var/folding/foldingathome/CPU2/unitinfo.txt | grep Progress | cut -d'[' -f1 | cut -d' ' -f2
exit
;;
esac

it doesnt look very pretty on the console but i think it sounds alright.

Better get some calculus done

::Edited for new version of code with wavfile output


12
May 08

Embedded C GPS Project

Afternoon folks, I’m supposed to be studying but dont have the heart to, so I’m documenting a recent project from Uni.

The remit was to be able to parse RS232 data coming in from a GPS unit and reformat it for a LCD display. I dont have the part numbers handy but I was programming on a 18F series PIC that supported C.

Most of the ancillary code is more platform dependant, such as working with the PIC interrupts etc, so for the purposes of this code snippit, assumme that a NMEA sentence (I used RMC and some RMB, but never really finished that bit) stored as a character buffer, and a structure, as defined, to store relevent data in.

PLEASE read up about NMEA sentence structure before continuing

typedef struct message
{
//date
int day, month, year;

//Time
int hour, min, sec;

//lat
int lat_deg;
float lat_min;
char lat_ref;

//lng
int lng_deg;
float lng_min;
char lng_ref;

}message;

Since NMEA sentences are comma separated values, I kinda cheated and iterated thru the string, replacing the commas with terminating characters and recording the next positions as character pointers.

for(i=0;i<BUFFERSIZE;i++){
if(end)buffer[i]=0; //wipe the rest of the sentence

if(buffer[i]==42&&check==1){ //asterix
check=0;
if(checksum==chr2hex(&buffer[i+1])) valid=1;
else valid=0;

i+=2; //get to the end of the checksum

end=1; //this is the end of the current sentence
}
if(check)checksum^=buffer[i];
if(buffer[i]==36){ //dollarsign

buffer[i]=0;

check=1;

AddToList(&(buffer[i+1])); //ignore first character

}
if(buffer[i]==44){
buffer[i]=0; //replace all commas with nulls
AddToList(&(buffer[i+1])); //add next position to list of words
}
}

The first character(dollar sign) is ignored because it is never needed beyond this point.

The NMEA sentence structure includes a asterix delimited checksum, i.e everything after the dollarsign and before the asterix is progressivly XOR’d and the hex value representation of this result is concatenated on the end of the sentence before transmission.

the chr2 hex function simply converts two ASCII characters to their Hex value equivalent.

AddToList, strangly enough, adds the pointer passed to it to a wordlist, which is an array of character pointers.

Now we have a list of pointers, because i used a character pointer array, and ended all the strings with nulls, we essentially now have individual strings for each part of the NMEA sentence, that can be addressed directly. eg:
{ //GPRMC
getTime(words[1],&incoming);
getDate(words[9],&incoming);
getLat(words[3],&incoming,*words[3+1]);
getLng(words[5],&incoming,*words[5+1]);
}

In this instance, the get functions all take two arguments, what to read from, and where to put it.

For anyone whos interested the full code is here

I guess i better do some work then.


Load Times Plugin made by Ares Free Download