Sieve of Eratosthenes - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Sieve of Eratosthenes

Description:

setup timer 0. tc = new ... of the array stands for a odd number // starting with 3. for (j = 0; j size; ... now set all of the multiples of // the current ... – PowerPoint PPT presentation

Number of Views:95
Avg rating:3.0/5.0
Slides: 13
Provided by: hask
Category:

less

Transcript and Presenter's Notes

Title: Sieve of Eratosthenes


1
Sieve of Eratosthenes
  • Lecture L7.2

2
Sieve of Eratosthenes in Java
package com.research.hanna import
com.ajile.drivers.gptc.TimerCounter /
_at_author Darrin Hanna / public class Sieve
  private static int j, a, b private static
int primeCount private static int flags new
int1024 private static int size private
static TimerCounter tc public static void
main(String args) int count2 size
1024
3
TimerCounter.setPrescalerClockSource(
TimerCounter.INTERNAL_PERIPHERAL_CLOCK )   //
Assuming Internal Peripheral clock is 50MHz, //
then Prescaler clock out is 1MHz TimerCounter.se
tPrescalerReloadRegisterValue( 50
) TimerCounter.setPrescalerEnabled( true
)   // setup timer 0 tc new TimerCounter( 0
) //tc.setMode_IO_Line_B( TimerCounter.TIMER_0_OU
TPUT_DIVIDE_BY_2 ) tc.setExternalTimerEnableMode
( TimerCounter.TIMER_ENABLED_ONLY_VIA_MTEN_AND_TR
IGGER ) System.out.println("timer start at "
tc.getCurrentTimeRegisterValue()) tc.setR
eloadRegisterValue( 5000000 ) tc.setMasterTimer
Enabled( true )
4
// first create an array of flags, where //
each member of the array stands for a odd
number // starting with 3. for (j 0 j lt
size j) flagsj 1
primeCount 0 for (j 0 j lt size
j) if (flagsj 1) // found a
prime, count it primeCount // now
set all of the multiples of // the current
prime number to false // because they couldn't
possibly be // prime a 2j 3 // odd
numbers starting with 3 b a j while(b
lt size) flagsb 0 b b
a
5
count2 tc.getCurrentTimeRegisterValue() /
/ output the number of primes System.out.println(
"Number of primes " primeCount) System.o
ut.println("count2 " count2) //Processor
clock is 73.728MHz
6
Sieve of Eratosthenes in Forth
FILL ( b u c -- ) \ fill u bytes at addr b
with char c -ROT \ c b u FOR \ c b OVER
OVER \ c b c b C! 1 \ c b1 NEXT DROP
DROP
7
sieve ( -- n ) \ n no. of prime s 0
1024 1 FILL \ fill flags array 0 \
cnt 1024 FOR \ cnt 1024 R_at_ - \ cnt
j DUP C_at_ \ cnt j flagsj IF \
cnt j DUP 2 3 \ cnt j a (2j
3) TUCK \ cnt a b (a j)
BEGIN \ cnt a b DUP 1024 lt \ cnt a
b f WHILE \ cnt a b 0 OVER C!
\ store 0 at flagsb OVER \ cnt
a b (a b) REPEAT 2DROP 1 \
cnt cnt1 ELSE DROP \ cnt THEN NEXT
8
Flowpath datapath
sieve ( -- n ) \ n no. of prime s 0
1024 1 FILL \ fill flags array 0 \
cnt 1024 FOR \ cnt 1024 R_at_ - \ cnt
j DUP C_at_ \ cnt j flagsj IF \
cnt j DUP 2 3 \ cnt j a (2j
3) TUCK \ cnt a b (a j)
BEGIN \ cnt a b DUP 1024 lt \ cnt a
b f WHILE \ cnt a b 0 OVER C!
\ store 0 at flagsb OVER \ cnt
a b (a b) REPEAT 2DROP 1 \
cnt cnt1 ELSE DROP \ cnt THEN NEXT
9
Flowpath controller
sieve ( -- n ) \ n no. of prime s 0
1024 1 FILL \ fill flags array 0 \
cnt 1024 FOR \ cnt 1024 R_at_ - \ cnt
j DUP C_at_ \ cnt j flagsj IF \
cnt j DUP 2 3 \ cnt j a (2j
3) TUCK \ cnt a b (a j)
BEGIN \ cnt a b DUP 1024 lt \ cnt a
b f WHILE \ cnt a b 0 OVER C!
\ store 0 at flagsb OVER \ cnt
a b (a b) REPEAT 2DROP 1 \
cnt cnt1 ELSE DROP \ cnt THEN NEXT
10
FPGA-VHDL datapath
11
FPGA-VHDL controller
12
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com