Thursday, May 29, 2008

hidden file & folder

Method 1:

Go to registry editor by running regedit in the run box.
Go to this key:
HKEY_CURRENT_USER\Software\Microsoft\
Windows\CurrentVersion\Explorer\Advanced


In the right hand area, double click hidden and change the value to 1.

Now you’re all set to go. Check it in your tools menu if the changes have taken effect.
Method 2: (By Random Hajile)

1. Click “Start” -> “Run…” (or press Windows key + R)
2. Type “regedit” and click “Ok”.
3. Find the key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\
Advanced\Folder\Hidden\SHOWALL
4. Look at the “CheckedValue” key… This should be a DWORD key. If it isn’t, delete the key.
5. Create a new key called “CheckedValue” as a DWORD (hexadecimal) with a value of 1.
6. The “Show hidden files & folders” check box should now work normally. Enjoy

Monday, April 28, 2008

thread program

/ without join
class MyThread extends Thread
{
MyThread(String s)
{
super(s); // to create a new Thread with s name
start();
}
public void run()
{
for(int i=1;i<=5;i++)
{
System.out.println(getName()+" Thread here");
try{ sleep(1000); }catch(Exception ex){}
}
}
}
class My1
{
public static void main(String aa[])
{
MyThread t1 = new MyThread("Ankit");
MyThread t2 = new MyThread("Hari Om");
MyThread t3 = new MyThread("Gaurav");
MyThread t4 = new MyThread("Prateek");
System.out.println("main Thread exit ................");
}
}




// without join
class MyThread extends Thread
{
MyThread(String s)
{
super(s); // to create a new Thread with s name
start();
}
public void run()
{
for(int i=1;i<=5;i++)
{
System.out.println(getName()+" Thread here");
try{ sleep(1000); }catch(Exception ex){}
}
}
}
class My2
{
public static void main(String aa[])
{
MyThread t1 = new MyThread("Ankit");
t1.setPriority(2); // Thread.MIN_PRIORITY+1 /Thread.NORM_PRIORITY-3 / Thread.MAX_PRIORITY-8 /
MyThread t2 = new MyThread("Hari Om");
t2.setPriority(4);
MyThread t3 = new MyThread("Gaurav");
t3.setPriority(9);
MyThread t4 = new MyThread("Prateek");
try
{
t1.join();
t2.join();
t3.join();
t4.join();
}catch(Exception ex){}
System.out.println("main Thread exit ................");
}
}







// without join
class MyThread extends Thread
{
AbhiTask t;
MyThread(String s,AbhiTask a)
{
super(s); // to create a new Thread with s name
t = a;
start();
}
public void run()
{
t.work(getName());
}
}
class AbhiTask
{
void work(String s)
{
for(int i=1;i<=5;i++)
{
System.out.println(s+" Thread here");
try{ Thread.sleep(1000); }catch(Exception ex){}
}
}
}
class Syn1
{
public static void main(String aa[])
{
AbhiTask t = new AbhiTask();
MyThread t1 = new MyThread("Ankit",t);
MyThread t2 = new MyThread("Hari Om",t);
MyThread t3 = new MyThread("Gaurav",t);
MyThread t4 = new MyThread("Prateek",t);
try
{
t1.join();
t2.join();
t3.join();
t4.join();
}catch(Exception ex){}
System.out.println("main Thread exit ................");
}
}



// with method synchronization - single method to be synchronized
class MyThread extends Thread
{
AbhiTask t;
MyThread(String s,AbhiTask a)
{
super(s); // to create a new Thread with s name
t = a;
start();
}
public void run()
{
t.work(getName());
}
}
class AbhiTask
{
synchronized void work(String s)
{
for(int i=1;i<=5;i++)
{
System.out.println(s+" Thread here");
try{ Thread.sleep(1000); }catch(Exception ex){}
}
}
}
class Syn2
{
public static void main(String aa[])
{
AbhiTask t = new AbhiTask();
MyThread t1 = new MyThread("Ankit",t);
MyThread t2 = new MyThread("Hari Om",t);
MyThread t3 = new MyThread("Gaurav",t);
MyThread t4 = new MyThread("Prateek",t);
try
{
t1.join();
t2.join();
t3.join();
t4.join();
}catch(Exception ex){}
System.out.println("main Thread exit ................");
}
}







// with Object synchronization - all methods to be synchronized
class MyThread extends Thread
{
AbhiTask t;
MyThread(String s,AbhiTask a)
{
super(s); // to create a new Thread with s name
t = a;
start();
}
public void run()
{
synchronized(t) // object synchronized
{
t.work(getName());
}
}
}
class AbhiTask
{
void work(String s)
{
for(int i=1;i<=5;i++)
{
System.out.println(s+" Thread here");
try{ Thread.sleep(1000); }catch(Exception ex){}
}
}
}
class Syn3
{
public static void main(String aa[])
{
AbhiTask t = new AbhiTask();
MyThread t1 = new MyThread("Ankit",t);
MyThread t2 = new MyThread("Hari Om",t);
MyThread t3 = new MyThread("Gaurav",t);
MyThread t4 = new MyThread("Prateek",t);
try
{
t1.join();
t2.join();
t3.join();
t4.join();
}catch(Exception ex){}
System.out.println("main Thread exit ................");
}
}




// with Object synchronization - all methods to be synchronized
class MyThread extends Thread
{
AbhiTask t;
MyThread(String s,AbhiTask a)
{
super(s); // to create a new Thread with s name
t = a;
start();
}
public void run()
{
synchronized(t) // object synchronized
{
t.work(getName());
t.work1(getName());
}
}
}
class AbhiTask
{
void work(String s)
{
for(int i=1;i<=5;i++)
{
System.out.println(s+" Thread here");
try{ Thread.sleep(1000); }catch(Exception ex){}
}
}
void work1(String s)
{
for(int i=1;i<=5;i++)
{
System.out.println(s);
try{ Thread.sleep(500); }catch(Exception ex){}
}
}
}
class Syn4
{
public static void main(String aa[])
{
AbhiTask t = new AbhiTask();
MyThread t1 = new MyThread("Ankit",t);
MyThread t2 = new MyThread("Hari Om",t);
MyThread t3 = new MyThread("Gaurav",t);
MyThread t4 = new MyThread("Prateek",t);
try
{
t1.join();
t2.join();
t3.join();
t4.join();
}catch(Exception ex){}
System.out.println("main Thread exit ................");
}
}







// with method synchronization -single method to be synchronized
class MyThread extends Thread
{
AbhiTask t;
MyThread(String s,AbhiTask a)
{
super(s); // to create a new Thread with s name
t = a;
start();
}
public void run()
{
t.work(getName());
t.work1(getName());
}
}
class AbhiTask
{
synchronized void work(String s)
{
for(int i=1;i<=5;i++)
{
System.out.println(s+" Thread here");
try{ Thread.sleep(1000); }catch(Exception ex){}
}
}
synchronized void work1(String s)
{
for(int i=1;i<=5;i++)
{
System.out.println(s);
try{ Thread.sleep(500); }catch(Exception ex){}
}
}
}
class Syn5
{
public static void main(String aa[])
{
AbhiTask t = new AbhiTask();
MyThread t1 = new MyThread("Ankit",t);
MyThread t2 = new MyThread("Hari Om",t);
MyThread t3 = new MyThread("Gaurav",t);
MyThread t4 = new MyThread("Prateek",t);
try
{
t1.join();
t2.join();
t3.join();
t4.join();
}catch(Exception ex){}
System.out.println("main Thread exit ................");
}
}







// to control the main Thread
class Th1
{
public static void main(String aa[])
{
for(char c='A';c<='Z';c++)
{
System.out.println(c);
try{ Thread.sleep(500); }catch(Exception ex){}
}
}
}





// to control the main Thread
import java.util.*;
class Th2
{
public static void main(String aa[])
{
Date d;
while(true)
{
d = new Date();
System.out.println(d.getHours()+" : "+d.getMinutes()+" : "+d.getSeconds());
try{ Thread.sleep(1000); }catch(Exception ex){}
}
}
}






// to create own thread
import java.util.*;
import java.applet.*;
import java.awt.*;
public class Th3 extends Applet implements Runnable
{
Button b = new Button("Clock");
Thread t;
Date d;
public void init()
{
setLayout(null);
b.setBounds(50,100,600,140);
b.setFont(new Font("Courier New",1,100));
add(b);
t = new Thread(this); // to create the new Thread for current applet
t.start();
}
public void run()
{
while(true)
{
d = new Date();
b.setLabel(d.getHours()+" : "+d.getMinutes()+" : "+d.getSeconds());
try{ t.sleep(1000); }catch(Exception ex){}
}
}
}
//








// to create own thread
import java.util.*;
import java.applet.*;
import java.awt.*;
public class Th4 extends Applet implements Runnable
{
Button b = new Button("Clock");
Thread t;
Date d;
public void init()
{
b.setForeground(Color.white);
setLayout(null);
b.setBounds(50,100,600,140);
b.setFont(new Font("Courier New",1,100));
add(b);
t = new Thread(this); // to create the new Thread for current applet
t.start();
new AbhiThread().start(); // AbhiThread t1 = new AbhiThread(); t1.start();
}
public void run()
{
while(true)
{
d = new Date();
b.setLabel(d.getHours()+" : "+d.getMinutes()+" : "+d.getSeconds());
try{ t.sleep(1000); }catch(Exception ex){}
}
}
class AbhiThread extends Thread
{
int cr,cg,cb;
public void run()
{
while(true)
{
cr = (int)(Math.random()*205);
cg = (int)(Math.random()*205);
cb = (int)(Math.random()*205);
b.setBackground(new Color(cr,cg,cb));
setBackground(new Color(cg,cb,cr));
try{ t.sleep(5000); }catch(Exception ex){}
}
}
}
}
//






