Archive

Archive for the ‘Reviews’ Category

Good articles in life hacker


Boring free times can be replaced with good reads in lifehacker and other good sites. The following are the few articles I personally cherished reading.

http://lifehacker.com/top-10-reasons-to-exercise-regularly-besides-losing-we-1473616982

http://lifehacker.com/train-your-brain-to-think-like-a-creative-genius-1509738599

http://lifehacker.com/why-exercise-helps-you-think-straight-557945206

http://lifehacker.com/how-to-build-your-confidence-and-why-it-matters-1442414831

http://lifehacker.com/why-you-should-track-your-efforts-not-your-achievement-1355909784

Advertisements

Aparapi + Java + OpenCL


Since I’m working on OpenCL project, I was very curious to know, how to reduce the number of lines of code to be written for any program in OpenCL. While searching for the way to reduce the code I came to know the release of Aparapi.

It is an  API for expressing data parallel workloads in Java and a runtime component capable of converting the Java bytecode of compatible workloads into OpenCL so that it can be executed on a variety of GPU devices.

Some cool features of Aparapi are

* No need of thinking of explicit data transfers between host program and GPU kernel(If required you can do for the improvements purposes)

* No need of querying for the platform, devices

* No need of creating context and managing command queue

* No need of writing code for creating buffers

* No need of setting kernel arguments explicitly

* No need of using enqueNDRange()  and remembering so many parameters to set the globalThreads and localThreads and dimensions

* If GPU is not found still the Aparapi transforms the kernel code to use either JTP(Java Thread Pool) or CPU. Its not required to check explicitly if GPU is present or not and no need of explicitly creating threads to manage data parallelism.

* No need to learn C99 OpenCL C to write Highly data parallel applications

* Fast learning curve

*Aparapi is an open source project

Limitations of Aparapi

How ever Aparapi is having a lot of advantages there are some limiataions

* Cannot support local memory(Huge optimization loss here)

* May not reach the highly optimized openCL C wrapper performance for complex mathematical operations

Notwithstanding, no support for local memory Aparapi is great to use because most of the data parallel applications written in Java can hugely benefit from usage Java based Aparapi.

Aparapi Download link

Aparapi Getting Started

Installation Notes

Note: All the views presented here are just subjective and my personal perceptions. If there any thing wrong or I’m not updated with the future releases please notify me.

Thanks for reading!!

Interview C puzzles


Here I want to share some of the simple & tricky C puzzles and interview questions I faced.

1) Write single line swapping function

Ans:  Check here for Python code

  Please check here for C code

2) Write single line macro to swap two numbers 


#include< stdio.h >

#define swap(a,b) b=(a+b)-(a=b)

int main(void)
{
    int a=12;
    int b=-34;
    printf("Before swapping a=%d, b=%d\n",a,b);
    swap(a,b);
    printf("After swapping a=%d, b=%d\n",a,b);
    return 0;
}

3) Write a macro to check whether a given number is a power of two or not


#include < stdio.h >

#define isPowOf2(x) ( ( x & ( x - 1 ) ) == 0) ? 1:0

int main(void)
{
    if(isPowOf2(4))
   	 printf("It is power of two\n");
    else
   	 printf("It is not power of two\n");
    if(isPowOf2(41))
   	 printf("It is power of two\n");
    else
   	 printf("It is not power of two\n");
    if(isPowOf2(64))
   	 printf("It is power of two\n");
    else
   	 printf("It is not power of two\n");
    if(isPowOf2(400))
   	 printf("It is power of two\n");
    else
   	 printf("It is not power of two\n");

    return 0;

}

4) Write code to swap two numbers with out using temporary variable and  using shifting operators

Ans: Please check here

5) Write a function to round off a given float/double to the nearest integer

#include < stdio.h >

int Myround(double n)
{
    return (int)(n+0.5);
}
int main(void)
{
    printf("%d\n",Myround(25.7));
    printf("%d\n",Myround(25.2));
    printf("%d\n",Myround(25.6));
    printf("%d\n",Myround(25.9));
    return 0;
}

5) Write a one line macro to round off a given float/double to the nearest integer

Ans: same as above
#define myround(a) (int)(a+0.5)

6) Write a function to print binary representation of a given integer

#include < stdio.h >

int binaryRep(int n)
{
    int i=0;
    for(i = sizeof(int)*8 - 1;i >= 0; i--)
    {
   	 if( ( n & (1 << i ) ) > 0 )
   		 printf("%d", 1);
   	 else
   		 printf("%d", 0);
   	 if(i%4==0)
   		 printf(" ");
    }
}

int main(void)
{
    binaryRep(10);
    printf("\n");
    binaryRep(100);
}

7) Write a macro to check whether a specified bit in a number is on or off

#include < stdio.h >

#define onROff(n,i) ( (n & (1 << i-1)) > 0 ) ? 1 : 0

int main(void)
{
    if(onROff(15,1))
   	 printf("first bit is on\n");
    else
   	 printf("first bit is off\n");

    if(onROff(15,2))
   	 printf("second bit is on\n");
    else
   	 printf("second bit is off\n");

    if(onROff(15,3))
   	 printf("third bit is on\n");
    else
   	 printf("third bit is off\n");

   return 0;
}

8 ) Write a macro to switch On a bit in a given number

#include < stdio.h >

#define switchOn(n ,i) n|=(1 << (i-1))

int main(void)
{
    int n=10;
    switchOn(n,1);
    printf("After switching on first bit of n=%d\n",n);
    switchOn(n,3);
    printf("After switching on third bit of n=%d\n",n);
}

