gentoo: gcc (auto) vectorization

First of all, for those wondering, [1]: vectorization is a process where a sequential program using a pair of operands on the same instruction in an iteration is transformed into a vector program where a single instruction can perform multiple operations or a pair of vector. In this notation by vector I call datasets of the same type.

In quite modern machines/architectures (namely x86) there exists such a vector processing(one or more ;-) ) unit utilized by the SIMD instructions set (usually SSE,SSE, see below). SIMD [2] is one of various ways implementing parallelism in computer hardware.  In this schema,some large set of CPU components perform the same task (operation) at the same time, each with different data leading to a high utilization of these components without wasting CPU cycles in the same operation.

For instance the following code is vectorized:

#define SIZE 1024
int a[SIZE], b[SIZE], c[SIZE], d[SIZE];

void linear ()
{
int i;

for (i=0; i<SIZE; i++)
{
a[i] = b[i] * c[i] + d[i];
}
}
If the parallelism is viable, then the compiler after the autovectorization process may produce  high performance code that makes high utilization of processor vector units. This certaintly is of supreme importance (to reduce the total instructions executed where applicable) in a high performance distribution. So after some reasearch,  I decided to enable on all of my gentoo machines the vectorization on the CFLAGS (the vectorization as one may see in its homepage is automatically enabled on the -O3 optimizations [3] ) . Gentoo should be the fastest linux distro around; END OF STORY.

CFLAGS="-march=nocona -mtune=nocona -O2 -pipe -fomit-frame-pointer -ftree-vectorizer-verbose=5 -ftree-vectorize -fassociative-math -msse -msse2 -msse3"
The options to do so is the -ftree-vectorize combined with tha -msse -msse2 options (which are the SIMD utilizers for the x86 (amd64) arch) if you are having a more capable SIMD instruction set you may use it (i.e. -msse3, -msse4.1, -m3dnow(:-P) etc), while -fassociative-math can be used instead of -ffast-math to enable vectorization of reductions of floats.

here are some before and after results concerning vectorization speedup  on:

rodos ~ # uname -a
Linux rodos 2.6.27-gentoo-r8-korki-pentium-prescott #8 SMP Mon Mar 9 19:28:11 EET 2009 x86_64 Intel(R) Pentium(R) 4 CPU 3.00GHz GenuineIntel GNU/Linux

The results follow in the following snippet and are for 8192 bytes in kilo

Vectorize Enabled Vectorize Disabled
md2 7135,23 6435,79 0,11
mdc2 9210,54 9404,42 -0,02
md4 901018,97 636548,84 0,42
md5 546226,18 306845,91 0,78
hmac(md5) 551026,69 551318,87 0
sha1 299592,36 296080,73 0,01
rmd160 174093,65 148373,5 0,17
rc4 439552,68 439959,55 0
blowfish 99672,06 98432,34 0,01
aes-128 111878,14 111209,13 0,01
aes-192 102440,96 100368,38 0,02
aes-256 91635,71 91280,73 0

or in a more comprehensible representation:

openssl performance

Unofficial presentation of pwmn @ upatras

Last friday some folks (including me) did an unofficial presentation of the pwmn @ upatras. The attendance was quite unexpected, and while the joke among the workgroup that planned the “event” was that there would be more pwmn members than students, the people that came was suprisingly high!

The purpose of the presentation was to intrigue students to participate to the open/free community called pwmn, and to give them some insight info about it, just in case they would like to get involved.

