Cellular Automaton Engine with C++ AMP – Part I

January 8, 2012 1 comment

Cellular Automata

For my first contact with cellular automata I thank to science fiction author Greg Egan and his brilliant novel Permutation City. It is hard-core sci-fi – not like wannabe-scientific fantasy fairy tales which are in form of books and movies everywhere today trying to persuade people that they represent sci-fi genre. At the time of reading it I did not even understand what cellular automata exactly is (in this novel, artificial life simulator was based on it). But later I spent some time trying to understand basics and I found a book which can be without exaggeration considered the bible of cellular automata: New Kind of Science (NKS) by scientist Stephen Wolfram. It is huge book and although I bought it some years ago, I did not manage to read it all so far. It looks at cellular automata from all angles, surprisingly covering many disciplines where the knowledge can be applied. Although this work is controversial and by many not so revolutionary as Wolfram claims, it helped me understand one thing: It is something fundamental. I was always attracted to fundamental things, things which are simple and capable to explain complex phenomena. That’s why I was interested in theoretical physics in the past (“popular science” level only) and that is also why for example I don’t care about mess which is in the field of elementary particles today (I am not interested in Higgs boson. It is just not fundamental enough.)

So what really is cellular automaton (CA)? I am not going to explain what it is, you can simply click on hyperlink to find out. I will say what it means for me: CA for me is an example of how complexity emerges from nothing. Understanding this has interesting implications and great philosophical consequences; it significantly changes how I look at the world, at the questions of our being, life and reasons why we and nature exist in the form we observe. But I will keep this philosophical aspect aside, because it is not important for what I want to do. It is just reason why I think it is such an exciting topic.

For purpose of the following, I can describe CA as discrete deterministic system of simple rules iteratively applied to n-dimensional space. In each step we apply the rules to find out the state of each cell of the space (usually cell state is 1 bit – “On” or “Off”). Inputs for the rules are states of the cell and neighbouring cells from previous iteration. I am going to experiment with 1-dimensional CA as Wolfram does in NKS. It maybe does not look so sexy as for example two-dimensional Conway’s Game of Life or CA in more dimensions, but it is fundamental and reduced to its essence. From now on I am talking about Elementary cellular automata only.

Programming massively parallel non-blocking programs

