data-structure and algorithm

20
Data-Structure and Algorithm Fall 2003 Project 1

Upload: truda

Post on 05-Jan-2016

25 views

Category:

Documents


0 download

DESCRIPTION

Data-Structure and Algorithm. Fall 2003 Project 1. Outline. Goal Mandatory Experiments How to run experiments in Java in C/C++ How to measure the running time in JAVA in C/C++ Tips Grade. Goals. Implement the four MSS algorithms Measure the running time Analyze the result ! - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Data-Structure and Algorithm

Data-Structure and Algorithm

Fall 2003Project 1

Page 2: Data-Structure and Algorithm

Outline

Goal Mandatory Experiments How to run experiments

in Java in C/C++

How to measure the running time in JAVA in C/C++

Tips Grade

Page 3: Data-Structure and Algorithm

Goals

Implement the four MSS algorithms Measure the running time

Analyze the result ! Does the big-O notation work? If not, analyze why!

Experience the power of optimization In various languages (JAVA, C, C++)

Page 4: Data-Structure and Algorithm

Mandatory Experiments

Implement four MSS(max subsequence sum) algorithms in textbook in C/C++ in Java

Run experiments on four different environment on same machine.

JavaInterpreter mode

JIT mode (HotSpot)

C/C++

w/o optimization

with optimizations

Page 5: Data-Structure and Algorithm

How to run experiments in Java(1/2) Just compile .java file with javac. Then run .class file with java in Interpreter mode a

nd JIT (HotSpot) mode. JVM(Java Virtual Machine)

Optimization occurred at runtime Interpreter mode : no optimization JIT mode (HotSpot) : optimization at runtime

You can find out how to change this mode by command line option at java.sun.com for SUN JDK.

Page 6: Data-Structure and Algorithm

How to run experiments in Java(2/2) For more information, visit

http://java.sun.com/docs/ And follow links

“SDK Docs” of your JDK version -> ”SDK Tool Documentation” ->”java”

For example, if you use JDK 1.4.1, you may find doc at http://java.sun.com/j2se/1.4.1/docs/tooldocs/windows/java.html

Page 7: Data-Structure and Algorithm

How to run experiments in C/C++(1/2) For C/C++, optimization occurred at

compile time. Compile C/C++ source file with your

favorite C/C++ compiler. w/o optimization option with optimization options

Then run executable file. You can find out how to disable/enable

optimizations within help documents included in your C/C++ compiler.

Page 8: Data-Structure and Algorithm

How to run experiments in C/C++(2/3) In case of GCC,

You can select the optimizing level with Compile flags : –O1, -O2, -O3

You can find other many optimization options by gcc --help

Page 9: Data-Structure and Algorithm

How to run experiments in C/C++(3/3) MS Visual C++

You can select the optimizing level at Project -> Settings -> C/C++ -> Optimizations Set Optimization with Maximum Speed (You’ll see the /O2 option appearing in the project o

ption textbox) You can find other many optimization options i

n help or by just typing below command in command window. C:\Program Files\Microsoft Visual Studio\VC98\

Bin> cl /?

Page 10: Data-Structure and Algorithm

How to Measure the Running Time in JAVA Using java.lang.System.currentTimeMillis()

Returns the current time in milliseconds in long type.

Usageimport java.lang.*;…{ long start_time, end_time, elapsed_time_in_msec; start_time = System.currentTimeMillis(); { run (); } end_time = System.currentTimeMillis(); elapsed_time_in_msec = end_time – start_time;}

Page 11: Data-Structure and Algorithm

How to Measure the Running Time in C/C++ (1/2) Using clock() or time() in time.h or gettim

eofday() Because resolution of above functions is dependen

t on platform(OS/CPU) and compiler, you have to select it at your own risk.

You can find out about clock() and time() at below website. http://www.gnu.org/manual/glibc-2.2.3/html_chapter/libc_2

1.html#SEC425

Page 12: Data-Structure and Algorithm

