You are on page 1of 12

NORTH SOUTH UNIVERSITY

ASSIGNMENT-1 Submitted To:


Dr. Abul L. Haque Professor Department of Electrical Engineering and Computer Science

Course Title: Advanced Computer Architecture Course Code: CSE 532

Submitted By: Tamjid Rahman ID: 1130815050 Submission Date: 19.2.2012

Introduction:

At first, we download the software CPU-Z. After running it at four different computers, we list details of those machines in the format below:

Vendor and model Processor Clock speed L2 cache RAM type and size Hard Disk OS Price

PC-1 Acer JE70_CP Intel Pentium P6200 931.2MHz 256 Kbytes DDR3 and 4096 Mbytes 500 GB Windows 7 28000 BDT

PC-2 Intel Cor. DG41WV Intel Core 2 Duo E7500 1595.9MHz 3072 Kbytes DDR3 and 4096 Mbytes 320 GB Windows 7 50000 BDT

PC-3 ASUSTek P5GCMX/1333 Intel Pentium E2200 1200.0 MHz 1024 Kbytes DDR2 and 2048 Mbytes 160 GB Windows 7 37000 BDT

PC-4 HP G61-304NR AMD Sempron M100 900.0 MHz 256 Kbytes 3072 Mbytes 160 GB Windows 7 25000 BDT

Using Turbo C++ compiler, we start doing task 1, task 2 and task 3 as follow:

Task1:
#include<stdio.h> #include<time.h> #include<conio.h> #include<stdlib.h> void main() { long i; char c; FILE *fp1,*fp2; double total_time; clock_t start, end; clrscr(); start = clock(); //time count starts. fp1=fopen("data.txt","w");

fp2=fopen("data_copy.txt","w"); srand(time(NULL)); //seed rand with the system time. for (i = 0; i < 200000; i++) { fprintf(fp1," %ld\n", rand()); } fp1=fopen("data.txt","r"); while((c=getc(fp1))!=EOF) { putc(c,fp2); } fclose(fp1); fclose(fp2); end = clock(); //time count stops. total_time = ((double) (end - start)) / CLK_TCK;//calulate total time printf("\nTime taken to print 200000 random number is: %f", total_time); getch();

Task 2:
#include<stdio.h> #include<conio.h>

#include<stdlib.h> #include<time.h> void merge_sort(int a[15000],int low,int high); void merge(int a[15000],int low,int mid,int high); void main() { clrscr(); int i,j, a[15000],n=12000,l=0; int E[15000]; double total_time; clock_t start, end; start = clock(); //time count starts. srand(time(NULL)); //seed rand with the system time. for (i = 0; i <n; i++) { a[i]=rand(); } merge_sort(a,l,n-1); printf("\n\nSorted list is:"); //The sorted result is stored in array E; i=0; for(j=0;j<n;j++) { //printf(" %d ",a[j]); E[i]=a[j]; i++; } for(i=0;i<n;i++) { E[i]=((1+E[i])*(1.5-E[i]))/E[i];

//printf(" %d ",E[i]); } srand(time(NULL)); for(i=0;i<10;i++) { j=rand(); if(j<n && j>0) { printf("%d ",E[j]); } else i=i-1; } end = clock(); //time count stops. total_time = ((double) (end - start)) / CLK_TCK;//calulate total time printf("\nTime taken %f", total_time); getch(); } void merge_sort(int a[15000],int low,int high) { int mid; if(low<high) { mid=(low+high)/2; merge_sort(a,low,mid); merge_sort(a,mid+1,high); merge(a,low,mid,high); } } void merge(int a[15000],int low,int mid,int high) {

int l,i,j,b[15000],k; l=low; i=low; j=mid+1; while(l<=mid&&j<=high) { if(a[l]<=a[j]) { b[i]=a[l]; l++; } else { b[i]=a[j]; j++; } i++; } if(l>mid) { for(k=j;k<=high;k++) { b[i]=a[k]; i++; } } else { for(k=l;k<=mid;k++) { b[i]=a[k];

i++; } } for(k=low;k<=high;k++) { a[k]=b[k]; } }

Task 3:
#include<stdio.h> #include<time.h> #include<conio.h> #include<stdlib.h> void merge_sort(int a[15000],int low,int high); void merge(int a[15000],int low,int mid,int high); void main() { long i; char c; FILE *fp1,*fp2; double total_time; clock_t start, end; clrscr(); start = clock(); //time count starts.

//task 1 fp1=fopen("data.txt","w");

fp2=fopen("data_copy.txt","w"); srand(time(NULL)); //seed rand with the system time. for (i = 0; i < 200000; i++) { fprintf(fp1," %ld\n", rand()); } fp1=fopen("data.txt","r"); while((c=getc(fp1))!=EOF) { putc(c,fp2); } fclose(fp1); fclose(fp2); //task 2 int j, a[15000],n=12000,l=0; int E[15000]; srand(time(NULL)); //seed rand with the system time. for (i = 0; i <n; i++) { a[i]=rand(); } merge_sort(a,l,n-1); printf("\n\nSorted list is:"); //The sorted result is stored in array E; i=0; for(j=0;j<n;j++) { //printf(" %d ",a[j]); E[i]=a[j]; i++;

} for(i=0;i<n;i++) { E[i]=((1+E[i])*(1.5-E[i]))/E[i]; } for(i=0;i<10;i++) { j=rand(); if(j<n && j>0) { printf("%d ",E[j]); } else i=i-1; } end = clock(); //time count stops. total_time = ((double) (end - start)) / CLOCKS_PER_SEC;//calulate total time printf("\nTime taken to print 10 random number is: %f", total_time); getch(); } void merge_sort(int a[15000],int low,int high) { int mid; if(low<high) { mid=(low+high)/2; merge_sort(a,low,mid); merge_sort(a,mid+1,high); merge(a,low,mid,high); } } void merge(int a[15000],int low,int mid,int high) { int l,i,j,b[15000],k; l=low; i=low; j=mid+1; while(l<=mid&&j<=high) { if(a[l]<=a[j])

{ b[i]=a[l]; l++; } else { b[i]=a[j]; j++; } i++; } if(l>mid) { for(k=j;k<=high;k++) { b[i]=a[k]; i++; } } else { for(k=l;k<=mid;k++) { b[i]=a[k]; i++; } } for(k=low;k<=high;k++) { a[k]=b[k]; } }

Analysis:
1. For recording execution times we run each task three times and take the average given below:

Task Task-1 Task-2 Task-3

PC-1 6.172161 0.32967 6.501831

PC-2 1.978022 0.10989 2.087912

PC-3 2.912088 0.164835 3.351648

PC-4 6.485317 0.401292 6.986605

Now, we plot comparative graph for execution time performance of the four machines as follow:

Fig: comparative graph for execution time

2. Observing the graph, it is easy to suggest that PC-2 is a good choice for task-1 and task-3 but we may choose PC-3 for task-2 because there is very subtle difference between the execution time of PC-2 and PC-3. 3. We know that execution time=1/performance. Using this formula, for task-3 we can plot a price-performance graph for the four different machines. Here we show the value as percentage.

Fig: Price-performance Graph

Conclusion:
If we notice the graph closely, we realize that price and performance are approximately proportional. If our company buys 100 new computers, then my suggestion is that buy 90 computers like PC-3 and 10 computers like PC-2. Although PC-3 is not faster like PC-2 but it will save 13000 BDT per computer. As we have seen earlier that the difference of execution time for task-2 is not much between PC-2 and PC-3.So for heavy work we can use the 10 computers.

You might also like