KWrite

Rational Evolution

May 20th, 2010

Google versus Apple

http://eleganceit.com/blog/wp-content/uploads/apple-vs-google_2.jpg

Does it ring a bell?

Isn’t it similar to the war between Microsoft and Apple in the early 90s? While Microsoft focused on creating a platform and inviting hardware/software partners to develop on that platform, Appled tried to produce all-in-one products at its best. Apple had some revolutionary products at the time and they once were hugely successful. But it the end, you know who won the war.

It looks like that Apple is walking the same path. Steve Jobs is clearly obsessed with his idealistic philosophy. Perhaps the vision of Steve Jobs in 1997, shortly after he came back to Apple, is only temporary.

I predict that Google Android will leap over Apple iPhone anytime soon.

March 13th, 2010

“Bibles” in High Performance Computing

This is the continuation of my series “Bibles” in Applied Math. I write a new page for this section because it is a bit off from what most people call “Applied Math”. Further, this topic deserves a blog entry, or even a forum, on its own because being able to make your code run 10-15% faster (or even 90% faster if you haven’t mastered certain level of the art of programming) is a big deal nowadays. It can even land you a lucrative job (here’s an example).

Suppose that you’re a master of Numerical Algorithms. You’ve spent 2 years working on a complex engineering problem and recently have developed a new algorithm that can solve the problem in linear time instead of the state-of-the-art O\left(N\log N)\right). Your new solver (and the 2 years) would be wasted if it is poorly written and/or poorly compiled. Here are a couple out of thousands of common poor programming practices.

1. Computing the same thing over and over again

for (int k=0;k<100;k++) {
 out[k] = 0;
 for (int i=0;i<M;i++)
  for (int j=0;j<N;j++)
   out[k] += kernel(i,j) * in[k];
}

In this example, kernel(i,j) is re-computed 99 times. Because this matrix Kernel is independent from the outer loop, it can and most of the times should be pre-computed. If the computation of kernel is computationally intensive, which is common, pre-computation of the matrix can make your program run 99.9 times faster.

2. Using the right flags when compiling

[zer0ne@ion]$ g++ myProgram.cpp -o myProgram
[zer0ne@ion]$ ./myProgram
Total time: 68.74 seconds
[zer0ne@ion]$ g++ -O3 myProgram.cpp -o myProgram
[zer0ne@ion]$ ./myProgram
Total time: 13.9 seconds
[zer0ne@ion]$ g++ -O3 -DNDEBUG myProgram.cpp -o myProgram
[zer0ne@ion]$ ./myProgram
Total time: 11.54 seconds

So, if you’re already good at designing algorithms, it’s worth to learn a bit of performance optimization tricks. I am no expert in HPC, let alone related fields such as Computer Architectures or Compilers, so my best bet is to point you to some great books out there. Also for the same reason, I’ll appreciate if you share your own tips.

  1. Performance Optimization of Numerically Intensive Codes by Hoisie. $73 seems high for a 173-page book but this thin bible is worth every penny. It covers all basic stuffs such as CPU architecture, compiler optimization, memory localit, profiling, etc.
  2. High Performance Computing by Kevin Dowd & Charles Severance. Similar contents but this book explains things in greater depth.

May 28th, 2009

Wave: the new monster product of Google

The product hasn’t been released yet but you all can see the demo below.

In short, I bet anything that this product will revolutionize the way this world communicates, just like how emails triumphed over regular mails. The impact of this product can be as big as of Google Search. No joke!

March 27th, 2008

My favorite Firefox plugins

  1. Adblock Plus. Banners/ads on websites all look annoying. In many cases, they take a lot of time to load and can slow down your web browser significantly. Adblock Plus is a solution. It even kills text-based Google ads. Isn’t it nice?
  2. GreaseMonkey. This is actually the most powerful plugin if you’re willing to use it. Very simple, it’s basically a script manager. You can browse already written scripts here and add the ones you like to your GreaseMonkey or you can also write your own script. It is similar to the freeware autohotkeys in a sense.
  3. CustomizeGoogle.
  4. Google Search Keys. If you’re a geek who hates using mouse (or touchpad, trackpoint, etc.) but loves the search engine, you may love this lightweight plugin as well.
  5. Translator. Do you sometimes have to read French/German/Chinese webs? If so, use this plugin.
  6. Google Preview. It simply helps make web search more enjoyable.

What are yours?

March 15th, 2008

Why iPhone sucks