One of the major concerns back in my days when I was intrested in wireless technologies was the speed (aka Need For Speed. How fast one can download stuff was my primary concern, and the second reason that made me establish a core node. (The first was the companionship among friends). Yet nowdays people such concerns are no issue! And I am actully wondering why? Are we so congested by the “high speed” dsl (namely 24mbit ~ actual 10mbps? Aren’t we intrigued by wireless bandwidth?

On the other hand the people that participated ware more intrested in the wifi technologies in use like the OS running in the routers, the routing protocols, the parameters of linking among different areas, and how the linking can be achieved. Wow! totally different generation…

** I will update this article at some point with photos from the “event” and other thoughts about the event

Another blast from the past

Yesterday as I returned from the lab@upatras, I ran into some peaceful protest in olgas square (protests in greece are more than common ground since the unjustified murder by the “democratic” police state). The protest was about an attack with a war hand grenade (yes the ones that kill people during war) against an assembly of people in athens that were talking about greek army mobilisation. Thankfully the attack failed and no people were harmed.

Despite the fact that one may or may not agree with such protests or gatherings (and at that point I am quite sure that noone is in favour of attacking unarmed civilians) , there is one definite value worth mentioning at these protests! The music! Some of the tracks played I haven’t head them since I was in high school and I feel really youthful and maybe nostalgic about these times. In this post I present one of my favorite with great lyrics and instrumentation that I heard yesterday :-)

Instrumentation is quite amazing! Through its simplicity the song manages to create a really ongoing extroverted feeling that each individual identifies it differently! And what can I say about the lyrics… This song is a masterpiece for the greek rock era, that cannot be overwhelmed by todays “productions”.

The song is dressed by Paul Sidiropoulos’  [link] and Maria Fotiu [link] voices

some (freely translated) portions of the lyrics;

and how the new day shall arise when the errors capture (your) time?

and hot the new day shall arise when the lie lead the way?

draw a sun in the ceiling, talk with the night breeze and dance with your shadow, in a weak’s heart beat!

call your lonliness or march towards the streets of fire

If  you are not greek and you have no idea about the greek language and the particular song, I would be very intrested hearing from you about my (flawed) translation. What did you understand?

Dev-c++ (dev-cpp) sucks

In my last blog post I commented dev-c++[1] to be way problematic! It is time to justify my saying.

So this article sums up to : why dev-c++ sucks! Remember that the dev c++ in question is the 5 beta version!

  • Ancient platform
    • last updated: something in the last decade
    • gcc 3.4.3 (WHAT??? - I am currently 4.3.3-p1 on my gen2) while the dev c++ stable -version 4 [2]- has gcc 2.95
    • gdb 5.1.2 (lol - currently I am using 6.8)
    • using cygwin (no winapi for native windows runtimes)
  • Totally immature
    • yeah right! after 5 years in beta stage this thing still crashes! yuppie!
    • cryptic project development
    • lack of standarized build tools (autotools, make, etc)
    • the way the gui controls the gdb seems problematic

The real question when you are about to choose your devenv is why having the wannabe devenv while you can have the real deal! Even the most unattended linux (i.e. slackware [3] :-P)  distro, have a decent gcc [4] accompanied with uptodate binutils [4] and coreutils [5],thus providing at least stable development enviroment.

If instead you insist on developing apps on windows make yourself a favour and choose a well adapted tool. i.e. Eclipse [5], netbeans [6] or Codeblocks [7]

C language misunderstandings

(or teaching undergrads how to code in C)

Last semester I was asked to support a class of undergrads for an introductory course in programming languages (namely plain old ansi C). During the semester various problems made the students underestimate C and its capabilities (maybe even hating the lang), making the course not just boring but also incomprehensible;

One fact worth mentioning is the “educational approach” taken by one of the tutors [1]; He created a small intresting game app (battleship), that arouse the students curiosity and intrest to create the application (in fact some were intrested in using ncurses for the term handling), and during the app build up he introduced some important aspects of the C programming (i.e. datatypes, var scope, functions , pointers , arrays, dynamic mem allocs, etc…). At many levels students of this class had many chances to stimulate their creativity using C, and some did so.

During this quest of getting familiar with a sturdy programming language like C many people had “enough” issues (issues that somehow are not usually addressed and are carried along the programming lifecycle for ages, even after graduation :-P ). Some of the important ones are:

  • You shouldn’t create dynamic arrays. Period
    • Whille the following code is valid on some compilers (namely gcc) the programming concept is inconsistent with the primitive language ideas


...
int a;
scanf("%d",&a);
int arr[a];
...

  • The implicit declaration of function xyz is not just a trivial warning that can cause no harm. This warning identifies a flaw in the programming habbits. When you use a function YOU must include the corresponding header where the prototype of this function lives!
    • For instance if you are using the <code>system</code> function, you ought to include the <code>stdlib.h</code> header. Of course usually there are no different implementation of the system function in the same arch but what about with the <code>malloc</code> directive? [hint: <removed the hint> ]. You may run into real trouble if you let the compiler decide the malloc behaviour.
  • Casting! What can one say about casting… (incorrect) Casting is usally a reason for runtime errors (i.e. segfaults), so students should be extra carefull when casting :)
  • Free the damned memory (I guess this is minor since when a programmer builds a memory intensive program he will take into account the needed memory but hey one should keep in mind that this may be a problem at one point)
  • using the wrong tools building their apps
    • Well let me tell you… Using the stupid DevShed is the single worst IDE for C/C++ i’ve ever seen. If you are about to learn programming, you should use a tool that may be reusable at some point later (like all software components should do); So why not using some wonderful opensource multiplatform dev IDE like a) eclipse [2] b) netbeans [3] c)or even sun studio [4]. Why bother with something so immature like devshed?
    • CC. A developer should be able to use some command tools at some point. things like {c,g,’ ‘}make, ld, ar, gcc ,icc mayor may not need some finetuning at some point. so why not messing around with them a bit.
    • DEBUGGING: Mandatory! -g, -Wextra, -Wall maybe type checking for even stricter code (-pedantic and/or -ansi and/or -c99 and/or …)
      • Some use of gdb (do just a backtrace mate)
      • strace (if the students get a glimpse of system calls during the classes )
      • some other cool debugger that I haven’t heard of (please comment about it if it’s F/OSS)

This is the short version of the issues (certaintly I forgot lots of other minor cases) but in my opinion these are major issues a class should emphasize on (if you have any other on mind please elaborate)!