Wednesday, January 30, 2013

HPC Contest IIT Kanpur: Analysis

IIT Kanpur saw its first high performance computing contest last weekend.

Contest duration : 24 hours
Number of Problems : 3
Maximum number of compute processors available : 6

1st - Team TafriBAAZ - Sumit Kumar ,Suyash Garg, Niraj Kant Sinha
2nd - Team JONAM - Manoj Chandrasekaran

The problems were designed to test some of the basic concepts of Parallel Computing.

Problem A: Vector addition
Concept: Data Redistribution

Add 2 vectors of N dimensions for T test cases and print the resulting vector.

Sample Input:
1 1 2 3
2 3 4 1
1 2 3 4 5
5 4 3 2 1

Sample Output:
3 4 6 4
6 6 6 6 6

The solution code is Here.

Problem B: Mersenne Prime

Concept: Parallel Search

There are some prime numbers p for which 2p-1 is also prime. We define 2p-1 as a Mersenne prime number and p as the Mersenne prime exponent. For eg. lets take p = 2 then 2p-1 = 3 is also prime, we call 3 as a Mersenne prime number and 2 is a Mersenne prime exponent. In the given sequence of integers find the first occurrence of a Mersenne prime number or a Mersenne prime exponent.

The first line contains an integer T (1<=T<=102), the number of test cases. The second line contains an integer, n (1<=n<=106). It is followed by one line containing a sequence of n space-separated integers (all integers are less than 2*107).

For each, test case output a single line containing the first occurrence of a lucky prime number or a lucky prime exponent in the sequence. Separate test cases with a new line.

Sample Input
14 586 1279
8191 3 19

Sample Output

In the first case 1279 is a Mersenne prime exponent.
In the second case 8191 is a Mersenne prime.

To get the solution code of more generic prime search problem click Here.

Problem C: Median
Concept: Parallel Selection

The median is described as the number separating the higher half of a sample, a population, or a probability distribution, from the lower half. The median of a finite list of numbers can be found by arranging all the observations from lowest to highest value and picking the middle one. If there is an even number of observations, the median is the mean of the two middle values.
For example:
1,2,3,4,5 : The median is 3.
1,5,9,2,8,4: The median is 4.5.

Visit this link for the solution algorithm and try implementing it as it will not be difficult if you can understand the solutions provided above.

Endnote: This contest was just a primer to the 1st International High Performance Computing Contest which will be organised in Techkriti'13.
Click here and follow our G+ page to get latest updates.

MPI Parallel Search - Prime

The following code prints the first prime number occurring in the array.

MPI Vector Addition

The root and other process codes can be clubbed together, but in this code root has been treated separately so as for better understanding.

Wednesday, January 23, 2013

Stalkbook Graph Search : Zuckerberg

To : "Mark Zuckerberg" <>
From : "Pappu Jigyasu" <>
Subject : Fb Graph Search Guide (for Stalkers)

Hi Zuck,

My name is Pappu, and I am a crushaholic. First of all I want to thank you for creating Facebook where I can sit online for hours and stalk pretty girls. Acquiring a new infatuation every split second. Moreover, I'm infatuated with infatuation, the way a new object of affection makes my stomach flip. Don't misunderstand me; I'm not talking about some desperate, obsessive, "I want to marry you and I can die for you" kind of love. I'm just an old-fashioned boy who silently loves the thrill of the chase.
Recently, you launched the Graph Search. I saw the demo and was really fascinated by the idea. But, somehow I feel the demo was incomplete. Can you please throw some more light on the tremendous potential of the Graph Search. It would be really helpful for guys like me.

Pappu Jigyasu
Pritampyaare Institute of Technology, Mayapur

---------------------------- 2 days later ------------------------------

To : "Pappu Jigyasu" <>
From : "Mark Zuckerberg" <>
Subject : Re:Fb Graph Search Guide (for Stalkers)

Hi Pappu,

Glad to know that you have recognized the true potential of Facebook. Let me go back in time and tell you the most fundamental idea or should I say the core concept behind creating Facebook -
Make the World more open and connected.

And those who benefit from this mission are people like you and me - Stalkers.

I invented Facebook to get back at the girl who dumped me, but it turned out to be a hugely successful social network. Honestly speaking I am still distracted by the lack of a "Friend" response from that girl.
"She hasn't accepted it, but she hasn't rejected it either." 
So all I can do is play around with the Privacy Policy of FB and find better ways to stalk her.

Now coming to the Graph Search.

The Facebook Graph is big, very big. And a huge chunk of our user base always complain why we emphasize so much on privacy. But, we are least bothered about it. It's just a mask to hide what we are underneath - crafty, cunning, silent stalkers.