How to Measure the Running Time in C/C++ (2/2)#include <sys/time.h> // for getimeofday(struct timeval *)#include <time.h> // for clock() and time(time_t *)…

{

clock_t start_clock_t, end_clock_t; time_t start_time_t, end_time_t; struct timeval start_timeval, end_timeval;

start_clock_t = clock(); time(&start_time_t); gettimeofday(&start_timeval, NULL);

run();

end_clock_t = clock(); time(&end_time_t); gettimeofday(&end_timeval, NULL);

printf("Elapsed time is %f sec\n", ((double) end_clock_t - start_clock_t)/CLOCKS_PER_SEC); printf("Elapsed time is %f sec\n", difftime(end_time_t, start_time_t)); printf("Start time is %ld sec, %ld microsec\n", start_timeval.tv_sec, start_timeval.tv_usec); printf("End time is %ld sec , %ld microsec\n", end_timeval.tv_sec, end_timeval.tv_usec);}

Page 13: Data-Structure and Algorithm

Tips (1) – Exclude I/O time and..

Wrong! Correct!

import java.lang.*;…{ long start_time, end_time, elapsed_time_in_msec; start_time = System.currentTimeMillis(); { init(); System.out.println(“Starting..”); run (); System.out.println(“Finished..”); } end_time = System.currentTimeMillis(); elapsed_time_in_msec = end_time – start_time;}

import java.lang.*;…{ long start_time, end_time,elapsed_time_in_msec; init(); System.out.println(“Starting..”); start_time = System.currentTimeMillis(); { run (); } end_time = System.currentTimeMillis(); System.out.println(“Finished..”); elapsed_time_in_msec = end_time – start_time;}

And exclude initializing phases.

Page 14: Data-Structure and Algorithm

Tips (2) – Garbage Collector in JVM

GC impact upon running time. GC(Garbage Collector) is unexpectedly called d

uring the execution, so the impact on running time should be inspected.

One method to reduce this effect is By increasing initial heap size of JVM by comm

and line option, you can prevent invocation of GC

Page 15: Data-Structure and Algorithm

Tip (3) – other factors..

OS(Operating System) You had better stop all unnecessary services a

nd applications. Cache Misses

Cache misses greatly affects your application’s running time.

I’m not sure you can reduce this effect, but just consider this when analyzing results.

And many other thing can affect running time. Find it yourself!

Page 16: Data-Structure and Algorithm

You have to submit..(1/3)

Report only! No source code required in report!

In Report, Describe specification of your

experimental environment CPU, clock speed, cache information(L1,L2) OS, Compiler, JDK

Page 17: Data-Structure and Algorithm

You have to submit..(2/3)

In Report, Explain which method you use to measure running time.

i.e. clock(), time(), gettimeofday() or other method.And explain why!

Explain which options you used and how do you run experiments. And explain why!

Show experimental result of four algorithm in four different experimental environment.(16 results!) Use graphical representation!

e.g. Graphs, Diagrams

Page 18: Data-Structure and Algorithm

You have to submit..(3/3)

In report, Then analyze the result. This is

most important! Does Big-O notation work?

If not, why? Does optimizations affect running time?

Comparison between w/o opt and w/ opt. Does any other factor affect running time?

Conclusion! Your opinion on performance and Big-O

notation in real world.

Page 19: Data-Structure and Algorithm

Grade (just for this project)

Explain your experiments in detail? But you don’t have to explain MSS algorithm!

Explain your experimental result logically? Correctness of experimental result may be not

considered. Bunch of useless data is negative factor!

Let TA grade your report efficiently :) If you have done more experiments and

find out more, you may get additional point.

Page 20: Data-Structure and Algorithm

Contact Information

TA Email : [email protected] Office : Bld. 301 Rm. 851 If you have any question, plz use bulletin board

at homepage. Submit

Due date : will be announced on homepage Place : Assignment box at Bld. 301 Rm. 851