// to create own thread
import java.util.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Th5 extends Applet implements Runnable,ActionListener
{
boolean flag = true;
Button b = new Button("Clock");
Thread t;
Date d;
public void init()
{
b.setForeground(Color.white);
setLayout(null);
b.setBounds(50,100,600,140);
b.setFont(new Font("Courier New",1,100));
add(b);
t = new Thread(this); // to create the new Thread for current applet
t.start();
new AbhiThread().start(); // AbhiThread t1 = new AbhiThread(); t1.start();
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(flag)
{
t.suspend();
flag = false;
}
else
{
t.resume();
flag = true;
}
}
public void run()
{
while(true)
{
d = new Date();
b.setLabel(d.getHours()+" : "+d.getMinutes()+" : "+d.getSeconds());
try{ t.sleep(1000); }catch(Exception ex){}
}
}
class AbhiThread extends Thread
{
int cr,cg,cb;
public void run()
{
while(true)
{
cr = (int)(Math.random()*205);
cg = (int)(Math.random()*205);
cb = (int)(Math.random()*205);
b.setBackground(new Color(cr,cg,cb));
setBackground(new Color(cg,cb,cr));
try{ t.sleep(5000); }catch(Exception ex){}
}
}
}
}
//






// to create own thread
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Th6 extends Applet implements Runnable,ActionListener
{
boolean flag = true;
Button b = new Button("Clock");
Thread t;
int m=59,s=59;
public void init()
{
b.setForeground(Color.white);
setLayout(null);
b.setBounds(50,100,600,140);
b.setFont(new Font("Courier New",1,100));
add(b);
t = new Thread(this); // to create the new Thread for current applet
t.start();
new AbhiThread().start(); // AbhiThread t1 = new AbhiThread(); t1.start();
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(flag)
{
t.suspend();
flag = false;
}
else
{
t.resume();
flag = true;
}
}
public void run()
{
while(m>=0)
{
s--;
if(s<=0)
{
m--;
s = 59;
}
b.setLabel("00 : "+m+" : "+s);
try{ t.sleep(1000); }catch(Exception ex){}
}
}
class AbhiThread extends Thread
{
int cr,cg,cb;
public void run()
{
while(true)
{
cr = (int)(Math.random()*205);
cg = (int)(Math.random()*205);
cb = (int)(Math.random()*205);
b.setBackground(new Color(cr,cg,cb));
setBackground(new Color(cg,cb,cr));
try{ t.sleep(5000); }catch(Exception ex){}
}
}
}
}
//









// to create own thread
import java.applet.*;
import java.awt.*;
public class Th7 extends Applet implements Runnable
{
Thread t;
int a=0,b=400;
Image m;
public void init()
{
m = getImage(getCodeBase(),"create.gif");
t = new Thread(this); // to create the new Thread for current applet
t.start();
}
public void run()
{
while(true)
{
a+=5;
b-=5;
if(a>=400)
{
a =0;
b = 400;
}
try{ t.sleep(100); }catch(Exception ex){}
repaint();
}
}
public void paint(Graphics g)
{
g.drawImage(m,a,a,this);
g.drawImage(m,b,b,this);
g.drawImage(m,b,a,this);
g.drawImage(m,a,b,this);
g.drawImage(m,200,a,this);
g.drawImage(m,200,b,this);
g.drawImage(m,b,200,this);
g.drawImage(m,a,200,this);
}
}
//








// to create own thread
import java.applet.*;
import java.awt.*;
public class Th8 extends Applet implements Runnable
{
Thread t;
int a=200,b=200;
Image m;
public void init()
{
m = getImage(getCodeBase(),"create.gif");
t = new Thread(this); // to create the new Thread for current applet
t.start();
}
public void run()
{
while(true)
{
a+=5;
b-=5;
if(a>=400)
{
a = 200;
b = 200;
}
try{ t.sleep(20); }catch(Exception ex){}
repaint();
}
}
public void paint(Graphics g)
{
g.drawImage(m,a,a,this);
g.drawImage(m,b,b,this);
g.drawImage(m,b,a,this);
g.drawImage(m,a,b,this);
g.drawImage(m,200,a,this);
g.drawImage(m,200,b,this);
g.drawImage(m,b,200,this);
g.drawImage(m,a,200,this);
}
}
//








// to create own thread
import java.applet.*;
import java.awt.*;
public class Th9 extends Applet implements Runnable
{
Thread t;
int x,y,s,cr,cg,cb,c=0;
Graphics g;
public void init()
{
g = getGraphics(); // g hold the current applet Graphics , now we can drawing without using paint method
t = new Thread(this); // to create the new Thread for current applet
t.start();
}
public void run()
{
while(true)
{
c++;
if(c>=200)
{
repaint();
c = 0;
}
drawing();
try{ t.sleep(20); }catch(Exception ex){}
}
}
void drawing()
{
x = (int)(Math.random()*800);
y = (int)(Math.random()*600);
s = (int)(Math.random()*50);
cr = (int)(Math.random()*255);
cg = (int)(Math.random()*255);
cb = (int)(Math.random()*255);
g.setColor(new Color(cr,cg,cb));
g.setFont(new Font("Courier New",3,s));
g.drawString("Gaurav",x,y);
}
}
//











// to create own thread
import java.applet.*;
import java.awt.*;
public class Th10 extends Applet implements Runnable
{
Thread t;
int x,y,w,h,cr,cg,cb,c=0;
Graphics g;
public void init()
{
g = getGraphics(); // g hold the current applet Graphics , now we can drawing without using paint method
t = new Thread(this); // to create the new Thread for current applet
t.start();
}
public void run()
{
while(true)
{
c++;
if(c>=300)
{
repaint();
c = 0;
}
drawing();
try{ t.sleep(10); }catch(Exception ex){}
}
}
void drawing()
{
x = (int)(Math.random()*800);
y = (int)(Math.random()*600);
w = (int)(Math.random()*50);
h = (int)(Math.random()*50);
cr = (int)(Math.random()*255);
cg = (int)(Math.random()*255);
cb = (int)(Math.random()*255);
g.setColor(new Color(cr,cg,cb));
g.fillOval(x,y,w,h);
}
}
//





// to create own thread
import java.applet.*;
import java.awt.*;
public class Th11 extends Applet implements Runnable
{
Thread t;
int a=0;
Image m[] = new Image[9];
public void init()
{
for(int i=0;i<8;i++)
m[i] = getImage(getCodeBase(),"aa"+i+".jpg");
t = new Thread(this); // to create the new Thread for current applet
t.start();
}
public void run()
{
while(true)
{
a++;
if(a>5)
a =0;
try{ t.sleep(1500); }catch(Exception ex){}
repaint();
}
}
public void paint(Graphics g)
{
g.drawImage(m[a],100,100,400,500,this);
}
}
//

Sunday, April 27, 2008

B.Tech 8 sem ACA Lab Program

// prefix.cpp : main project file.
#include "stdafx.h"
#include "omp.h"
#include "stdio.h"
#include "conio.h"
#include "math.h"

using namespace System;

int main(array ^args)
{
// Console::WriteLine(L"Hello World");
int a[100],j,k,n,i;
//int i,j,k;
//float n;
//float n,i;
int p;
printf("enter the count of nos. to be added"); //no of processors spawned
scanf("%d", &n);
for(k = 0 ; k {
printf("enter the no. to be added"); //value at each processor
scanf("%d ", &a[k]);
}

#pragma omp parallel private(x,y) shared(sum,n)
{
/*for(i=0;i {
printf(" \nthe value of n is %f", n);
float z= log(n);
for (j=0; j<=(ceil(z-1));j++)
{
printf(" \nthe value of z is %f", z);
printf(" \nthe value of j is %d", j);
if ((i - (2^j)) >= 0)
{
a[i]=a[i]+a[(i-(2^j))];
printf("\nthe sum is %d ", a[i]);
}
}
}*/

p=floor(log(n));
for (j=0;j<=p;j++)
{
if((i-(2^j))>=0))
{
a[i]=a[i]+a[i-(2^j)];

}
printf("\n the value of a[%d] = %d",i,a[i]);
}

//printf("the sum is %d ", a[0]);
}
getch();
return 0;
}











///////////////////////////////////////////////
//
// Java PROGRAM of Gaussian Elimination
// Name: Gaussian_dyn.java
// Programmed by Jun Ni, Ph.D.M.E., at jni@hpcsoft.com
// Last modified July 17, 2003
// Reference: Numerical Methods for Engineers
// by Griffiths and Smith, 1991, CRC Press
//
///////////////////////////////////////////////

