Wednesday, May 16, 2012

Install Contiki 2.5 on ubuntu 11.10

  • Contiki – a dynamic operating system for networked embedded systems
  • Loadable modules, multiple network stacks,
  • multiple threading models
  • Open source; 3-clause BSD licence
  • Small memory footprint
  • Designed for portability
Here I will explain you how to install it manually in Ubuntu 11.10. (This method works for any ubuntu distribute and any contiki distribute). You can use Instant contiki Instead of this method.


1. Install msp430 tool chain. Type this command in terminal

sudo apt-get install binutils-msp430 gcc-msp430 msp430-libc

2. Install the AVR tool chain. Type this command in terminal

sudo apt-get install gcc-avr binutils-avr gdb-avr avr-libc avrdude

3. Now you need JRE and JDK. Ubuntu is not providing sun java repositories now. So you can install openjdk as a substitute for it (Works well). Use this commands to install.

sudo apt-get install openjdk-7-jdk openjdk-7-jre

4. Then you need to setup JAVA_HOME and PATH environment variables. Refer this link to setup java path. Or if you need to install sun(oracle) java refer this link.

5. To run cooja simulator you will need Ant. To install it type this command in the terminal. 

sudo apt-get install ant

6. Then you need to download contiki source code. Use this sourceforge link to download it. You can select what version you like.

7. Ok now you have installed enough sufficient tools to run contiki. Unzip the contiki2.5.zip and change directory in to it. Then you need to go in to Examples/Hello-world. 

8. Type this in terminal. make TARGET=native hello-world. If no error occur type this in terminal. ./hello-world.native. If you get this out put, you just say hello to contiki world, congratulations. 


9. Now you need to check your program in cooja simulator. Run this commands. 

$cd contiki-2.5/tools/cooja
$ant run

Then cooja simulator will be opened. Follow the instructions on the website that I linked. 

10. Then you need to check your program in mspsim simulator. 
Here I used my own simple code to check mspsim.

$cd contiki-2.5/Examples/blink
make TARGET=sky blink.mspsim

Here is the screen shot of what I get


Ok. Now you correctly and manually installed contiki 2.5 in ubuntu.  

P.S
If you get an error on step 9 and 10 (this occurs when using msp430 micro controller chips,Avr do not have this issue) that is msp430 tool chain problem in ubuntu (sys/unistd.h missing). There is a naive method to solve it. Its very simple than change your operating system to ubuntu 11.04 or use instant contiki. You need to download this file. Then you need copy that file in to/usr/msp430/include/sys. 

To do it run this command. 
sudo cp unistd.h /usr/msp430/include/sys

Ok then your problem should be solved. 

Again I have to ask you, are you getting this kind of error? 
"/core/dev/ds2411.c:199: undifined reference to 'BV'."

Add these lines to following file. 

#define _BV(bitno)   1<<bitno   
#define BV(bitno) _BV(bitno)

contiki-2.5/platform/sky/contiki-conf.h 

Ok. I think you are now free to do any development using contiki.

Wednesday, May 2, 2012

ElGamal example over GF(11) field

 This very simple example of ElGamal with small field. It's highly recommended that use large fields.
  • Our group is GF(11) = {1,2,3,4,5,6,7,8,9,10}
  • Lets take n = 10 and  α = 2. Bob randomly select b = 5 then αb =25 = 10.Have public key (n,α,αb) = (10,2,10) and private key b = 5.
  • Alice chooses k = 7 and calculates αk = 27 = 7.
  • Alice looks up αb = 10 and encodes message as m = 3 then calculates           m(αb)k = 3 * 107 = 8.
  • Alice sends (αk,mαbk) = (7,8).
  • Bob Calculates mαbk((αk)b)-1 = 8(75)-1 = 3.
  • Thus Bob receives the message, 3, as sent by Alice
You need some idea about finite fields and modular arithmetic

Saturday, March 31, 2012

Hardware for Parallel Processing

1. Multi-tasking Single Processor Computer


Multiple processes can be run on a time-shared manner on a general single processor computer. Difficult to get a speed-up unless while one process is doing computing the other processes are involved input/output for example.


2.  Shared memory computers 


       2. 1 Multiprocessor Configurations (SMPs: Symmetric Multiprocessors)

SMP involves a multiprocessor computer hardware architecture where two or more identical processors are connected to a single shared memory and are controlled by a single OS instance.In an SMP multiple identical processors share memory connected via a bus. Bus contention prevents bus architectures from scaling. As a result, SMPs generally do not comprise more than 32 processors.

       2. 2 Hyperthreading (Simultaneous Multithreading [SMT])

With HT Technology, two threads can execute on the same single processor core simultaneously in parallel rather than context switching 1 between the threads. Scheduling two threads on the same physical processor core allows better use of the processor’s resources. HT Technology adds circuitry and functionality into a traditional processor to enable one physical processor to appear as two separate processors. Each processor is then referred to as a logical processor.

       2. 3 Dual Core

This term refers to integrated circuit (IC) chips that contain two complete physical computer processors (cores) in the same IC package. Typically, this means that two identical processors are manufactured so they reside side-by-side on the same die. It is also possible to (vertically) stack two separate processor die and place them in the same IC package. Each of the physical processor cores has its own resources
(architectural state, registers, execution units, etc.).

        2.4 Multi Core