If you are wondering that the idea of Graph Search is new then you are mistaken - it isn't, as none of our ideas ever are. We are always on the lookout for inspiration, be it the Snapchat rip-off Poke or the Twitter-style Ticker. Even the idea of Facebook wasn't my intellectual property.

These things hardly matter as long as you like looking at the profiles of people you don't know that well on Facebook, don't you? Of course you do, because we're all sick and it's fun. A few months back I started gathering a list of everything you search for on FB and it was for your own benefit as now there is no need of remembering the names everyday. Even the Ticker's true intention was to provide you with the pictures of hotties your friends liked on the fly.

Sometime in not so distant past a MIT graduate Oliver Yeh built a service called Stalkbook that caught my attention. He claimed that it allowed you to stalk people on Facebook even if you're not friends with them on the social network. Yeh had a simple but malicious trick: he used other Facebook users' credentials to view whichever profile you wanted to stalk.
When I went to the site, typed in my name ("Mark Zuckerberg") and clicked "Stalk," I was greeted with the following message: "Stalking is considered to be morally wrong. Why don't you try talking to the person instead." Stalkbook wasn't released publicly, but Yeh demoed it to me personally.
Yeh even explained in further detail how Stalkbook worked:
So, the photo version works by whenever a person signs on to the application; not only does he reveal his or her own information but he also compromises all of his or her friends' information too. So for example, if I sign on to the site, then my friend Ursula would also be signed on to the site because I'm friends with Ursula. And because with my credentials, I can see her information. Now, everyone on the Internet can also see her information by using my credentials. And as more people sign up to Stalkbook, you get this network effect, in which you only need perhaps 10 percent of Facebook to join to compromise 80 to 90 percent of Facebook.
If that's a bit too complicated for you, this diagram should simplify it:

He did all that with Facebook API -- which is software we developed so that third-party developers can access Facebook's information, which was very depressing as I never came up with this idea.
No worries.
I banned Stalkbook as it goes against Facebook's terms of service (Statement of Rights and Responsibilities which I made). In the Safety section of Facebook's TOS, point number five clearly states: "You will not solicit login information or access an account belonging to someone else."
A user's friends' data can only be used in the context of the user's experience on your application.

These are my rules and only I have the right to break it. So we came up with our own Graph Search.

Now, coming to your question
'What can Graph Search do?'

and 'How can it benefit the stalkers?'

To give you a sense of the stalking that ‘Graph Search’ enables, here are a few potential searches which you can try out using the Graph Search Beta I activated on your Facebook account.

Let's begin with some simple searches-

"My single female friends"

"Photos of my single female friends"

"Photos of females liked by men"

Lets make it a bit complicated-
"Photos of my female friends who are single and live in mayapur"

Or if you have a friend who is quite good at stalking himself. You can try out :
"Photos of females who posted photos liked by X" (where X is the persons name)

"Photos of females who live in X liked by Y"

"People who live in X and work for Y are single"
"Female friends of X who are single."
If X is a female you will definitely get better search results or just add some famous folk of your college and enjoy.

But, this is not 'the thing'.
I have even greater plans to be a step ahead of Google.
Before Google launches - Google Matrimony, I am planning to integrate the feature of match making in Facebook and Graph Search is just the beginning.

"My single female friends who are over 25 years old and less than 27 years old"

"Female friends of my female friends who are less than 27 years old and who study Economics and live in Delhi, India "

Once people start using it for match-making purpose, I'll start charging them a nominal fee per search just like I did for Pages. But, till then you can enjoy the beta version and if you discover some innovative ways to stalk people on Facebook, do tell me.
I shall be more than willing to add it to the documentation.

Mark Zuckerberg

Saturday, January 5, 2013

Supercomputing Workshop for IHPC

You can find the important parts of the lecture below.

The Codes are given below:

MPI Hello World - 1
MPI Hello World - 2
MPI Pi Calculation

Join our discussion group asap:
HPC IIT Kanpur
Follow our page to stay updated:

MPI Pi Calculation

This Program for Pi calculation depicts the usage of MPI_Wtime, MPI_Bcast and MPI_Reduce.

MPI Hello World - 1
MPI Hello World - 2

MPI Hello World - 2

This MPI program illustrates the use of MPI_Send and MPI_Recv functions. Basically, the master sends a message, “Hello, world”, to the process whose rank is 1, and then after having received the message, the process prints the message along with its rank.

Compile it using

Execute it using

MPI Hello World - 1
MPI Pi Calculation Lecture

MPI Hello World - 1

Here is the Hello World Sample.

Compile it using

Execute it using

Here is the Hello World Sample for Python. You cannot execute it in CC server but you can install the mpi4py module on your workstation

Execute it using

MPI Hello World - 2
MPI Pi Calculation