public class Gaussian_dyn
{

public static void main(String[] args)
{
int n;
System.out.println("******* Gaussian Elimination *********");
System.out.println("input number of equations n=");
n=MyInput.readInt();

double [][] a=new double[n][n];
double [] b=new double[n];
double x,sum;
int i,j,k;

System.out.println("Input matrix coefficients a(i,j)=");
for (i=0;i for (j=0;j a[i][j]=MyInput.readDouble();

System.out.println("Input right-hand side vector b(i)=");
for (i=0;i b[i]=MyInput.readDouble();


System.out.println("Coefficient matrix:");
printMatrix(a,n);
System.out.println("\nRight-hand side vector:");
printVector(b,n);
System.out.println();
// convert to upper triangular form
for (k=0;k {
if ( Math.abs(a[k][k])>=1.e-6)

{
for (i=k+1;i {
x = a[i][k]/a[k][k];
for (j=k+1;j b[i] = b[i] - b[k]*x;
}
}
else
{
System.out.println("Zero pivot found in line:"+k);
System.exit(1);
}
}

/* back substitution */
b[n-1]=b[n-1]/a[n-1][n-1];
for (i=n-2;i>=0;i--)
{
sum = b[i];
for (j=i+1;j sum = sum - a[i][j]*b[j];
b[i] = sum/a[i][i];
}
System.out.println("Solution:");
printVector(b,n);
}


static void printMatrix(double a[][], int n)
{
for (int i=0;i {
for (int j=0;j System.out.println(a[i][j]);
System.out.println();
}
}

static void printVector(double b[],int n)
{
for (int i=0;i System.out.println(b[i]);
}
} //class ends





/********************************************************/
/* HyperQuickSort Program */
/********************************************************/

#include
#include
#include
#include
#include
#include
#include
#include "hqs.h"

void merge( );
void QuickSort( );


/*********************************************************************/
/* --- SendData--- send subarray and length to each node */
/*********************************************************************/
void SendData(int numberToSort, int numberOfNodes, int *length0, int items[]) {
int
i, /* Loop control variable */
extras, /* Number of processors that get one more */
length, /* Lengths of subarrays for each node */
length1; /* Lengths of subarrays for each node */


/* Distribute array data to nodes */

/* Initialize array to sort */
srand( SEED );
for ( i = 0; i < numberToSort; i++ ) {
items[i] = rand( );
}
printf( "Data generation complete. Sorting begins.\n\n" );
fflush( stdout );

/* Load balance, at least initially */
length = numberToSort / numberOfNodes;
extras = numberToSort - length * numberOfNodes;
length1 = length + 1;

/* Send initial data to be sorted to each process */
for ( i = 1; i < numberOfNodes; i++ ) {
if ( i >= extras ) {
MPI_Send( &items[ length * i + extras ], length, MPI_INT,
i, DATA, MPI_COMM_WORLD );
} else {
MPI_Send( &items[ length * i + ( i < extras ) * i ],
length1, MPI_INT, i, DATA, MPI_COMM_WORLD );
}
}


/* Length for processor 0 */
if ( extras )
*length0 = length1;
else
*length0 = length;
}


/*********************************************************/
/* HQSnode */
/*********************************************************/
int HQSnode( int argc, char *argv[ ] ) {
int
half[ MAX_ARRAY ], /* Subarray for merging */
lower[ MAX_ARRAY ], /* Array for subdividing problem */
items[ MAX_ARRAY ], /* Array of info to be sorted */
localMedian, /* Median of all sorted substrings */
globalMedian, /* Median of all sorted substrings */
medians[ MAX_NODES ], /* Array of medians */
upper[ MAX_ARRAY ]; /* Array for subdividing problem */

char hostName[ 100 ]; /* hostname */

double
startTime,
endTime; /* variables to handle MPI timer results */

int dimension, /* Dimension of hypercube */
error=0,
first, /* Number of first node in subcube */
halfLength, /* Length of subarray for merging */
i, /* Loop control variable */
j, /* Loop control variable */
k, /* Loop control variable */
last, /* Number of last node in subcube */
length, /* Length of this node's list */
lowerLength, /* Length of subdivision */
myCubeNumber, /* Current subcube number */
myNodeNumber, /* My node number */
myRank, /* My rank in current subcube */

numberToSort, /* Size of array to sort */
numberOfNodes, /* Number of nodes in hypercube */
numberOfProcessors, /* Number of processors */
numberOfCubes, /* Number of cubes in subdivision of
hypercube */
partner, /* Number of node to exchange with in this
subdivision of hypercube */
cubeSize, /* Number of nodes in subcube */
time, /* User time in 1/10s of a second */
upperLength; /* Length of subdivision */

MPI_Status
Status; /* Status returned from MPI_Recv function */

MPI_Comm
subcubeCommunicator; /* The following variable is needed to do
subgroup communication */

struct rusage
resources; /* Structure to access time */

MPI_Comm_rank( MPI_COMM_WORLD,&myNodeNumber );
MPI_Comm_size( MPI_COMM_WORLD,&numberOfProcessors );

gethostname( hostName, 100);
printf( "Hello from process %d out of %d on %s\n",
myNodeNumber, numberOfProcessors, hostName );
fflush( stdout );

/* Initialize variables */
dimension = floor( log2( (double) numberOfProcessors ) );
numberOfNodes = 1 << dimension;

if ( argc != 3 ) {
/* Check command line arguments; "random" is not really necessary;
it's just used to show a concept */

if ( myNodeNumber == HOST ) {
printf( "Usage: %s random \n", argv[0] );
fflush( stdout );
}
error = 1;
} else if ( !(strcmp( argv[1], "random" ) == 0) ){
if ( myNodeNumber == HOST ) {
printf( "The first command line argument must be random\n");
fflush( stdout );
}
error = 1;
}

/* Abort if there's an error on the command line */
if ( error ) {
return (1);
}

numberToSort = atol( argv[2] );
if ( numberToSort < 2 || numberToSort > MAX_ARRAY ) {
if ( myNodeNumber == HOST ) {
printf( "The number to sort must be between 2 and %d\n",
MAX_ARRAY );
}
error = 1;
}

/* Abort if there's an error on the command line */
if ( error ) {
return (1);
}

/* Generate numbers to sort and split the work among the processors */
if ( myNodeNumber == HOST ) {

/* SendData will return length and array for the HOST node */
SendData( numberToSort, numberOfNodes, &length, items );

} else if ( myNodeNumber < numberOfNodes ) {

/* If this processor is actually participating */
MPI_Recv( items, MAX_ARRAY, MPI_INT, HOST, DATA, MPI_COMM_WORLD,
&Status );
MPI_Get_count( &Status, MPI_INT, &length );

} else {

/* If this processor is NOT participating */
length = 0;

}

/* NOTE: Timing is system dependent */
/* Start timing */
MPI_Barrier( MPI_COMM_WORLD );

getrusage( RUSAGE_SELF, &resources );
time = resources.ru_utime.tv_sec * 1000000 + resources.ru_utime.tv_usec;

startTime = MPI_Wtime( );

/* Do only if this processor is participating */
if ( myNodeNumber < numberOfNodes ) {

/* 2) Sort using quicksort */
QuickSort( items, 0, length-1 );

}

for ( i = dimension; i > 0; i-- ) {

/* Do only if this processor is participating */
if ( myNodeNumber < numberOfNodes ) {

/* 3) Broadcast median to rest of subcube */

/* Determine which subcube this processor is in */
numberOfCubes = 1 << ( dimension - i );
cubeSize = numberOfNodes / numberOfCubes;
myCubeNumber = myNodeNumber >> i;

/* Calculate median */
if ( length % 2 ) { /* if odd */
localMedian = items[ length / 2 ];
} else { /* if even */
localMedian = ( items[ ( length / 2 ) - 1 ]
+ items[ length / 2 ] ) / 2;
};

first = myCubeNumber * cubeSize;
last = first + cubeSize;
}

/* Set up communication subgroup */

if ( myNodeNumber < numberOfNodes ) {

/* Do only if this processor is participating */
MPI_Comm_split( MPI_COMM_WORLD, myCubeNumber, myNodeNumber,
&subcubeCommunicator );
MPI_Comm_rank( subcubeCommunicator, &myRank );

} else {

/* Do if this processor is NOT participating - Note use of
MPI_UNDEFINED */
MPI_Comm_split( MPI_COMM_WORLD, MPI_UNDEFINED, myNodeNumber,
&subcubeCommunicator );
}

/* Do only if this processor is participating */
if ( myNodeNumber < numberOfNodes ) {

/* Broadcast median to each node in subcube (except me) */
medians[ myRank ] = localMedian;
for ( j = 0; j < cubeSize; j++ ) {
MPI_Bcast( &medians[j], 1, MPI_INT, j, subcubeCommunicator );
}


/* Determine median of medians */
QuickSort( medians, 0, cubeSize-1 );

/* There are always an even number of medians */
globalMedian = ( medians[ ( cubeSize / 2 ) - 1 ]
+ medians[ cubeSize / 2 ] ) / 2;


/* 4) Create lower and upper 'halves' of items */
j = 0;
k = 0;
while ( ( items[ j ] <= globalMedian ) && ( j < length ) ) {
lower[ k ] = items[ j ];
k++;
j++;
};
lowerLength = k;
k = 0;
while ( j < length ) {
upper[ k ] = items[ j ];
k++;
j++;
};
upperLength = k;

/* 5) Send lower/upper 'half' to partner */

/* Determine partner by inverting bits of node number */
partner = ( numberOfNodes - 1 ) - myNodeNumber;
partner = ( myNodeNumber ^ ( ~( ~0 << 1 ) << ( i-1 ) ) );

/* Exchange info with partner */
if ( myNodeNumber > partner ) {

/* Send lower 'half' to partner */
MPI_Send( lower, lowerLength, MPI_INT, partner, HALF,
MPI_COMM_WORLD );

/* Receive upper 'half' from partner */
MPI_Recv( half, MAX_ARRAY, MPI_INT, partner, HALF,
MPI_COMM_WORLD,
&Status );
MPI_Get_count( &Status, MPI_INT, &halfLength );

} else {

/* Receive lower 'half' from partner */
MPI_Recv( half, MAX_ARRAY, MPI_INT, partner, HALF,
MPI_COMM_WORLD,
&Status );
MPI_Get_count( &Status, MPI_INT, &halfLength );

/* Send upper 'half' to partner */
MPI_Send( upper, upperLength, MPI_INT, partner, HALF,
MPI_COMM_WORLD );
};


/* 6) Merge lower/upper array with 'half' array into items array */
if (myNodeNumber > partner) {
merge( upper, half, items, upperLength, halfLength );
length = upperLength + halfLength;
} else {
merge( lower, half, items, lowerLength, halfLength );
length = lowerLength + halfLength;
};
};
};


/*NOTE: Timing is system dependent */
/* End timing */
getrusage( RUSAGE_SELF, &resources );
time = resources.ru_utime.tv_sec * 1000000 + resources.ru_utime.tv_usec
- time;

MPI_Barrier( MPI_COMM_WORLD );
endTime = MPI_Wtime( ) - startTime;

/* Confirm array is sorted */
for ( i = 0; i < length - 1; i++ ) {
if ( items[ i ] > items[ i + 1 ] ) {
printf("%d error --(%d:%d) (%d:%d)\n", myNodeNumber, i, items[ i ],
i + 1, items[ i + 1 ] );
fflush( stdout );
}
}

/* Report results */
if ( length != 0 ) {
printf( "Node %d (time=%6.6f seconds/%6.6f seconds, length = %d) : %d ... %d\n\n",
myNodeNumber, ( float ) time / 1000000.0, endTime, length,
items[ 0 ], items[ length - 1 ] );
fflush( stdout );
} else {
printf( "Node %d (time=%6.6f seconds/%6.6f seconds, length = %d)\n\n",
myNodeNumber, ( float ) time / 1000000.0, endTime, length);
fflush( stdout );
}
return (0);

}


/*******************************************************************/
/* --- merge --- merge and sort two sorted arrays into third array */
/*******************************************************************/
void merge(int a[ ], int b[ ], int c[ ], int m, int n) {
int i, /* Loop control for array a */
j, /* Loop control for array b */
k; /* Loop control for array c */

i = 0;
j = 0;
k = 0;

while ( ( i < m ) && ( j < n ) ) {
if ( a[ i ] < b[ j ] ) {
c[ k ] = a[ i ];
k++;
i++;
} else {
c[ k ] = b[ j ];
k++;
j++;
};
}


/* Pick up any remainder */
while ( i < m ) {
c[ k ] = a[ i ];
k++;
i++;
};
while ( j < n ) {
c[ k ] = b[ j ];
k++;
j++;
};

}


/********************************************************/
/* Swap: swap two values */
/********************************************************/
void Swap(int *i, int *j) {
int t; /* Temporary variable for swap */

t = *i;
*i = *j;
*j = t;
}


/*****************************************************************************/
/* Median3: Find the median of left, center, and right; return the median */
/* as the pivot, and "hide" the pivot as the next-to-last (right-1) element. */
/*****************************************************************************/
void Median3 (int a[], int left, int right, int *pivot) {
int center; /* Temporary variable for determining median */

center = ( left + right ) / 2;

if ( a[ left ] > a[ center ] ) {
Swap ( &a[ left ], &a[ center ] );
}
if ( a[ left ] > a[ right ] ) {
Swap ( &a[ left ], &a[ right ] );
}
if ( a[ center ] > a[ right ] ) {
Swap ( &a[ center ], &a[ right ] );
}

*pivot = a[ center ];
Swap ( &a[ center ], &a[ right - 1 ] );
}


/********************************************************/
/* QuickSort: the basic QuickSort algorithm. */
/* Note requires > 2 items to sort properly */
/********************************************************/
void QuickSort(int a[], int left, int right) {
int
i, /* Loop control variable */
j, /* Loop control variable */
pivot; /* Quicksort pivot */

if ( left < right ) {
Median3 (a, left, right, &pivot); /* Find the pivot. */

/* Do the partition. */
i = left;
j = right - 1;
if ( i < j ) {
do {
do {
i++;
} while ( a[ i ] < pivot );
do {
j-- ;
} while ( a[ j ] > pivot );
Swap( &a[ i ], &a[ j ] );
} while ( j > i );

Swap( &a[ i ], &a[ j ] ); /* Undo last swap. */
Swap( &a[ i ], &a[ right - 1 ]); /* Restore pivot. */
};

QuickSort( a, left, i - 1 );
QuickSort( a, i + 1, right );
}
}


/*******************************************************/
/* Main program - starts up on each machine */
/*******************************************************/
void main( int argc, char *argv[ ] ) {

/* Set up mpi machine */
MPI_Init( &argc, &argv );

HQSnode( argc, argv );

MPI_Finalize( );












MatrixMultiplication.java

Below is the syntax highlighted version of MatrixMultiplication.java from §9.5 Numerical Linear Algebra.

/*************************************************************************
* Compilation: javac MatrixMultiplication.java
* Execution: java MatrixMultiplication
*
* 6 different ways to multiply two N-by-N matrices.
* Illustrates importance of row-major vs. column-major ordering.
*
* % java MatrixMultiplication 400
* Generating input: 0.765 seconds
* Order ijk: 7.875 seconds
* Order ikj: 14.542 seconds
* Order jik: 7.838 seconds
* Order jki: 20.86 seconds
* Order kij: 13.132 seconds
* Order kji: 20.813 seconds
*
*************************************************************************/

public class MatrixMultiplication {
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
long start, stop;
double elapsed;


// generate input
start = System.currentTimeMillis();

double[][] A = new double[N][N];
double[][] B = new double[N][N];
double[][] C;

for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
A[i][j] = Math.random();

for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
B[i][j] = Math.random();

stop = System.currentTimeMillis();
elapsed = (stop - start) / 1000.0;
System.out.println("Generating input: " + elapsed + " seconds");


// order 1: ijk = dot product version
C = new double[N][N];
start = System.currentTimeMillis();
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
for (int k = 0; k < N; k++)
C[i][k] += A[i][j] * B[j][k];
stop = System.currentTimeMillis();
elapsed = (stop - start) / 1000.0;
System.out.println("Order ijk: " + elapsed + " seconds");


// order 2: ikj
C = new double[N][N];
start = System.currentTimeMillis();
for (int i = 0; i < N; i++)
for (int k = 0; k < N; k++)
for (int j = 0; j < N; j++)
C[i][k] += A[i][j] * B[j][k];
stop = System.currentTimeMillis();
elapsed = (stop - start) / 1000.0;
System.out.println("Order ikj: " + elapsed + " seconds");

// order 3: jik
C = new double[N][N];
start = System.currentTimeMillis();
for (int j = 0; j < N; j++)
for (int i = 0; i < N; i++)
for (int k = 0; k < N; k++)
C[i][k] += A[i][j] * B[j][k];
stop = System.currentTimeMillis();
elapsed = (stop - start) / 1000.0;
System.out.println("Order jik: " + elapsed + " seconds");

// order 4: jki = GAXPY version
C = new double[N][N];
start = System.currentTimeMillis();
for (int j = 0; j < N; j++)
for (int k = 0; k < N; k++)
for (int i = 0; i < N; i++)
C[i][k] += A[i][j] * B[j][k];
stop = System.currentTimeMillis();
elapsed = (stop - start) / 1000.0;
System.out.println("Order jki: " + elapsed + " seconds");

// order 5: kij
C = new double[N][N];
start = System.currentTimeMillis();
for (int k = 0; k < N; k++)
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
C[i][k] += A[i][j] * B[j][k];
stop = System.currentTimeMillis();
elapsed = (stop - start) / 1000.0;
System.out.println("Order kij: " + elapsed + " seconds");

// order 6: kji = outer product version
C = new double[N][N];
start = System.currentTimeMillis();
for (int k = 0; k < N; k++)
for (int j = 0; j < N; j++)
for (int i = 0; i < N; i++)
C[i][k] += A[i][j] * B[j][k];
stop = System.currentTimeMillis();
elapsed = (stop - start) / 1000.0;
System.out.println("Order kji: " + elapsed + " seconds");


// order 7: jik optimized ala JAMA
C = new double[N][N];
start = System.currentTimeMillis();
double[] bj = new double[N];
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) bj[k] = B[k][j];
for (int i = 0; i < N; i++) {
double[] ai = A[i];
double s = 0;
for (int k = 0; k < N; k++) {
s += ai[k] * bj[k];
}
C[i][j] = s;
}
}
stop = System.currentTimeMillis();
elapsed = (stop - start) / 1000.0;
System.out.println("Order kji: " + elapsed + " seconds");


}

}





import java.lang.*;
import java.io.*;
class MatMulti extends Thread
{
static int in1[][];
static int in2[][];
static int out[][];
static int n=2;
int row;
M// merge.cpp : main project file.

#include "stdafx.h"
#include "omp.h"
#include "stdio.h"
#include "conio.h"
#include "math.h"

using namespace System;

int main(array ^args)
{
int a[20],b[20],c[20],i,low,high,x,j,k,n,z;
int index,y;

printf("enter the no. of elements in sorted array <=20"); //value at each processor
scanf("%d ", &n);

for(k=1; k<=(n/2) ; k++)
{
printf("enter the no. IN FIRST ARRAY IN SORTED ORDER"); //value at each processor
scanf("%d ", &a[k]);
}
printf("\n\n");
for(k = (n/2)+1; k<=n ; k++)
{
printf("enter the no. IN SECOND ARRAY IN SORTED ORDER"); //value at each processor
scanf("%d ", &a[k]);
}
for(i = 1; i<=n ; i++)
{
printf("a[%d]=%d", i, a[i]);
c[i]=0;
}

#pragma omp parallel
{

for(i=1;i<=n;i++)
{
if(i<= (n/2))
{
low =(n/2)+1;
high=n;
// printf("\n%d %d", low,high);
}
else
{
low=1;
high=(n/2);
// printf("\n%d %d",low,high);
}

x=a[i];
//printf("x is %d", x);
while(low{
index= ((low+high)/2);
//printf("\n%d ", index);
//printf("a[%d]=%d ", index, a[index]);
if(x {high=index-1;
//printf("\n%d ", high);
}
else
{low=index+1;
//printf("\n%d ", low);
}
};
y=high+i-(n/2);
printf("\ny is %d", y);
c[y]=x;

}
}

printf("\nthe no.in SORTED ORDER");
for(z = 1 ; z<=n ; z++)
{
printf("\t%d ", c[z]);
}
getch();
return 0;
}atMulti(int i)
{
row=i;
this.start();
}
public void run()
{
int i,j;
for(i=0;i {
out[row][i]=0;
for(j=0;j out[row][i]=out[row][i]+in1[row][j]*in2[j][i];
}
}
public static void main(String args[])
{
int i,j;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the order of Matrix : ");
try
{
n=Integer.parseInt(br.readLine());
}catch(Exception e){}
in1=new int[n][n];
in2=new int[n][n];
out=new int[n][n];
System.out.println("Enter the First Matrix : ");
for(i=0;i {
for(j=0;j {
try
{
in1[i][j]=Integer.parseInt(br.readLine());
}catch(Exception e){}
}
}
System.out.println("Enter the Second Matrix : ");
for(i=0;i {
for(j=0;j {
try
{
in2[i][j]=Integer.parseInt(br.readLine());
}catch(Exception e){}
}
}
MatMulti mat[]=new MatMulti[n];
for(i=0;i mat[i]=new MatMulti(i);
try
{
for(i=0;i mat[i].join();
}catch(Exception e){}
System.out.println("OUTPUT :");
for(i=0;i for(j=0;j System.out.println(out[i][j]);
}
}


// abcdef.cpp : main project file.

#include "stdafx.h"
#include "omp.h"
#include "stdio.h"
#include "conio.h"
#include "math.h"

using namespace System;

int main(array ^args)
{
// Console::WriteLine(L"Hello World");
int n,a[100];
int i,j,k;

printf("enter the count of nos. to be added");
scanf("%d ", &n);
for(k = 0 ; k {
printf("enter the no. to be added");
scanf("%d ", &a[k]);
}

#pragma omp parallel private(x,y) shared(sum,n)
{
for(i=0;i<= (floor(n/2))-1;i++)
{
int z= log(n);
for (j=0; j<=(ceil(z))-1;j++)
{
if (((i % (2^j)) == 0) &&( ((2*i) +( 2^j)) {
a[2*i]=a[2*i]+a[(2*i) +(2^j)];
}
}
}

}
printf("the sum is %d ", a[0]);
getch();
return 0;
}


private static void quickSort(int worker, int left, int right) {
int pivot = nums[left]; int l = left, r = right;
// enclose what this worker is working on in a black outline rectangle
int ymin = minn(nums, left, right);
int ymax = maxx(nums, left, right);
float xpos, ypos, xsize, ysize;
xpos = scaleX(left); ypos = scaleY(ymin);
xsize = scaleX(right-left); ysize = scaleY(ymax-ymin);
xa.rectangle("rect"+worker, xpos, ypos, xsize, ysize, Color.black, xa.OUTLINE);
xa.delay(1);
// change items sorted to this worker's color
for (int i = left; i <= right; i++) {
xa.color("nums"+i, colors[worker]); // would be better to do
xa.fill("nums"+i, xa.SOLID); // these as a batch i.e.
} // no frameDelay
xa.delay(1);
// make pivot outline color
xa.fill("nums"+left, xa.OUTLINE);
// draw a black horizontal line from the pivot across the rectangle
xpos = scaleX(left); ypos = scaleY(pivot);
xsize = scaleX(right-left); ysize = 0.0f;
xa.line("lineH"+worker, xpos, ypos, xsize, ysize, Color.black, xa.THIN);
// draw two vertical lines at left+1 and right
xpos = scaleX(l+1); ypos = scaleY(pivot);
xsize = 0.0f; ysize = scaleY(ymax-pivot);
xa.line("lineVL"+worker, xpos, ypos, xsize, ysize, Color.black, xa.THIN);
xpos = scaleX(r); ypos = scaleY(ymin);
xsize = 0.0f; ysize = scaleY(pivot-ymin);
xa.line("lineVR"+worker, xpos, ypos, xsize, ysize, Color.black, xa.THIN);
xa.delay(1);
boolean done = false;
while (!done) {
if (nums[l+1] > pivot) {
while (r > l+1 && nums[r] > pivot) { r--;
// move the right vertical line one to the left
if (!done) {
xa.jumpRelative("lineVR"+worker, scaleX(-1), 0.0f);
}
}
if (r > l+1) { l++;
int temp = nums[r]; nums[r] = nums[l]; nums[l] = temp;
done = l >= r-1;
// swap locations and ids of the objects
xa.moveAsync("nums"+r, scaleX(l), scaleY(nums[l]));
xa.move("nums"+l, scaleX(r), scaleY(nums[r]));
xa.swapIds("nums"+r, "nums"+l);
// move the left vertical line one to the right
if (!done) {
xa.jumpRelative("lineVL"+worker, scaleX(1), 0.0f);
}
} else done = true;
} else { l++; done = l >= r;
// move the left vertical line one to the right
if (!done) {
xa.jumpRelative("lineVL"+worker, scaleX(1), 0.0f);
}
}
}
int temp = nums[left]; nums[left] = nums[l]; nums[l] = temp;
// swap locations and ids of the objects
xa.moveAsync("nums"+left, scaleX(l), scaleY(nums[l]));
xa.move("nums"+l, scaleX(left), scaleY(nums[left]));
xa.swapIds("nums"+left, "nums"+l);
if (right-(l+1) > 0) send(task, new Task(l+1, right));
else if (right-(l+1) == 0) { V(doneCount);
// color the object solid black to indicate it is in final position
xa.color("nums"+right, Color.black);
xa.fill("nums"+right, xa.SOLID);
}
// delete the line and rectangle objects
xa.delete("rect"+worker);
xa.delete("lineH"+worker);
xa.delete("lineVL"+worker);
xa.delete("lineVR"+worker);
V(doneCount);
// color the object solid black to indicate it is in final position
xa.color("nums"+l, Color.black);
xa.fill("nums"+l, xa.SOLID);
if ((l-1)-left > 0) send(task, new Task(left, l-1));
else if ((l-1)-left == 0) { V(doneCount);
// color the object solid black to indicate it is in final position
xa.color("nums"+left, Color.black);
xa.fill("nums"+left, xa.SOLID);
}
}





// prefix.cpp : main project file.
#include "stdafx.h"
#include "omp.h"
#include "stdio.h"
#include "conio.h"
#include "math.h"

using namespace System;

int main(array ^args)
{
int a[100],b[100],j,k,i;
float n;
printf("enter the count of nos. to be added"); //no of processors spawned
scanf("%f", &n);
for(k = 0 ; k {
printf("enter the no. to be added"); //value at each processor
scanf("%d ", &a[k]);
}

#pragma omp parallel private(x,y) shared(sum,n)
{
int z=0;
for(i=1;i{
printf("\ni value %d", i);
float p=ceil(log(n));
printf("\np value %f", p);
for (j=0;j<=p-1;j++)
{ printf("\nj value %d", j);
z= (i-(pow(2.0,j)));
printf("\nz value %d", z);
if(z>=0)
{
a[i]=a[i]+a[z];
printf("\n the value of a[%d] = %d",i,a[i]);
}

}

}
}
getch();
return 0;
}










B.Tech 8 sem DS Lab Program

Simulate the functioning of Lamport's Logical clock in 'C'



Lamport's logical clocks
Method: The logical clock runs on top of some other message-passing protocol, adding additional state at each process and additional content to the messages (which is invisible to the underlying protocol). Every process maintains a local logical clock. When a process sends a message or executes and internal step, it sets clock ? clock + 1. If it sends a message, it piggybacks the resulting clock value on the message. When a process receives a message, it sets clock ? max(clock, message timestamp)+1; the resulting clock value is taken as the time of receipt of the message.
Claim: If we order all events by clock value, we get an execution of the underlying protocol that is locally indistinguishable from the original execution.
Proof: Key observation is that clock-updating rules ensure (a) all events at the same process occur in increasing order and (b) the receipt of a message has a higher clock value than its transmission. In other words the clock order is consistent with the causal order. So we can apply the local indistinguishability theorem from Synchronizers to argue that the reordered execution does what we want.
Logical Clocks
A logical clock C is a map from the set of events E to N (the set of natural numbers) with the following constraint:










/*program to implement lamports logical clock*/



#include
#include
#include
void main()
{
int n,i,a[100],m,j,c[100][100],d[100],temp,s[100][100],g,r[100][100];
clrscr();
printf("\nenter the no. of process in the distributed system=");
scanf("%d",&n);
for(i=0;i printf("\nenter the no. of events in each process=");
scanf("%d",&a[i]);
}
for(i=0;i printf("\nenter the drift velocity of each process");
scanf("%d",&d[i]);
}
printf("\the overall configuration of the distributed system is");
for(i=0;i{
printf("\nthe process P[%d] has %d events in it and its drift rate is %d",i,a[i],d[i]);
}
//for each process, entering happened before relationship of events within that process
for(j=0;j{
for(i=0;i{
printf("\nenter the timestamp of %d event of process P[%d]",i+1,j);
scanf("%d",&c[j][i]);
}
}
//computing happened before reln. among the events of single process
for(j=0;j{
for(i=0;i{
if(c[j][i]>c[j][i+1])
{
temp=c[j][i];
c[j][i]=c[j][i+1];
c[j][i+1]=temp;
}
}
}
for(j=0;j{
printf("\nthe non-decreasing order of events of a process P[%d] are",j);
for(i=0;i{
printf("\nthe c[%d][%d] event with timestamp value %d is %d in the process",j,i,c[j][i],i);
}
}
//considering the inter-process communication messages
printf("\nenter the no. of sending events=");
scanf("%d",&m);
for(g=0;g{
printf("\nenter the timestamp index of send message event=");
scanf("%d\t%d",&s[j][i]);
s[j][i]=c[j][i];
}
for(g=0;g{
printf("\nthe sending events in the distributed system are s[%d][%d] with timestamp values %d",j,i,s[j][i]);
}
//establishing happened before relationship among the events of the processes
//using the implementation rule 1 and 2
c[j][i]=c[j][i]+d[j];//incrementing the values
//for IPC
c[j][i]=max(c[j][i]
getch();
}







II-----------



/*
A basic extension of the java.applet.Applet class
*/
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.util.*;
public class chatServer extends Applet
{
client clientObject;
String line;
public void init()
{
super.init();
setLayout(null);
addNotify();
resize(640,480);
txtName = new java.awt.TextField();
txtName.setText("ID");
txtName.reshape(72,12,168,27);
txtName.setFont(new Font("Dialog", Font.BOLD, 14));
txtName.setBackground(new Color(16776960));
add(txtName);
lblIp = new java.awt.Label("IP Address");
lblIp.reshape(240,12,96,24);
lblIp.setFont(new Font("Dialog", Font.BOLD, 14));
add(lblIp);
lblPort = new java.awt.Label("Port");
lblPort.reshape(480,12,48,24);
lblPort.setFont(new Font("Dialog", Font.BOLD, 14));
add(lblPort);
txtPort = new java.awt.TextField();
txtPort.setText("4321");
txtPort.reshape(528,12,72,27);
txtPort.setFont(new Font("Dialog", Font.BOLD, 14));
txtPort.setBackground(new Color(16776960));
add(txtPort);
txtArea = new java.awt.TextArea();
txtArea.setEditable(false);
txtArea.reshape(24,72,588,288);
txtArea.setBackground(new Color(65535));
add(txtArea);





btnConnect = new java.awt.Button("Connect");
btnConnect.reshape(276,432,84,34);
add(btnConnect);
txtField = new java.awt.TextField();
txtField.reshape(24,384,587,32);
txtField.setFont(new Font("Dialog", Font.BOLD, 14));
txtField.setBackground(new Color(16776960));
add(txtField);
txtIPaddr = new java.awt.TextField();
txtIPaddr.setText("161.178.121.1");
txtIPaddr.reshape(336,12,144,27);
txtIPaddr.setFont(new Font("Dialog", Font.BOLD, 14));
txtIPaddr.setBackground(new Color(16776960));
add(txtIPaddr);
label1 = new java.awt.Label("Enter your ID and press connect to begin");
label1.reshape(156,48,312,19);
label1.setFont(new Font("Dialog", Font.BOLD, 14));
label1.setBackground(new Color(12632256));
add(label1);
lblName = new java.awt.Label("Name");
lblName.reshape(12,12,60,24);
lblName.setFont(new Font("Dialog", Font.BOLD, 14));
add(lblName);
}
public boolean action(Event event, Object arg)
{
if (event.target == btnConnect)
{
btnConnect.disable();
txtField.requestFocus();
clientObject = new client(this, txtIPaddr.getText(), txtPort.getText());
return true;
}
if (event.target == txtField)
{
line = txtField.getText();
txtField.setText("");
String lineOut = "00000000|" + txtName.getText() + "|" + line + "|";
clientObject.pout.println(lineOut);
return true;
}






return super.action(event, arg);
}
java.awt.TextField txtName;
java.awt.Label lblIp;
java.awt.Label lblPort;
java.awt.TextField txtPort;
java.awt.TextArea txtArea;
java.awt.Button btnConnect;
java.awt.TextField txtField;
java.awt.TextField txtIPaddr;
java.awt.Label label1;
java.awt.Label lblName;
}
class client extends Thread {
DataInputStream dis;
Socket sock;
PrintStream pout;
InputStream in;
OutputStream out;
DataInputStream din;
DataOutputStream dout;
String IPA;
chatServer myClient;
String port;
int portInt;
client(chatServer myClient, String IPA, String port) {
this.myClient = myClient;
this.IPA = IPA;
this.port = port;
portInt = Integer.valueOf(port).intValue();
start();
}
public void run() {
System.out.println("client thread started");
try {
sock = new Socket(IPA, portInt);
System.out.println("connection made");
in = sock.getInputStream();
out = sock.getOutputStream();
pout = new PrintStream(out);
din = new DataInputStream(in);
dout = new DataOutputStream(out);






while(true) {
String request = din.readLine();
myClient.txtArea.appendText(request + "\n");
}
}
catch (UnknownHostException e ) {System.out.println("can't find host"); }
catch ( IOException e ) {System.out.println("Error connecting to host");}
}
}




III---------------------------


// RMI
import java.math.*;
import java.rmi.*;
import java.rmi.server.*;
public class PowerServiceServer extends UnicastRemoteObject
implements PowerService
{
public PowerServiceServer () throws RemoteException
{
super();
}
public BigInteger square ( int number )
throws RemoteException
{
String numrep = String.valueOf(number);
BigInteger bi = new BigInteger (numrep);
bi.multiply(bi);
return (bi);
}
public BigInteger power ( int num1, int num2)
throws RemoteException
{
String numrep = String.valueOf(num1);
BigInteger bi = new BigInteger (numrep);
bi = bi.pow(num2);
return bi;
}
public static void main ( String args[] ) throws Exception
{
if (System.getSecurityManager() == null)
System.setSecurityManager ( new RMISecurityManager() );
PowerServiceServer svr = new PowerServiceServer();
Naming.bind ("PowerService", svr);
System.out.println ("Service bound....");
}
}



IIII---------------------



Introduction:

If a collection of processes share a resource or collectionof resources, then often mutual exclusion is required to revent interferences and ensure consistency when accessing the resources. This is critical section problem, familiar in the domain of operating systems. In a distributed system, however, neither sahred variables nor facilites supplied by a single local kernel can be used to solve it, in general. We require a solution to distributed mutual exclusion: one that is based solely on message passing.

Algorithm:

On initiation
state:= RELEASED;
To enter the section
state:= WANTED;
Multicast request to all processes;
T:= request's timestamp;
Wait until (number of replies receeived = (N-1));
state:= HELD;
On receipt of a request at Pj(i(j)
if(state=HELD or (state = WANTED and (T,pj)<(Ti,pi)))
Then
Queue request from pi without replying;
Else
Reply immediately to pi;
End if
To exit the ciritical section
State:= RELEASED;
Reply to any queued request;



package MutualExclusion;

import daj.*;
import java.util.*;

public class RicartAgrawala extends Application {
public static final int PNUM = 6;
public static final int DISTANCE = 70;
public static final int BORDER = 40;

public static void main(String[] args) {
new RicartAgrawala().run();
}

/** Creates new Main */
public RicartAgrawala() {
super("RicartAgrawala Mutual Exclusion",
(int) ((PNUM * DISTANCE) / Math.PI) + 2 * BORDER,
(int) ((PNUM * DISTANCE) / Math.PI) + 2 * BORDER);
}

public void construct() {
Node[] nodes = new Node[PNUM];
int i, j;
double phi, r = (PNUM * DISTANCE) / (2 * Math.PI);

for (i=0; i phi = (double) i / PNUM * Math.PI * 2;
nodes[i] = node(new Prog(i), new Integer(i).toString(),
(int) (r * Math.cos(phi) + r + BORDER),
(int) (r * Math.sin(phi) + r + BORDER));
}

for (i=0; i for (j=0; j link(nodes[i], nodes[j]);
//link(nodes[j], nodes[i]);
}
}
}

public String getText() {
return "An implementation of the RicartAgrawala Algorithm for\n" +
"solving the distributed mutual exclusion problem.";
}
}

/**
* The code that will be executed on each node.
* @author rene
* @version
*/
class Prog extends Program {
/** possible value for region: idle */
public static final int R = 0;
/** possible value for region: try to get the ressource */
public static final int T = 1;
/** possible value for region: critical region entered */
public static final int C = 2;
/** possible value for region: exiting critical region */
//public static final int E = 3;

/** the node number */
protected int index;
/** the region can be either R, T, C or E */
protected int region = R;
/** the current clock value */
protected int clock = 0;
/** for every node, the message history */
protected Vector[] history = null;
/** for every neighbour, the buffer for remembering deferred ok messages
until critical region has been left */
protected Vector[] deferred_ok = null;
/** the logical time of the last "try" message that has been sent */
protected LogicalTime lastTryTime = null;

/** the default constructor initializes the index and the arrays */
public Prog(int index) {
this.index = index;
history = new Vector[RicartAgrawala.PNUM];
for (int i=0; i history[i] = new Vector();
deferred_ok = new Vector[RicartAgrawala.PNUM];
for (int i=0; i if (i != index)
deferred_ok[i] = new Vector();
else
deferred_ok[i] = null;
}

/** the user function for trying to get the ressource (getting the
permission to enter the critical region) */
public void tryRessource() {
// single actions must be atomic --> synchronize them
synchronized (this) {
clock++;
region = T;
lastTryTime = new LogicalTime(clock, index);
out().send(new Msg(Msg.TRY, lastTryTime));
}
}

/** the user function for freeing the ressource (exiting the critical
region) */
public void freeRessource() {
synchronized (this) {
clock++;
// this does not match the formal specification - the release is
// done immediately
region = R;
for (int i=0; i if (i != index) {
for (int j=0; j out(i).send((Msg) deferred_ok[i].get(j));
}
deferred_ok[i].removeAllElements();
}
}
}

/** this function is called when the ressource can be taken (the critical
region can be entered) */
public void ressourceAvailable() {
// for testing purposes there is no user to ne notified
}

/** this function is called when the ressource has been freed (the critical
region has been left) */
public void ressourceFreed() {
// for testing purposes there is no user to ne notified
}

/** this method performs the node's main functions */
public void main() {
Random rand = new Random();
GlobalAssertion safety = new CriticalRegionConflict(),
liveness = new CriticalRegionLockout();

while (true) {
assert(safety);
assert(liveness);
/* first the tree construction routines */
int received = in().select(2);
if (received >= 0) {
synchronized (this) {
Msg msg = (Msg) in(received).receive();
if (msg.time.clock > clock)
clock = msg.time.clock;
clock++;
history[received].add(msg);
// respond to try requests from other nodes
if (msg.type == Msg.TRY && received != index)
handleTryMessage(received, msg);
// check if the critical region can be entered now
if (region == T && checkOkMsgsReceived()) {
clock++;
region = C;
// the last try is invalid now
lastTryTime = null;
}
}
}
// simulate the user here
if (region == R && rand.nextInt(RicartAgrawala.PNUM * 2) == 0) {
tryRessource();
}
else if (region == C && rand.nextInt(RicartAgrawala.PNUM) == 0) {
freeRessource();
}
}
}

public String getText() {
String s = "Node " + index + "\nRegion: ";
switch (region) {
case R: s += "idle";
break;
case T: s += "trying to get lock:\n";
s += "try time = " + lastTryTime + "\n";
break;
case C: s += "inside critical region";
break;
/*case E: s += "exiting critical region";
break;*/
default: s += "invalid";
}
s += "\nClock value: " + clock;
return s;
}

/** This is a helper function that responds properly to a received "try"
message. */
private void handleTryMessage(int received, Msg msg) {
Msg ackMsg = new Msg(Msg.OK, new LogicalTime(clock, index));
if (region == R /*|| region == E*/)
out(received).send(ackMsg);
else if (region == C)
deferred_ok[received].add(ackMsg);
else if (region == T) {
if (lastTryTime != null && msg.time.lessThan(lastTryTime))
out(received).send(ackMsg);
else
deferred_ok[received].add(ackMsg);
}
}

/** This is a helper function that checks if all "OK" messages have been
recieved for the last try message. */
private boolean checkOkMsgsReceived() {
boolean receivedOkMsgs = true;
for (int i=0; i if (i != index) {
// always check the last "OK" msg of the history
// queues, because this is the one that has been
// recieved at last
int j = history[i].size() - 1;
while (j >= 0 && ((Msg) history[i].get(j)).type != Msg.OK)
j--;
if (j >= 0) {
Msg lastMsg = (Msg) history[i].get(j);
if (! lastTryTime.lessThan(lastMsg.time))
// there is no "OK" message that is newer
// than our own "try" message
receivedOkMsgs = false;
}
else
// there is no "OK" message from this node
receivedOkMsgs = false;
}
}
return receivedOkMsgs;
}
}

/** Represents a logical time value with operations for checking for equality
* and order.
*/
class LogicalTime {
/** the clock value */
public int clock;
/** for equal clock values the sender process's index is compared */
public int process;

/** a logical time object can only be constructed when both parameters are
known */
public LogicalTime(int clock, int process) {
this.clock = clock;
this.process = process;
}

/** checks for equality as defined for the Lamport logical time */
public boolean equals(Object o) {
if (o instanceof LogicalTime &&
((LogicalTime) o).clock == clock &&
((LogicalTime) o).process == process)
return true;
else
return false;
}

/** check if the the current time is less than t as defined for the Lamport
logical time */
public boolean lessThan(LogicalTime t) {
if (clock < t.clock ||
(clock == t.clock && process < t.process))
return true;
else
return false;
}

public String toString() {
return "(" + clock + ", " + process + ")";
}
}

class Msg extends Message {
/** message type: try (a process tries to get the shared ressource) */
public static final int TRY = 0;
/** message type: ok (a process confirms another process's request */
public static final int OK = 1;

/** the message type */
public int type;
/** the logical time of the sending process when the message was sent */
public LogicalTime time;

public Msg(int type, LogicalTime time) {
this.type = type;
this.time = time;
}

public boolean equals(Object o) {
if (o instanceof Msg &&
((Msg) o).type == type &&
((Msg) o).time.equals(time))
return true;
else
return false;
}

public String getText() {
String s = "Message type: ";
switch (type) {
case TRY: s += "try";
break;
case OK: s += "ok";
break;
default: s += "invalid";
}
s += "\nTime: " + time.toString();
return s;
}
}

/** This assertion checks that at most 1 process is in the critical region at
the same time. */
class CriticalRegionConflict extends GlobalAssertion {
private Vector procsInCR = new Vector();

public boolean assert(Program progs[]) {
int numOfProcsInCR = 0;
procsInCR.removeAllElements();

for (int i=0; i if (((Prog) progs[i]).region == Prog.C) {
numOfProcsInCR++;
procsInCR.add(new Integer(i));
}
}
return numOfProcsInCR <= 1;
}

public String getText() {
String text = "Processes in the critical region: ";
for (int i=0; i text += procsInCR.get(i) + " ";
return text;
}
}

/** This assertion checks that if a process tries to enter the critical region,
no other process trying it at any time later will be allowed to enter the
critical region before the first process has entered it. */
class CriticalRegionLockout extends GlobalAssertion {
private LogicalTime[] tryTimes = new LogicalTime[RicartAgrawala.PNUM];
private int procInCR = -1, procTryingLonger = -1;

public CriticalRegionLockout() {
for (int i=0; i tryTimes[i] = null;
}

public boolean assert(Program progs[]) {
// remember the times when the processes tried to enter the CR
for (int i=0; i if (((Prog) progs[i]).region == Prog.T)
tryTimes[i] = ((Prog) progs[i]).lastTryTime;

// Now check when a process is in the CR, if another one is still
// trying but started to try earlier. This should not happen.
for (int i=0; i if (((Prog) progs[i]).region == Prog.C) {
for (int j=0; j if (((Prog) progs[j]).region == Prog.T &&
tryTimes[j].lessThan(tryTimes[i])) {
procInCR = i;
procTryingLonger = j;
return false;
}
}
}

return true;
}

public String getText() {
return "Process " + procInCR + " is in the critical region, but " +
procTryingLonger + "was trying earlier !";
}
}

what is unique key

A unique constraint is a single field or combination of fields that uniquely defines a record. Some of the fields can contain null values as long as the combination of values is unique

Wednesday, April 23, 2008

swing notes

Swing -Swing is the next generation of awt(advance version
of awt). swing components r 100% pure java components,
they has own Look And Feel that means platform
independent components but awt components r platform
dependent components because there is no concept of
Look & Feel.
swing components r light weight components, they all
r written in java itself. but awt components r written
in C++ that r the heavy weight components.

size of C++ exe file - more
size of java class file - less

loading time & varifying is less.


swing is the part of JFC (Java foundation classes)

java.lang.*;
java.util.*;
java.awt.*;
javax.swing.*;

Look And Feel -

MetalLookAndFeel - java look , default
MotifLookAndFeel - unix & Linux look
WindowsLookAndFeel - windows Look ,
MachintoshLookAndFeel - Machintosh look
OrganicLookAndFeel - organic look

prop awt Swing
1- Image Icon N Y
2- ToolTipText N Y
3- Toolbar N Y
4- TabbedPane N Y
5- Slider N Y
6- ComboBox N Y
7- Shortcut Keys(ctrl + alt) N Y
8- InternalFrame N Y
9- MsgBox & Inputbox N Y
10- Color Dialog N Y
11- Borders N Y
12- PasswordField N Y
13- RadioButton N Y
14- Tree N Y
15- Table N Y
16- ToggleButton N Y
17- lookand Feel N Y
18- ProgressBar N Y
19- Packages java.awt.*; javax.swing.*; x - for extended
20- Classes Button/Applet JButton / JApplet
21- components adding -

awt -
add(a1);
add(a2);
add(a3);
swing -
Component c = getContentPane();
c.add(a1);
c.add(a2);
c.add(a3);
c.add(a4);

JApplet & JFrame act like a container for other components.

but no need in jdk1.5 & jdk1.6 , in jdk1.5 & 1.6 we
can add components like awt.

** for changing the backcolor we need it(JApplet & JFrame).

jdbc notes

JDBC -

ODBC - ODBC stands for Open Database Connectivity. it is set of APIs
Written in C Language. used for making the Connectivity with
Front end to backend. it is product of Microsoft.

ODBC Application has 5 Layers -

*1 - Application Layer - front end
2 - ODBC interface Layer
3 - Driver Manager Layer
*4 - Driver Layer - DSN
*5 - Data Source Layer. - Backend

1 - Application Layer - it's provide the GUI & business Logics written
in language like C , C++ , VB , VC++ , C# ,
JAVA etc.
Layout for users.
2 - ODBC Interface Layer - it's provide the Interface between
Application Layer & ODBC.
3 - Driver Manager Layer - it's manage the All Drivers avaliable in
System.
4 - Driver Layer - it is the actual components.

Oracle Driver - Oracle
SQL server Driver - SQL Server
VFP Driver - VFP(Visual Fox Pro)
Access Driver - Access
MySQL Driver - MySQL
Fox pro Driver - Fox Pro

5 - Data Source Layer - it's depends on the Driver Layer.

VB <---> ODBC <----> Database(SQL / Oracle / Access)
MS MS - valid
Java <----> ODBC - invalid


JDBC - JDBC stands for java Database Connectivity. it is set of APIs
, used for making the Connectivity with Java to Backend.
it is the product of Sun MicroSystem.

JDBC Application has 2 Layers.

1 - Application Layer - coding
2 - Driver Layer - DSN

JDBC is the Upper Layer of ODBC. its convert Java code to ODBC
equivalent Code.

Sun code to Microsoft Code.

JDBC -
1 - with ODBC Driver.

Java <---> JDBC <---> ODBC <--> Backend(data base)

2 - with thin Layer (Oracle) -- direct with database without IIIrd party tool

Java <---> JDBC thin Layer <-----> Oracle

Oracle8i = sun + Oracle

JDBC complete in 6 steps --

1 - to create a Driver in control panel.

start -> controlpanel -> admin tool(not in 98/NT) ->
ODBC DataSource -> add new -> name & database select -> OK

coding
2 - to import JDBC ODBC Bridge (to activate all drivers)-

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); - for ODBC driver
Class.forName("oracle.jdbc.driver.OracleDriver"); for thin Layer Driver


3 - to create the Connection Object.

Connection c = DriverManager.getConnection("jdbc:odbc:vishal");
-- with Access & VFP
Connection c = DriverManager.getConnection("jdbc:odbc:vishal","scott","tiger");

-- with Oracle & SQL Server

4 - to create the Statement Object for executing SQL statement.

Statement s = c.createStatement();

5 - to execute the SQL statement , if statement is the select
statement then data stored inside the ResultSet object.

ResultSet rs = s.executeQuery("select * from emp"); - only for select statement
s.execute(any sql statement); - insert / update / delete / alter / drop / create

6 - display

while(rs.next()) // while rs not empty. next record exists
{
System.out.println(rs.getString(1)); - Ist Column
System.out.println(rs.getString(2)); - IInd Column
System.out.println(rs.getString(3)); - IIIrd Column
}




- for running oracle in XP , if says - Oracle not avaliable

connect - internal/oracle

sql>startup

sql>exit & reconnect with any user

oracle provides default 4 users.

sys / change_on_install - ABCDE
internal/oracle - test123
system/manager - abc123
simple user
scott/tiger - abc1
abc1/abc2 - abc12

-- for creating new user , need to connect with
system/manager
-- to create new user
create user abc1 identified by abc2
-- to assign privileges -
grant connect,resource,dba to abc2
-- to connect with abc2 user
login abc1/abc2
or
sql>connect abc1/abc2



CONNECT WITH ORACLE THIN LAYER

-- to display the current database name

connect oracle - system/manager
uname pass
SQL> select name from v$database;

display the database name. (ORCL)

find out the classes111.zip paste on c:\ drive
(oraclehome/ora81/jdbc/lib/classes111.zip)
set classpath with classess111.zip

set classpath=c:\classes111.zip;.

Class.forName("oracle.jdbc.driver.OracleDriver"); // for thin layer connectiviry
Connection c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","gaurav","gupta");
with thinlayer:@serveradd:oracleport:dbname,user,pass
-- to create a procedure in oracle

create or replace procedure mysal(x in number,s out number)
is
begin
select sal into s from emp where empno=x;
end;


- to execute procedure in oracle

SQL> var a number
SQL> exec mysal(1002,:a)
SQL> print a


- to call procedure in java

SQL commands

SQL*Plus: Release 8.1.5.0.0 - Production on Sat Sep 1 08:06:50 2007
(c) Copyright 1999 Oracle Corporation. All rights reserved.
Connected to:Oracle8i Enterprise Edition Release 8.1.5.0.0 - ProductionWith the Partitioning and Java optionsPL/SQL Release 8.1.5.0.0 - Production
SQL> connect system/managerConnected.SQL> create user gaurav identified by gupta 2 /
User created.
SQL> grant connect,resource,dba to gaurav 2 /
Grant succeeded.
SQL> connect gaurav/guptaConnected.SQL> select * from emp;select * from emp *ERROR at line 1:ORA-00942: table or view does not exist
SQL> select * from tab;
no rows selected
SQL> create table emp 2 ( 3 empno number(4), 4 ename varchar(20). 5 SQL> edWrote file afiedt.buf
1 create table emp 2 ( 3 empno number(4), 4 ename varchar(20), 5 sal number(7,2) 6* )SQL> /
Table created.
SQL> insert into emp values(1001,'ankit Ji',23000) 2 /
1 row created.
SQL> edWrote file afiedt.buf
1* insert into emp values(1002,'Gaurav Ji',25000)SQL> /
1 row created.
SQL> edWrote file afiedt.buf
1* insert into emp values(1005,'abhi Ji',24000)SQL> /
1 row created.
SQL> edWrote file afiedt.buf
1* insert into emp values(1009,'anoop Ji',22000)SQL> /
1 row created.
SQL> commit 2 /
Commit complete.
SQL> select * from emp 2 /
EMPNO ENAME SAL--------- -------------------- --------- 1001 ankit Ji 23000 1002 Gaurav Ji 25000 1005 abhi Ji 24000 1009 anoop Ji 22000
SQL> select name from v$database 2 /
NAME---------ORCL
SQL> create or replace procedure mysal(x in number,s out number) 2 is 3 begin 4 select sal into s from emp where empno=x; 5 end; 6 /
Procedure created.
SQL> var a numberSQL> exec mysal(1002,:a)
PL/SQL procedure successfully completed.
SQL> print a
A--------- 25000
SQL> edWrote file afiedt.buf
1 create or replace procedure mysal1() 2 is 3 begin 4 update emp set sal=sal+sal*.3; 5* end;SQL> /
Warning: Procedure created with compilation errors.
SQL> edWrote file afiedt.buf
1 create or replace procedure mysal1 2 is 3 begin 4 update emp set sal=sal+sal*.3; 5* end;SQL> /
Procedure created.
SQL> select * from emp 2 /
EMPNO ENAME SAL--------- -------------------- --------- 1001 ankit Ji 23000 1002 Gaurav Ji 25000 1005 abhi Ji 24000 1009 anoop Ji 22000
SQL> exec mysal1
PL/SQL procedure successfully completed.
SQL> select * from emp 2 /
EMPNO ENAME SAL--------- -------------------- --------- 1001 ankit Ji 29900 1002 Gaurav Ji 32500 1005 abhi Ji 31200 1009 anoop Ji 28600
SQL> /
EMPNO ENAME SAL--------- -------------------- --------- 1001 ankit Ji 29900 1002 Gaurav Ji 32500 1005 abhi Ji 31200 1009 anoop Ji 28600
SQL> /
EMPNO ENAME SAL--------- -------------------- --------- 1001 ankit Ji 29900 1002 Gaurav Ji 32500 1005 abhi Ji 31200 1009 anoop Ji 28600
SQL> edWrote file afiedt.buf
1* select * from empSQL> edWrote file afiedt.buf
line 5 truncated. 1 create or replace procedure mysal1(x in number) 2 is 3 begin 4 update emp set sal=sal+x; 5* endSQL> /
Warning: Procedure created with compilation errors.
SQL> showerrorSP2-0042: unknown command "showerror" - rest of line ignored.SQL> show errorErrors for PROCEDURE MYSAL1:
LINE/COL ERROR-------- -----------------------------------------------------------------6/0 PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ; delete exists prior The symbol ";" was substituted for "end-of-file" to continue.
SQL> ed Wrote file afiedt.buf
1 create or replace procedure mysal1(x in number) 2 is 3 begin 4 update emp set sal=sal+x; 5* end;SQL> /
Procedure created.
SQL> select * FROM EMP 2 /
EMPNO ENAME SAL--------- -------------------- --------- 1001 ankit Ji 88397.39 1002 Gaurav Ji 95823.25 1005 abhi Ji 92110.32 1009 anoop Ji 84684.46
SQL>