The multi core system is an extension to the dual core system except that it would consist of more than 2 processors. The current trends in processor technology indicate that the number of processor cores in one IC chip will continue to increase. If we assume that the number of transistors per processor core remains relatively fixed, it is reasonable to assume that the number of processor cores could follow Moore’s Law, which states that the number of transistors per a certain area on the chip will double approximately every 18 months. Even if this trend does not follow Moore’s Law, the number of processor cores per chip appears destined to steadily increase - based on statements from several processor manufacturers. 

        2.5 Many Core

Many core is a multi-core processor in which the number of cores is large enough that traditional multi-processor techniques are no longer efficient largely because of issues with congestion in supplying instructions and data to the many processors. The many-core threshold is roughing in the range of several tens or hundreds of cores. 

        2.6 Graphics Processing Units (GPUs)

Graphics cards (often having 100+ processor cores) and a rich structure of memory that they can share is a good general purpose computing platform. Each processor can do less than your CPU, but with their powers combined they become a fast parallel computer.
  
3. Distributed Computing

A distributed computer is a distributed memory computer system in which the processing elements are connected by a network. Also known as a distributed memory multiprocessor or multi computer.  


        3.1 Cluster computing

A cluster is a group of loosely coupled computers that work together closely, so that in some respects they can be regarded as a single computer.Clusters are composed of multiple standalone machines connected by a network. While machines in a cluster do not have to be symmetric, load balancing is more difficult if they are not. The most common type of cluster is the Beowulf cluster, which is a cluster implemented on multiple identical commercial off-the-shelf computers connected with a TCP/IP Ethernet local area network.

        3.2 Massively parallel processing

A massively parallel processor (MPP) is a single computer with many networked processors. MPPs have many of the same characteristics as clusters, but MPPs have specialized interconnect networks (whereas clusters use commodity hardware for networking). MPPs also tend to be larger than clusters, typically having ”far more” than 100 processors. In an MPP, each CPU contains its own memory and copy of the operating system and application. Each subsystem communicates with the others via a high-speed interconnect.

         3.3 Grid computing

Grid computing is the most distributed form of parallel computing. It makes use of computers communicating over the Internet to work on a given problem. Because of the low bandwidth and extremely high latency available on the Internet, grid computing typically deals only with embarrassingly parallel problems. Most grid computing applications use middleware, software that sits between the operating system and the application to manage network resources and standardize the software interface. Often, grid computing software makes use of ”spare cycles”, performing computations at times when a computer is idling.


Note: Please do not make conflicts between these general terms with commercial terms. (i.e intel dual core, core 2 duo)




Wednesday, August 17, 2011

Reinstall missing Grub after install Windows


When you are install windows after installing ubuntu linux version on your pc, no need to install ubuntu linux version again. Follow below instructions to recover grub easily.


1. Boot your computer from Ubuntu live CD


2. Go Places->My Computer


3. Click on the partition you installed ubuntu operating system. Then it will mount.


4. Get the terminal


5. Type this commands in the terminal


    $mount | tail -1


6. You will get result like below


    /dev/sda6 on /media/0d104aff-ec8c-44c8-b811-92b993823444 type ext4 (rw,nosuid,nodev,uhelper=dev


7. Then type this


    $sudo grub-install --root-directory=/media/0d104aff-ec8c-44c8-b811-92b993823444 /dev/sda


(bold texts must be the same)


8. Then Reboot the machine. Here is the command "sudo shutdown -r now" without quotes.


9. Now you can see the grub, but sometime your windows entry may not work. Then go to ubuntu, get the terminal, type this command. You have to provide your password here.


$sudo update-grub


10. End of Task...


Sinhala version

Running an Executable and Collecting the Output using C#

Sometimes you may need in the middle of a C# application you want to run an executable and collect the output.  Below sample of code will do what you want.. 

1. Simple method:

 

Process P = Process.Start("eyeDetect.exe", "hello1.jpg haarcascade_frontalface_alt.xml haarcascade_eye.xml");
P.StartInfo.UseShellExecute = false;
P.WaitForExit();
int result = P.ExitCode;
Console.WriteLine("Here is my result " + result);
Console.ReadLine(); 

2. Descriptive Method:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class Program
    {         
        static void Main(string[] args)
        { 
            StringBuilder Output = new StringBuilder(); 
            using (Process proc = new Process())
                {
                    proc.StartInfo.FileName = "eyeDetect.exe";
                    proc.StartInfo.Arguments = "hello1.jpg haarcascade_frontalface_alt.xml haarcascade_eye.xml";
                    proc.StartInfo.UseShellExecute = false;
                    proc.StartInfo.RedirectStandardOutput = true;
                    proc.StartInfo.RedirectStandardError = true;
                    proc.OutputDataReceived += (o, e) => Output.Append(e.Data).Append(Environment.NewLine);
                    proc.Start();
                    proc.BeginOutputReadLine();
                    proc.BeginErrorReadLine();
                    proc.WaitForExit();
                    int ExitCode = proc.ExitCode;
                }
                Console.WriteLine(Output);
                Console.ReadLine();
        }
    }
}

How to re install Windows 7 Boot loader

Boot the machine using windows 7 bootable DVD, When you get the second screen go to repair your computer. Select the command prompt and type below commands. 

bootrec /fixmbr 
press enter

bootrec /fixBoot
press enter.
Restart.