9) Write a macro to switch Off a bit in a given number


#include < stdio.h >

#define switchOfff(n,i) n = n & (~ (1 << (i-1) ) )

int main(void)
{
    int n=15;
    switchOfff(n,1);
    printf("After switching off first bit n=%d\n", n);
    switchOfff(n,2);
    printf("After switching off second bit n=%d\n", n);
    switchOfff(n,3);
    printf("After switching off third bit n=%d\n", n);
    switchOfff(n,4);
    printf("After switching off fourth bit n=%d\n", n);
    return 0;
}

Some of the following questions can be applications of the above specified bit wise operators and other programs specified in this blog. Some of them cab be easily found in the web. I wish all the best for your technical C interview.

10) Write a macro to reverse a bit at a given position

11) Write a function to display binary representation of a given floating/double number

12) Write a function to find the largest sum of  a sub sequence of an array.

ex: { 1 , – 4, 5, 7}

in the above example the highest sum sub sequence is {1,5,7}. If all the elements in the array are +ve then  the whole array itself is the largest sum subsequence. But the given array contains some -ves also.

13) Write a program to mirror a binary tree

ex: Here we have to mirror the whole left sub tree with right sub tree and right sub tree with the left one

14) Write DFS with out using recursion

15) How best (time complexity in Big – Oh )you can write an algorithm which finds the first repeated value in a sorted  array.

16) Write an algorithm which sorts an array with time complexity less than O(nlogn) 

Hint: Take some assumptions and solve

17) Write an algorithm for finding a given string in a file and replacing it with a replacement string

ex:    findAndReplace(FILE *fp, char * findString, char * replaceString)

18) How to find size of a structure / data type with out using sizeof operator

Hint: Use pointers and arithmetic operations principles

19) How do you develop a object collector in C (like one in Java)

20) Find the first repeating character in a string. Constraint use only O(n) time complexity and O(1) space complexity

21) Write BFS using recursion

22) Find the middle of a linked list

23) How do you find last but one and third from last in a linked list

24) How do you find a loop in a linked list

Hint: For the above three linked list questions you can use the concept of fast * pointer and slow * pointer

25) Write Ceil function with out using any comparison operators

26) Reverse a linked list using recursion and with out using recursion

27) Longest continuous sequence

28) All the subsets in a given array (Out put should have 2 ^ n entries)

Web 2.0 vs. Web 3.0 by Eric Schmidt


Here is the video which depicts the concept of web 2.0. The CEO of Google explains the term Web 2.0.

NITK Youth Program, Swamy Vivekananda Jayanthi


Yesterday was swamy Vivekananda’s birthday which is considered as Youth day. It is so because he always preached about the youth, he knows the very fact that India is having the most youth power than any other country has, and the youth is power, the vigor of which can transform anything and everything.

As a part of this auspicious day, Two swamis from Ramakrishna math visited NITK. Both speeches of them were highly inspiring, but one story was really thought provoking. The story goes on like this

One of the friends of Swami lived in Tokyo of Japan for the training. He used to live in the nearest village due to high cost of living of Tokyo. He used to travel by train, One day it was so happened that in his compartment one old lady had come and sat. Suddenly he noticed something strange, The lady pulled out  needle and string and started sewing torn seat. He thought she might be a worker of railway department, so out of curiosity he asked “Haven’t you retired yet?” She replied “10 years back”. He then asked “How many years have you worked in railway department?” She strangely replied “No” I haven’t t worked for the railway department. He then asked, I noticed you sewing the seat I thought you might be an employee of railway department she told once again “No”. He then went on asking “Why have you sewed the seat? Won’t you feel shy?” She replied with a smile on her face. “This train belongs to Japan and I belong to Japan” Swami went on explaining the moral of the story. The story tells about the belongingness of being a part of a country.

It doesn’t require any other reasons for How Japan become developed country with in a very short span.

We all belong to India but we need to question ourselves how far we have felt. We too should have the belongingness of being part of our country which has great culture of being in harmony of different cultures, great wisdom of existing Vedas, great heart of accepting every religion as its own.

2010 in review


The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

Healthy blog!

The Blog-Health-o-Meter™ reads Wow.

Crunchy numbers

Featured image

A Boeing 747-400 passenger jet can hold 416 passengers. This blog was viewed about 3,600 times in 2010. That’s about 9 full 747s.

In 2010, there were 63 new posts, not bad for the first year! There were 31 pictures uploaded, taking up a total of 10mb. That’s about 3 pictures per month.

The busiest day of the year was June 14th with 282 views. The most popular post that day was Programming/Coding .

Where did they come from?

The top referring sites in 2010 were en.wordpress.com, twitter.com, facebook.com, bigextracash.com, and jutawan-paypal.blogspot.com.

Some visitors came searching, mostly for adjacency list java, java magic square, vasanth experiments, magic square table in java, and vasanth raja.

Attractions in 2010

These are the posts and pages that got the most views in 2010.

1

Programming/Coding June 2010
4 comments

2

Java Program to construct the Magic Square October 2010
2 comments

3

Adjacency list represention of graph in Java October 2010

4

About Me June 2010

5

Reviews June 2010

Categories: Reviews, Technology

Stephen wolfram computing a theory of everything


http://www.wolframalpha.com/ is one of the finest creation. This search engine takes the queries and tries to find lucid and crisp results. It is very easy to find answers to your question if the data is already available to Woframalpha. There is a lot much improvement can be done to Wolframalpha, but, even for now it has a lot of sophisticated algorithms working behind the scenes. The video is related to wolframalpha and I liked this video.