Sunday, March 7, 2010

Compiling Google-protobuf without pthreads on Linux

Here is simple tutorial how to create libprotobuf.a that does not require linking with the pthread libraries.

libprotobuf does not support linking with single threaded application, but sometimes it is necessary to do so. Unfortunately it is not possible to do this without some slight modification of the code, but the number of necessary modifications is very small. Only the following four files in src/google/protobuf/stub need some a slight addition: once.h, once.cc, common.cc and once_unittest.cc

A modified package for libprotobuf-2.3.0 can be downloaded from here:

http://metamatix.org/~chris/protobuf-2.3.0-with_single_thread_support.tgz

To make this package work as expected the following three important points should be observed:

  1. -D_SINGLE_THREADED must be appended to the content of the CXXFLAGS environment variable in the shell before running configure.
  2. Use the command ' make PTHREAD_CFLAGS="" ' for building the libprotobuf package.
  3. You project should also be compiled using the -D_SINGLE_THREADED compilation flag and include the modified libprotobuf header files. (for example by appending -I/path/to/modified/libprotobuf/src). Of course the modified libraries should be linked as well (they are stored in .libs subdirectory of the project or at the location specified by the --prefix flag to configure after the project is installed.)

Sunday, May 31, 2009

The Price of Abstraction

The purpose of using using higher level programming languages is to be able to use higher level of abstraction in order to make code more readable and reusable. However, added levels of abstraction usually results in loss of efficiency (speed, memory or both).

This posting is a small case study on three different programming languages (OCaml, Scala and C++) comparing this hit on the running time as the level of abstraction and genericity increases. To highlight the overhead I chose a task which is CPU bound an where the relative overhead of abstraction (when introduced) is as high as possible. So this example can be viewed as a kind of worst case scenario.

The results can be read here

Thursday, May 21, 2009

A Spiritual Explanation to the Fermi Paradox

Where are our extraterrestrial friends? - asks the Fermi paradox.

If there are other intelligent civilizations, should not we have detected at least one of them?

According to the current state of astronomy, earth is relatively young. There are a lot of earth-like planets and several of them must be much older then ours. Just in our galaxy, there should be billions of them. Even if only a few civilizations would have managed to spread, they should be much more advanced than ours and be easily detectable by our equipments.

Still, we have not detected anything. Why?

Of course the most obvious explanation is that there are no interstellar civilizations in our vicinity. Maybe not one in our galaxy. Why is this strange? If only one single advanced civilization would have preceded us, it would probably be able to spread by 1/100th of the speed of light. Assuming that the colonization of a planet and setting up factories to produce star ships takes around 1000 years, it would have taken a couple of millions of years to spread to and colonize most of the Milky Way. This sounds like a lot of time, but even 100 millions of years are just 2% of the lifetime of the Earth. Since there are a lot of earth-like planets in our galaxy, a lot of them twice as old as our planet, should not we see traces of extremely advanced civilizations spread across our galaxy?

The most popular answers to this questions are the following:

1) It's highly improbably for intelligent life to emerge
2) If civilizations reach a certain sophistication, the risk of self destruction (by wars, runaway bio/nanotechnology.) becomes very high.
3) Advanced civilizations are hard to detect.

Can there be other explanations besides the above? Here, I elaborate on a fourth hypothesis.

First, just revisit the human history. The basic underlying principle of our world view was always human centered: that our species fulfills a special important purpose and that we are somehow important and valuable in the grand scheme of things. Our science and religions always assumed that we and our planet is somehow central. As our knowledge grew, it turned out that it was wishful thinking. We thought our planet to be the center of the universe, then we moved to a heliocentric view. Later we assumed our solar system to be near to the center of our galaxy.

It turned out to be incorrect all along: Our place in Universe seems to be completely random and insignificant. In fact, our planet is just a piece of dust compared to our own galaxy, which is only one of many billions.

Of course, we still did not give up our pioneering spirit: humanity still believes in conquering the skies and thinks of our Universe as a God-given playground for us.

However, as our science and knowledge progresses, we may learn a lot about our Universe. Maybe there is some real purpose to its existence. Maybe there is a creator or just some deep and important meaning to our physics which we will be able to decipher some day. If humanity will somehow survive the next centuries, we will get much closer to see some patterns and get a lot of explanations to the very nature of our Universe.

What are the chances that we were utterly wrong about the role we play?

Can't it be that we are just some random artifacts, not just irrelevant but even contra-productive to the real purpose of our world? What if we recognize that we are just parasites in a beautifully constructed machine which has a well-defined and decipherable purpose?

After progressing awhile, we may reach a certain technical and spiritual excellence, where we are not only clever and resourceful, but also wise. What would our wisdom tell us, if we recognize that we are just a fluke in a fantastic and beautiful entity.

What would humanity do if it recognizes that our role here is just that of a virus infecting an otherwise healthy and magnificent organism?

Would we still want to spread, if we would recognize we are nothing but cancer?

Who knows, maybe these were the questions that our hypothetical advanced and wise extraterrestrial friends had to ask themselves at some point back in time...

Tuesday, January 29, 2008

A Scientific Dissent from Newtonism

We are skeptical of claims for the ability of force fields in a 3 dimensional space to account for the dynamics of universe. Careful examination of the evidence for Newtonian theory should be encouraged.

I wonder if Einstein would have agreed with the above statements. It may not be too far fetched to assume so. Still, would have been probably wise enough not to sign such a statements if the Pope had circulated it. Not because anything is particularly wrong about examining the evidence for any Theory, but because superficial observers may draw wrong conclusions about his stance. Some may even think that he believes that the Sun orbits the Earth and would use his consent to argue against teaching classical mechanics in school.

Actually I have to revise some of the above statements: I think that there are theories (like the so called theory of intelligent design) that are so absurd that no sane scientist would agree on the need of examining the evidences for it. There has to be certain trust in a theory before it deserves such a statement.