At first something about my motivation. I work as a software developer in Microsoft ecosystem (.NET, C#) currently specializing to GUI (Silverlight) development. Although it is challenging and definitely not boring, there is something lacking in it. I do not want to completely reduce it to simplification that what most developers today work on is just “screen, form, database” and variations on it. I would borrow words of a friend who said it is a craftsmanship. Creative and exciting, but craftsmanship. It is engineering work with less and less computational problems rather more focused on integration and orchestration of tens of internal and 3rd party components and subsystems. Where is pure computer science?

Therefore for balancing what I work on professionally, I want to widen my horizons at home. What interests me now is pure computation, parallelism (with minimum blocking) also with less abstractions and 3rd party components, closer to the “iron”. 100% utilization of resources by efficient algorithms.

Next take on GPU computing: C++ AMP

We live in such an exciting time. We recently realized capabilities of GPUs for different applications. Although identifying data-parallel problems and implementing them requires paradigm shift, taking advantage of GPUs is more and more common. But still, general purpose computing on GPU (GPGU) is in its early stages. What technology / stack to pick? CUDA which is I think the most mature architecture with amazing tooling but it is NVidia specific? Or OpenCL which is for heterogeneous platforms, with similarities to OpenGL? Or DirectCompute which is heterogeneous only from hardware perspective? With all of them requiring to use special language (C for CUDA, GLSL, HLSL) for shaders. Or something on top of mentioned adding another abstraction layer?

I decided I will go for something new: C++ AMP. It is new, not yet finally released technology from Microsoft. Their ambition is standardize it as part of C++ specification. I do not know how successful it will be and it is possible it will be forgotten. But I hope not. I am quite excited about it.

What I like it does not force you to use any special language. It is part of C++ (C# would be nice as well but I admit starting with more low-level general purpose language is logical). It allows you to annotate methods or lambdas with the new restrict keyword, which is used to tell compiler where the method can be executed. Your regular C++ program can contain blocks which will be executed on accelerator (GPU) with advantage of compile time checking for restrictions of target hardware (no writing to console on GPU ;-)).

It is built on top of DirectCompute (compiler generates HLSL for you and embeds it into the executable), but wait – it is future proof. DirectCompute is only current implementation detail and for example NVidia can provide CUDA implementation later. And when sometime in future GPU vendors come with unified interface to GPUs, this abstraction layer can be taken away completely.

There are other reasons to be excited about AMP, for example debugging experience is awesome. I highly recommend this video to everyone who is interested in this technology.

There is one big drawback. Early adoption of something, what does not have even stable release will be pain. I know it. I realize that this is not the most comfortable way to pick (CUDA is), but learning something new which can change GPGU field and make it really platform independent and “general purpose”, is worth it.

And I almost forgot: Why to use GPU for CA? Because it is data parallel problem (same algorithm applied to lot of data without need for synchronization). (We will see that it is not that simple and some synchronization is required).

First (naive) implementation and lessons learned

Objective of this first exercise was modest: running simplified CA algorithm and making the GPU sweat. It was not important whether it is efficient now, this was to try out AMP and discover concepts, limitations and possibilities of it. I also wanted to hear fans of my GPU (without playing a game :-)).

Program is simulating 1-dimensional CA, space length is fixed. Pure simulation, no visualisation.

Algorithm exposes following interface (C#)…

BitArray Run(int spaceLength, int ruleNumber, int iterations, int[] initialTrueIndexes)

…where spaceLength parameter is number of cells, ruleNumber parameter allows you to specify rules of CA using Wolfram’s numbering scheme, iterations is number of iterations for the automaton. Instead of providing initial state for all cells of CA, initialTrueIndexes allows you to specify which cells are initially in “On” state (usually one cell). Return value represents the whole space after the CA simulation.

Requirement for C++ AMP is Visual Studio 11 Developer Preview. GPU debugging works only on Windows 8, so I installed Windows 8 Developer Preview to VirtualBox virtual machine for debugging purposes.

I exposed functionality as C# library which is wrapper around C++ library. For this I used approach described here (see also here). I had to refresh my C++ knowledge (including bit operations). The biggest problem I faced was missing outer brackets in #define directives what caused me lot of pain (yes, lame mistake).

CA “engine” is implemented in Engine.cpp file (whole solution is included in this blog post). I am not going to discuss it in big detail, because I realized it is kind of throw-away prototype. It has various flaws which I will describe.

I decided to do data parallelism on cell level with 1-bit granularity, that means 1 thread per each cell (which is one bit). Obviously, bit is not addressable, so I could use int for one cell instead (byte is not supported on GPU), but it looked like huge inefficiency (it would use 32x more memory than it essentially needs). And running 32 threads on the same data (one int) is basically crazy idea, because of required synchronization. So what I have done is I decreased level of parallelism by simulating 32 cells by one GPU thread which computes their states serially. This decrease of parallelism was mistake I will not repeat, because massive parallelism is what I wanted to gain from GPU originally.

Another rather fundamental flaw was that I was designing it with the assumption that it will be whole executed on GPU and CPU will simply wait until GPU runs required number of iterations. I did not realize there is an synchronization issue. Because state of cell depends not only on its previous state but also previous states of its neighbours, there has to be some barrier which will cause threads to wait. Global barrier for the whole space is logically not required and inefficient too (and I do not even know whether AMP / GPU supports something like that). Another option is barrier on the tile but that is not possible because CA space cannot be split into subspaces which are independent. There are other reasons why this was wrong approach. Long running GPU kernel (> 2 sec.) will cause graphics driver to restart, so apparently this was not supported use case (so no, I did not make GPU fan noisy). Other future features like read-back of space during the simulation, expansible and sparse space, all of those will require CPU, because of GPU limitations I learned.

Current naive implementation does not contain synchronization and therefore it can theoretically return unpredictable results. I created something which is not correct and has flaws, but it pointed me to new directions, stimulated me to discuss it with others and to think about something better. But it essentially runs CA and I learned a lot about not only AMP but GPGU paradigm generally. Objective partially met.

Get source here

Next steps

Next and the proper solution will consist of part executed on CPU and part executed on GPU. CPU will intelligently dispatch subspaces to GPU for computation of partial results. It will manage expansion of space and synchronize interdependencies between subspaces. Only what is required will be computed (number of dispatched subspaces will grow with increase of cells in “On” state). It will allow to read-back the space during the simulation (later maybe also visualize it). I will also consider creating general n-dimensional engine. Because of the high cost of CPU memory <-> GPU memory copying, it will not be trivial and has yet to be analysed properly.

Since it will be tight cooperation between CPU and GPU executed code, I am planning to implement both parts in C++. Wrapping GPU code by managed wrapper just adds unnecessary complication. I will get rid of C# completely.

To be continued… I am looking forward but I suspect it won’t be anytime soon 😦


Scandi-Trip Part V

September 3, 2011 Leave a comment

The last part of our trip is basically getting home from Lofoten islands in Norway through Baltic countries. It includes visiting interesting places, mainly capitals of countries which we cross. But the plan is tight and we have only limited time for them.

Quick crossing of Sweden is followed by entering Finland (which is different time zone). Driving southwards through Finland is long and boring. Monotonous neverending lowlands with forests is what we see from the car. In Rovaniemi (on Arctic circle) we are visiting Santa Claus Village. It is pure fail. For some unclear reason this village claims it is home of Santa. Everything what it offers to tourists is maybe 10 giftshops plus one gift shopping center with another 10 giftshops. Atmosphere wants to be christmas-like (unsuccessfully) to persuade tourists to buy various useless Santa Claus themed things. Working here in gift shop I must consider the saddest and most depressing job at all.

Second and last stop in Finland is its capital, Helsinki. We spent just couple of hours here, so it is hard to judge it. But generally, city is not very interesting. People (compared to Norway) don’t speak English and Finnish reminds us Hungarian language. Our attempt to board first ferry to Tallinn is not successful. Failure in their reservation system causes us to wait several hours for the next one. Our ferry – Baltic Princess is huge, with 10 floors, equipped with various facilities (shops, pubs, restaurants, live music…). Cruise takes 3.5 hours.

Next three countries are Estonia, Latvia and Lithuania in this order. We know almost nothing about these Baltic countries, by visiting their capitals (Tallinn, Riga, Vilnius) we are at least trying to learn differences between them. Threatened by statistics of high numbers of homicides (found by friend), overnights we are staying in city campings (for the first time). What these countries have in common is that almost nobody understands English. We can also feel that we are in former eastern block influenced by period of communism (for example architecture, statues in socialistic realism style…). Generally, cities are similar to Bratislava, it is apparent that our histories have something in common. Also the same horrible roads, the same trams, trolleybuses… But they are also very nice, it is not only about communism. Culturally, cities are full of history (old towns are bigger than in Bratislava) and everything is blended with modern style developed after 90s in a positive way. Girls are beautiful here (Estonian blondes probably win). We stayed only 2-3 hours in each capital, it would be definitely worth to explore more (also nightlife). Maybe sometimes in future. Old town of Tallinn is cozy and full of nice historical buildings, though it left a little bit sleepy impression on us (but that is maybe because we were there at 9 in the morning). Riga was bigger and very lively. Students celebrating beginning of the school year (with help of alcohol) were guarded by many policemen (BTW, density of police in the streets is much higher in post-communist countries than elsewhere). We enjoyed great views of the city from church tower. Vilnius old town (part of UNESCO heritage) we enjoyed from sightseeing bus. Very nice, lot of churches, visible influences of various cultures (russians, jews).

Last country before coming back to Slovakia was Poland, the country with probably worst roads in EU. We found time to visit Warsaw for 4 hours. We took sightseeing bus again to briefly explore main highlights (old town is UNESCO listed again). But the most impressive thing in Warsaw for me was monumental Palace of Culture and Science, 231 m high building built by Soviet Union as a gift to Polish people in 1955. It is controversial building which reminds communism for some people, but according to me it is aesthetically very nice. We enjoyed panoramic view of the city from its 33th floor.

Our return to Bratislava follows and after nearly 9000 km traveled, our trip comes to an end. In three weeks we explored mainly Norway and briefly also capitals of Denmark, Finland, Baltic countries and Poland. Our coverage of interesting places was not complete and we identified places we want to visit again and dedicate more time to them.

So what’s next? Flying back to London, processing hundreds of taken pictures… and planning next travels (New Zealand? New York? Stockholm?). Because as someone said: “The world is a book and those who do not travel read only one page.”

Categories: Travel Tags:

Scandi-Trip Part IV

August 30, 2011 Leave a comment

Following 4 days of our Scandinavian travels are dedicated to northern Norway, mainly Lofoten islands. Long, boring journey towards north is interrupted by crossing the arctic circle, the only place worth mentioning. Arctic circle is border of area where polar day / night occurs at least once a year. We could not witness it, but still, even at midnight, sunlight was visible on the horizon (in case it was not cloudy). But it was nothing special, I would really like to experience polar day and also northern lights which we could not see this time of year as well. Back to crossing the arctic circle: plain empty country on the plateau, clouds maybe ten metres above us, cold, wind, herds of reindeers and tourist centre without tourists. At least gift shop (with all kinds of arctic circle themed clothing) was there so we spent most of the time shopping – because main tourist season is over there were lot of discounts.

Near Bodø, we looked at the worlds strongest maelstrom (tidal current) from the bridge but it was around 11 pm, so it was not very visible. I have also seen living elk for the first time. It was standing by the road and it was huge. Since that moment we started to take elk warning signs more seriously. In Bodø we boarded almost empty ferry to Moskenes on Lofoten islands. It was 3 hours long sail at night. Me and friend were sleeping on chairs on board, rest of the crew remained sleeping in the car despite the fact it was prohibited (resulting they were locked in the car deck). On Lofoten we slept more to gain strength to tomorrows hike.

Lofoten is an archipelago of which islands are interconnected with road bridges and tunnels. Area of all islands is covered with mountains which are tall, sharp and dramatic – different to mountains we have seen so far in Norway. From what we have heard, Lofoten were supposed to be uniquely beautiful but there is a risk in visiting them. And that is weather – if it is sunny it looks like from a fairytale, if not (which is quite often), it just does not pay off to spend so much time traveling to get there. Unfortunately we were not lucky and weather was bad. First day it was raining and mountains were being alternately covered and uncovered with mist and clouds. So for moments we were able to see the beauty partially (and yes, it was very nice) but we wanted to climb up some peak to see more. So we waited in caravan playing games and when it stopped raining we departed. But after ten minutes it started to rain again and we had to return back. We ended up completely wet. So with sadness on our faces we drove further through the islands hoping for better weather the next day. On the way weather was better and we discovered beautiful sandy beaches, the only problem of whose is that water is cold all year round here (but that did not stop some old grandma to swim in there). Our first night here (again some lonely place by the sea) was quite scary, because strong wind was rocking with the car and we were not sure whether we will not wake up turned on the side. But it was fine.

Next day it was still cloudy, but not raining. Great, let’s have some hike. Because of the absence of marked hiking paths here, we more or less randomly picked place to stop, looked up to the mountains and pointed at valley between two mountains – our destination. It looked quite innocently, but it ended up as 5 hours outing with quite high technical difficultly (only three of us went there, we told remaining friend (girl) that we are back in maybe 2 hours). Elevation was around 650 m, and it was very steep (up to 60 degrees). Pathless climbing complicated the hike a lot, at first we had to cross electric fence for sheep (it hit friend – they have to hear his scream on the other side of the island), then we have to walk through dense bushes followed by dominant part of loose rocks. Bonus: sheep shit everywhere, sometimes sheep as well (god, how they could climb up here?). Before reaching the top I went alone to rocky ridge, but it was too much adrenaline to me (such a height on both sides, loose rocks, no path) – so when I frightened started to shake I went back and caught up the rest. When we reached our highest point, we enjoyed the view and went back (different way). Steep descending was dangerous and friend who was constantly scared of falling into the moss-covered hidden gap between loose rocks, falled into the moss-covered hidden gap between loose rocks. Literally seconds after talking about it. The fall looked scary, he was really shocked and we thought that maybe we will have to call a helicopter. But it was ok at the end, little bit of blood, no broken arm or leg. So we did it. Very nice hike.

The northernmost place of our trip (and of my life so far) was Ardenes on island Andøya. Long driving without meeting any car and finally arriving into this sleepy coastal town had just one reason – whale watching. And it was great. It was 3 hours long wet and windy cruise on small (30 m) former fishing boat with guides and other tourists. Hydrophones were used to track the whales. We were lucky, we saw 6 huge (16 m) sperm whales – each one for maybe 5 minutes. Talk of the guides was informative and I know now much more about this nice animals (in addition I still have a piece in the fridge).

And that was our last stop in Norway. What follows now is long long drive through Sweden, Finland and Baltic countries back home. We still have interesting cities to see but all of us feel that the core of our journey is over. Excitement decreased, living together in caravan non-stop is becoming more and more annoying and we are starting to think about our normal lifes. But there is 6 days more. Let’s see…

Categories: Travel Tags:

Scandi-Trip Part III

August 25, 2011 Leave a comment

Next part of our journey covers traveling from southern Norway up to Lofoten islands. It is a long way, so most of the time we spent driving, often only 300 km per day (narrow roads, construction limitations, ferries). But we had some interesting stops, obviously. We are still driving in the land of fjords – so we are making lot of “photo breaks” where we observe and document the country. There is lot of waterfalls, we drove to one intentionally (Voringfoss) but soon we realized it is not required – there is one in every ten minutes on the way. They are tall, falling from steep hills often straight to the fjord. Frequency of ferry transfers increases to up to 3 a day, tunnels are maybe 20 in one day. Weather is not good, often rainy but that is Norwegian climate, what to do… We sleep on various places by the road, interesting one was on some plateau in mountains where we parked at night and the next day saw the nice view around. That morning we also found out that we are surrounded by sheep which were brave not reacting to our attempts to scare them…it seems that they learned that they can get some food from people from caravans (to be specific they smelled our bacon for breakfast) to complement their boring grass diet. Not from us though.

Bergen, the second largest Norwegian city, was the place where we spent one afternoon. Nice city by the sea with small centre. Interesting were old crooked wooden houses – part of UNESCO heritage. We enjoyed nice view of the city, sea and islands nearby from hill above Bergen where we got by funicular, the only one in Scandinavia (as train lover I wanted to buy souvenir – piece of rail they were selling, but it would be too heavy). Interesting part was fish market where locals were selling all kinds of seafood. Some of the seafood we were given to taste, afterwards we bought some caviar, salmon and whale. Especially whale was new to us. We named him Willy. Next evening we had luxury dinner in caravan – whale with bread and wine. It was a strange feeling, we felt a bit guilty. I like intelligent animals and I usually do not eat them but I must say they also taste good. Willy was simply delicious.

Planned part of our schedule was hiking on Jostadelsbreen, the largest glacier in Europe. We came there quite late but we were lucky to catch last guided walk on the glacier that day. It was the shortest and easiest variant of the walk called “Family blue ice walk” (we would have to wait till next day to something more difficult and longer). It was very interesting and informative one hour walk on the bottom part of the glacier. We were equipped with climbing irons on our shoes to avoid sliding and all in our group of eight persons plus guide were connected with rope together. So if those four Israeli seniors fall down into some hole in glacier, we are going with them. At the end we survived and enjoyed it.

The next day we took a guided tourist (equals more expensive) ferry on UNESCO listed Geiranger fjord. Nice, nice, very nice but… we are starting to be little tired of fjords. Give me something else! Exciting attraction that day was Path of the Trolls, road going from 800 m high mountain pass downwards. Narrow road, 180 degrees hairpin turns – quite impressive but we think that less know roads we drove on a week ago were more dangerous than this.

That day my camera died. It came suddenly without any apparent reason to die (unlike my previous camera which ended its life by 20 m fall from the rock). But I am not worrying a lot, we have three more cameras here.

Next day greeted us with very nice sunny weather. I am wearing shorts for the first time, sunglasses as well. It is a shame we spend most of the day in car. Next highlight – atlantic road. It is 8 km long road with bridges through small islands near the the coast. Descriptions like the worlds best road trip set our expectations probably too high because it was not anything special and we were disappointed.

On the way up north we stopped in Trondheim, third largest city in Norway, again situated by the sea. It is university town literally full of students. Caravan crew splitted into two groups. Couple went for romantic sightseeing and me with friend parked in big wooden pub with one part floating on the river. We missed beer a lot (we drink radler every day but beer is beer). Although the beer was for around 10€, we both agreed that this is the pub of dreams. It was crowded of young students, 90% of them female, 90% of them blond. There has not been so many girls (without males) in my viewing angle until this evening (sorry, taking a picture would look creepy). Leaving the pub was hard mainly for my friend who falled in love with one black haired angel, codename “Snow White”. But it was one-directional love (as usually 😦 ) and surely there are seven dwarfs waiting for Snow White in her college room.

Anyway, we have to continue towards arctic circle. We are spending more and more time driving and this part is becoming tiring and boring (hopefully some hike on Lofoten will fix this feeling). Lesson learned for future trips: travel less, experience more.

Categories: Travel Tags:

Scandi-Trip Part II

August 21, 2011 Leave a comment

We are spending one week and half in Norway and starting point for us was Oslo. First impression: wow. Word “city” redefined. One of the best places for living I have seen so far. Ok, city centre looks quite normal, but the city area as a whole…. it is more like mountain tourist resort (a la Tatranska Lomnica). Houses spread across hills separated by lot of trees. Most of the inhabited area is basically forest with “cottage style” houses. Public transport solved by metro system called T-Bane goes under ground in the centre, but outside it looks more like mountain tram in High Tatras. And on top of that, everything is by the sea, with nice views to surrounding islands. What I did not expect is diversity of nationalities / cultures living here – similar to London (what was the major sort-of drawback I have seen). But I could imagine to live here, everyone understands English (even seniors).

We spent one day and night there parking and sleeping close to church near last T-Bane stop. Interesting parts of Oslo sightseeing were: Vigeland park with many full sized sculptures of variously interacting men, women and children; modern opera house by the sea, roof of which was fully accessible to visitors (and I must not forget luxury toilet experience in the opera); then visit of Ski Jump (plus skiing museum) with nice view of Oslo; museum with three preserved Viking ships; public transport boat cruise; royal palace and cathedral in front of which there is still lot flowers dedicated to victims of recent Oslo killing. It was sunny and warm, both locals and tourists were enjoying the weather and streets were full.

Oslo was the last city for a long time going forward. Nature follows. Next three days we spent in southern part of Norway (to the west from Oslo). No big towns any more, just mountains, forests, lakes, fjords and villages. Driving here was an exciting experience – Norwegians do not have highways and they are completely ok with it. Most of the roads are very narrow, so often it is impossible to pass another vehicle with similar size going opposite direction without waiting on place where road is little bit wider. We had some “almost-collisions” when it took us couple of minutes to pass by another car without damage (so far only one mirror contact occurred which is great). And while doing this, we had to get rid of sheep which were attempting to eat our caravan when we slowed down (really) without harming them. Traffic is not very dense, max. speed is 80 km/h often reduced to 50. Roads go through big height differences, sometimes from 0 to 1000m (fjord-mountain), they are steep and turns are often 180 degrees (usually several of them in a row). There is plenty of tunnels which sometimes form spiral to achieve big climbing on small space.

Driving itself and observing the country is wonderful. At first nature was similar to slovakian (mountains, forests), on higher places it was more raw, rocky and empty like Scotland. But it was also unique too – for example such a big number of lakes I did not see anywhere else. And that was before fjords. Fjords are the best of all natural wonders here, so driving by them, crossing them by bridges and ferries (later more common than former) is very eye-appealing.

We have two navigation devices competing in offering us the best service. Sometimes we pick decision of the device which finds the worse alternative and we end up in woods on some gravel rally-style road (at night it is quite scary and we were
expecting some Breivik’s training centre in every lonely cottage). BTW, for the first time in my life I have seen road crossing the airport runway (in the middle of it) – it was like rail crossing but with runway instead of rails.

While driving, weather was sometimes sunny, sometimes cloudy and rainy. Nights we are staying (with other caravans) on various parking places for free (usually nice ones with toilets, place to sit outside and fjord or waterfall next to it).

Among man-created wonders what we have seen, I must mention system of wooden locks on connected water channels in Telemark area (sometimes multiple locks forming unique water staircase for boats).

And what was the best and most exciting? Definitely two hiking trips what we have done. It is hard to describe them in words – we are making lot of pictures and surely I will publish them later. First hike was to Kjeragbolten (5 hours roundtrip, 700
m elevation) which we initially started at 6pm. But all hikers returning back we met, were knocking on their heads and asking whether we have torch with us… after this we rather returned and postponed the hike to next early morning. Although it was cloudy, it was great – steep walking and often rather climbing (supported by chains) in raw rocky country without trees, occasionally meeting sheep begging for food. The whole hike was basically on the edge of Lysenfjorden 1 km above fjord. Stunning height, hard to describe. The actual Kjeragbolten is rock stuck between two cliffs with 1000 m long potential drop to fjord underneath (very popular place for base jumpers). All of us were brave enough to stand on it (one by one – it is small), but it really required steady feet, mental focus and strength to cope with possible death (of my friends obviously, I would not fall :-D).

My knee was surprisingly better (thanks to hiking sticks and knee compression wrap) and after mix of endorphins and adrenaline I got, I did not care much to be honest.

Second hike was to Preikestolen (4 hours roundtrip, 330 m elevation), forest, rocks, worse weather (but good is that heavy rain started after we returned) and annoying crowd of people (reminded me Oxford Street on Sunday). Again it was on the (other) edge of Lysenfjorden and the point of the hike was possible casualty again – this time 25 x 25 m flat square rock hundreds metres directly above fjord. Not every tourist could handle sitting on the edge with feet hanging from the cliff, but I think it’s not required to explicitly say whether I did it or not 🙂 This adrenaline dose was pure pleasure and I am becoming addicted (base jumping next time? :-).

Ok, let’s continue towards north… still a long long way to arctic circle…

Categories: Travel Tags:

Scandi-Trip Part I

August 17, 2011 2 comments

This year I decided to spend my main holiday in Scandinavia. Three weeks out of problems I live with without people I spend time with and avoiding all usual thoughts I have (both positive and negative). Ok, it is not easy to completely switch myself to holiday mode and forget everything / everyone… but whatever, I am trying…

First issue what came before the trip was my knee. Something happened and suddenly I started to feel pain in it. I was limping before departure. I considered visiting doctor but I discarded the idea, because: 80% of them are useless (80:20 rule) and anyway… either it is not serious and I don’t need doctor or it is serious and there is not enough time to help me. Maybe just my body wants to tell me I am getting old… but I decided to fight. I will not return on wheelchair. Glacier hiking will cure me!

Flight to Vienna, meeting with three friends I travel with in Bratislava (I will respect their privacy and I won’t mention their names but they are 2 boys and 1 girl). Journey starts with boarding the caravan. Yes, we will drag our bedroom, kitchen, even shower and loo with us. Friends bought almost almost everything from grocery shop, it looked like for whole school canteen.

After loading, we departed. Direction Prague, Berlin, Puttgarden. In Prague I experienced my first drive with the huge beast (caravan) – thanks to our GPS it was through city centre – so with sightseeing included. I discovered that my style of driving which consists of accelerating, braking and quick steering is not just inefficient but dangerous too. Dynamic of the vehicle and its content was completely different, and I was occasionaly reminded to it when everything was moving and falling down with noise.

First day was about getting to ferry in Puttgarden which we boarded next day. First night was new experience for us. Everything is small and comfort is far from sleeping in real bed. Size of bed in the back is something like my bed, but I have to share it with friend. And friend does not mean nice girl unfortunately, actually it does not mean girl at all. Second “bed” which I have the pleasure to use every second night we have to assemble from back chairs and it is clear that sleeping is not main purpose of that thing.

Next day, we boarded ferry to Denmark. I have seen for the first time in my life whole train boarding the ferry – I did not even know that is possible. Our only stop in Denmark was Copenhagen. It is nice city full of channels and islands. We spent half day sightseeing, including boat tour. But the most interesting thing was part of town called Christiania. At first sight it looked like Camden – lot of strange people selling strange things. But those strange things were mainly THC based drugs – and selection was very rich. Labels “no photo”, “don’t run” and “selling drugs is still illegal” were everywhere. When I wanted to put my camera in the bag, I was almost attacked by some “rules enforcer” and I was forced to show him the camera to check I did not take any picture. But otherwise it was very friendly place full of relaxed people. We bought one unspecified consumable souvenir which we consumed with pleasure right there. Then we left this place where law is different than in EU.

Second night we spent in Sweden, on some empty space by the sea. No one was there but pirate flag and toilets. Actually, we found out there are lot of places where caravans can stay overnight for free and they are always equipped by luxury toilets. We took advantage of them also following night when we slept on the best place so far – on beautiful island surrounded by other islands, right next to impressive bridge.

Because the core of our trip is Norway, we spent only one day in Sweden. To be more specific it was in Götteborg. Firstly, it is completely true that young swedish blond girls are amazing. All of them wear short jeans and they are nicely tanned (what I did not expect for such a northern country). And the city itself? I liked it, at least some hills compared to Copenhagen. We walked the centre where we took a ride on smaller version of London Eye, then visited Scandinavium – ice hockey stadium where Slovaks won gold in 2002. The last and best of Götteborg was visit of AtmosFear attraction in local amusement park which was basically 85 m high tower where we experienced several seconds long unforgettable free fall.

My knee is still not ok, sometimes I am nervous about it but I am trying not to care too much.

I already mentioned that sleeping is different that I am used to. I am actually looking forward my bed right now. But although it is not comfortable compared to staying in hotels / motels, this has very unique advandage to sleep almost anywhere we want. And we are more and more picky… if there is no lake, fjord or nice view, we are not staying.

Also eating is different, we are not visiting restaurants, because we have everything. But we have to eat some type of food quickly while it is ok… for example we have so many bananas which we have to eat quickly that we use them as threats and punishments (“wash dishes or you’ll have to eat a banana!” etc.).

The Scandi-trip continues in Norway (starts with Oslo) which I will cover later…

Categories: Travel Tags:

Sometimes simple program surprises me

December 18, 2010 3 comments

I was really surprised today by behavior of following simple program.

5+5=9? How come double happy string was de-duplicated?

static void Main()
    var original = new List<string>()   
        { "I", "wish", "you", "merry", "christmas"  };
    var additions = new List<string>()  
        { "merry", "christmas", "and", "happy", "happy", "new", "year" };
    var newAdditionsOnly = additions.Where(s => !original.Contains(s));
    PrintItems("original", original);                   
        // original has 5 items: I, wish, you, merry, christmas
    PrintItems("newAdditionsOnly", newAdditionsOnly);   
        // newAdditionsOnly has 5 items: and, happy, happy, new, year    
        // adding 5 items to original
    PrintItems("original", original);                   
        // original has 9 items: I, wish, you, merry, christmas, and, happy, new, year
static void PrintItems(string itemsName, IEnumerable<string> items)
    Console.WriteLine("{0} has {1} items: {2}", 
                      string.Join(", ", items));

After a while I realized what’s going on… can you see it immediately?

Categories: c# Tags: ,