It really does!

  1. For Windows users, iPhone can only synchronize the contacts and calendar with Outlook (Express). This is very strange because Apple doesn’t seem to be a close friend of Micro$oft.
    • Corollary 1: for non-Outlook users, like me, iPhone is bloody sucky.
    • Corollary 2: even worse, it cannot synchronize with Google Calendar.
    • Conclusion: this limitation is really a big drawback of iPhone. Well, if I was a software engineer, I would have tried to write a patch for iTunes so that it can synchronize with Thunderbird (and Google).
  2. iPhone is not designed for Linux users. Why?
    • [Skip this item if you're not a programmer] As Linux and Mac OS share similar platforms, I was at first surprised why Apple developers don’t spend a few days tuning and compiling an iTunes version for Linux. Let’s dig a bit deeper. As I’ve just learned, while there’re some similarities between the two OS’s kernels, programming in Mac is quite different. Loosely speaking, Apple builds in Mac an object-oriented framework called Cocoa to utilize Mac’s *strengths*. The native language for this framework is Objective-C, which is not quite the same as C++. In one sentence, it’s not that easy to compile the source code of iTunes, written in Objective-C, in Linux.
    • It’s of course as hard or harder to rewrite iTunes for Windows. However, Windows has a much larger market share, which is worth the effort (even when there’s no such thing called iPhone). Moreover, only Windows/Mac users are hyped about the iPhone.
  3. It doesn’t have the push-email feature that Blackberry has. Being said, you have to check your email manually or to set iPhone to check emails periodically (every 15/30/60 minutes), which makes the battery life go down pretty fast.
    • This is the biggest drawback for a lot of users, especially corporate people. Blackberry currently dominates the smart phone market mainly due to this reason. As I’m writing this, Steve Jobs had already announced that push-email will be available on iPhone starting June 2008 [it's an entertaining presentation for iPhone developers].
    • However, frankly said, I don’t care shit about this feature as I would check my emails manually anyway. As a non-corporateman, I find email notifiers very irritating and time wasting.

Don’t get me wrong. That iPhone sucks doesn’t mean other devices don’t. In fact, all available mobile devices are far from being desirable, in one way or another. Weighing all the options, I still place iPhone as the top mobile device. It just has to improve much more to keep its top spot stable.

What struck me is that all the features above can be easily implemented, with some effort, but haven’t found their way to reality yet. I bet they’ll all be available within next year, after Apple releases their iPhone firmware 2.0 in 06/08.

March 2nd, 2008

Programming Tips (C++)

Since I’ve been back coding for the last few days, I’d like to save some useful programming tips that I’ve just figured out.

1. Linear Algebra package: use uBlas. uBlas, developped by Boost, is very object-oriented and easy to use. Not only does it support linear algebra, it also nicely supports sparse matrix storage and processing, which is important for iterative methods (when solving PDEs by Finite Difference or Finite Element). Take a look at my little program below, which constructs a sparse matrix when solving a boundary value problem.

Code:

#include <boost/numeric/ublas/vector.hpp>

#include <boost/numeric/ublas/matrix_sparse.hpp>

using namespace std;

namespace ublas = boost::numeric::ublas;const int N = 5000; // number of discretizations on each direction

typedef ublas::vector<double> Vector;

typedef ublas::compressed_matrix<double> Matrix; // Sparse Matrix class

void initializeMatrix(Matrix& A) {

    long k=0;

    for (int i=0; i<N; i++)

        for (int j=0; j<N; j++) {

            A(k,k) = -4;

            // adjacent elements in x-direction

            if (i>0) A(k,k-N)=1;

            if (i<N-1)

                if (i==0) A(k,k+N)=2; // Neumann condition on this side

                else A(k,k+N)=1; //Dirichlet condition on this side

            // adjacent elements in y-direction

            if (j>0) A(k,k-1)=1;

            if (j<N-1)

                if (j==0) A(k,k+1)=2; // Neumann condition

                else A(k,k+1)=1; // Dirichlet condition

k++;

        }

}

Drawbacks of uBlas

  • It has poor performance compared to (atlas-)Blas. One reason is that it is the most abstract linear algebra library (easier to use). Another critical reason is that it performs many *useful* (debugging) checks. The performance issue can be overcome through some optimization tricks, such as one that I described in the compiler section. Check out the effective uBlas wiki page for more performance tips. If performance is critical, consider binding with Atlas.
  • Poor documentation: if you’re used to Java’s API (which is terrific) as I was, using uBlas as first may be difficult because uBlas’s documentation is, now, quite short and lacks many details. The developers are working hard on it though. Moreover, they also maintain a main mailing list (and some other satellite sites) where you can ask questions.

2. Quant Finance Library: use QuantLib, the major open-source library

3. Compiler: when finished with your programming/debugging, consider using -O3 and -DNDEBUG for a much better performance (thanks to Tuyen). Most of the time, it optimizes the program significantly. Below is an illustration.

Code:

[khoa@trinidad]$ g++ myProg.cpp -o myProg

[khoa@trinidad]$ ./myProg

Total time: 68.74 seconds

[khoa@trinidad]$ g++ -DNDEBUG myProg.cpp -o myProg

[khoa@trinidad]$ ./myProg

Total time: 49.43 seconds

[khoa@trinidad courses]$ g++ -O3 myProg.cpp -o myProg

[khoa@trinidad courses]$ ./myProg

Total time: 13.9 seconds

[khoa@trinidad]$ g++ -O3 -DNDEBUG myProg.cpp -o myProg

[khoa@trinidad]$ ./myProg

Total time: 11.54 seconds

September 21st, 2007

The lecture of a lifetime

Intro: Once awhile, I introduced an inspiring commencement address by Steve Jobs (Apple’s CEO) at Stanford about life. Now comes another sensational one, also by a techie and also about life: the last lecture by Randy Pausch.

Randy Pausch is a highly respected Computer Science Professor at Carnegie Mellon University, mostly known for his work in Human-Computer Interaction.

Quote by WSJ

What wisdom would we impart to the world if we knew it was our last chance? For Carnegie Mellon professor Randy Pausch, the question isn’t rhetorical — he’s dying of cancer.

Note that the 3rd story of Steve is also about his struggling with cancer. Fortunately, he survived and then gave a speech about death. Randy gave words of wisdom knowing that he would die in a few months. Instead of talking about death, he talked about how he has “achieved” his childhood dreams, how he has enabled others achieve their childhood dreams, and how we achieve our dreams.

Read the rest of this entry »

March 31st, 2007

Random commands

In Terminal:

  1. Change the title of terminal tabs: PROMPT_COMMAND=’echo -ne “\033]0;$title\007″‘
  2. Tar with gzip: tar -czvf $archive.tgz $files
  3. Untar: tar -xzvf $filename
  4. Download a file from a url: wget $url

VI:

  1. Delete a line: dd
  2. Undo: u
  3. Redo: ctrl-r
  4. Move to [$] screen: [top]H, [middle]M, [bottom]L
  5. Move to line n: :n (for the last line of the file: G)

Google:

  1. Music Search: -inurl:(htm|html|php) intitle:”index of” +”last modified” +”parent directory” +description +size +(wma|mp3) “$songname

HTML:

  1. Embed mp3:<br><embed type=“application/x-mplayer2″ src=$urlheight=45 width=280 autostart=false></embed><br>
  2. Embed real:<br><embed type=“audio/x-pn-realaudio-plugin” src=$urlheight=45 width=280 autostart=false></embed><br>

Windows File Sharing: http://handson.ca/tutorials/sharexpp.html

January 18th, 2007

Steve Jobs and his iPhone

Earlier yesterday, I watched Bill Gates’ keynote address given at the International CES 2007. It was indeed a great show. If you follow it until the end, you’d probably agree with me. Then, I turned to see Steve Jobs’ keynote given at the Macworld Conference 2007. I was completely thrilled by Steve and his iPhone. It was a really long presentation: 2 hours. If you often attend presentations or at least scientific presentations, you know that 30 minutes are usually enough for you to fall asleep. But, his introduction of the iPhone is different. It will keep you interested all the way to the end.

Recently, I have developed an admiration for Steve Jobs due to his way of business, his experience, and his extraordinary public speaking skills (although like Bill, he dropped out of college after 1 semester). Another classic example is his commencement speech in 2005, which inspired a a crowd of Stanford graduates and probably would change the way many of them see life.

You need to a flashplayer enabled browser to view this YouTube video

His 1997 Macworld Conference keynote is also a masterpiece. Seriously, this 10-years-old talk has changed my attitude toward Apple’s human capital and future Apple products.

It’s not a bad idea to compile a list of top 10-20 Steve’s presentations. I’d be interested in seeing such a list.

|