示例#1
0
#!/usr/bin/env python

# Find all primes in the given range using trial division

import sys
from trialdiv import trialdiv
from writeresults import writeresults

args = xrange(int(sys.argv[1]),int(sys.argv[2])+1)

primesFound = 0

for num in args:
	if(trialdiv(num)):
		primesFound += 1

writeresults("trialdiv",int(sys.argv[2])-int(sys.argv[1])+1,int(primesFound))
示例#2
0
jobsInExtraBatch = numJobs%jobsPerBatch
#print "Jobs in extra batch: " + str(jobsInExtraBatch)
#print "Start of extra batch: " + str(rangeStart)
#print "End of extra batch: " + str(rangeStart+jobsInExtraBatch)
numJobs -= jobsInExtraBatch # remove the modulo just for simplicity
batchesSent = 0 # amount of batches sent EXCLUDING extra batch
# first do the extra batch to reduce the complexity of code
if jobsInExtraBatch != 0:
	jobs.append( job_server.submit(batch , (rangeStart,rangeStart+jobsInExtraBatch,int(sys.argv[3]),), (fermat,), ("random","time",)) )
	#print "Extra:" , rangeStart , rangeStart+jobsInExtraBatch

if numJobs <= 0:
	for job in jobs:
		primesFound+=int(job())
	#print "No more batches needed."
	writeresults("fermat",str(rangeStart)+"to"+str(rangeEnd)+"_b"+sys.argv[3],int(primesFound))
	exit()

batchRangeStart = 0
if jobsInExtraBatch == 0:
	batchRangeStart = rangeStart
else:
	batchRangeStart = rangeStart+jobsInExtraBatch
batchRangeEnd = batchRangeStart+jobsPerBatch
if batchRangeEnd > rangeEnd: batchRangeEnd = rangeEnd
#print "Start of batch 1:" , batchRangeStart
#print "End of batch 1:" , batchRangeEnd
jobs.append( job_server.submit(batch , (batchRangeStart,batchRangeEnd,int(sys.argv[3]),), (fermat,), ("random","time",)) )
batchesSent=1

#print "Amount of batches:" , numJobs/jobsPerBatch
示例#3
0
#!/usr/bin/env python

# Find all primes in the given range using Fermat's Primality Test

import sys
from fermat import fermat
from writeresults import writeresults

args = xrange(int(sys.argv[1]),int(sys.argv[2])+1)

primesFound = 0

for num in args:
	if(fermat(num)):
		primesFound += 1

writeresults("fermat",int(sys.argv[2])-int(sys.argv[1])+1,int(primesFound))
#!/usr/bin/env python

# Find all primes in the given range using the Miller-Rabin Primality Test

import sys
from millerrabin import millerrabin
from writeresults import writeresults

args = xrange(int(sys.argv[1]),int(sys.argv[2])+1)

primesFound = 0

for num in args:
	if(millerrabin(num)):
		primesFound += 1

writeresults("millerrabin",int(sys.argv[2])-int(sys.argv[1])+1,int(primesFound))
jobsInExtraBatch = numJobs%jobsPerBatch
#print "Jobs in extra batch: " + str(jobsInExtraBatch)
#print "Start of extra batch: " + str(rangeStart)
#print "End of extra batch: " + str(rangeStart+jobsInExtraBatch)
numJobs -= jobsInExtraBatch # remove the modulo just for simplicity
batchesSent = 0 # amount of batches sent EXCLUDING extra batch
# first do the extra batch to reduce the complexity of code
if jobsInExtraBatch != 0:
	jobs.append( job_server.submit(batch , (rangeStart,rangeStart+jobsInExtraBatch,int(sys.argv[3]),), (millerrabin,), ("random","time",)) )
	#print "Extra:" , rangeStart , rangeStart+jobsInExtraBatch

if numJobs <= 0:
	for job in jobs:
		primesFound+=int(job())
	#print "No more batches needed."
	writeresults("millerrabin",str(rangeStart)+"to"+str(rangeEnd)+"_b"+sys.argv[3],int(primesFound))
	exit()

batchRangeStart = 0
if jobsInExtraBatch == 0:
	batchRangeStart = rangeStart
else:
	batchRangeStart = rangeStart+jobsInExtraBatch
batchRangeEnd = batchRangeStart+jobsPerBatch
if batchRangeEnd > rangeEnd: batchRangeEnd = rangeEnd
#print "Start of batch 1:" , batchRangeStart
#print "End of batch 1:" , batchRangeEnd
jobs.append( job_server.submit(batch , (batchRangeStart,batchRangeEnd,int(sys.argv[3]),), (millerrabin,), ("random","time",)) )
batchesSent=1

#while (batchesSent*jobsPerBatch) < numJobs :
#!/usr/bin/env python

# Find all primes in the given range using the Lucas-Lehmer Primality Test

import sys
from lucaslehmer import lucaslehmer
from writeresults import writeresults

args = xrange(int(sys.argv[1]),int(sys.argv[2])+1)

primesFound = 0

for num in args:
	if(lucaslehmer(num)):
		primesFound += 1
		print "M%d"%num,
		sys.stdout.flush()

writeresults("lucaslehmer",int(sys.argv[2])-int(sys.argv[1])+1,int(primesFound))

jobsInExtraBatch = numJobs%jobsPerBatch
#print "Jobs in extra batch: " + str(jobsInExtraBatch)
#print "Start of extra batch: " + str(rangeStart)
#print "End of extra batch: " + str(rangeStart+jobsInExtraBatch)
numJobs -= jobsInExtraBatch # remove the modulo just for simplicity
batchesSent = 0 # amount of batches sent EXCLUDING extra batch
# first do the extra batch to reduce the complexity of code
if jobsInExtraBatch != 0:
	jobs.append( job_server.submit(batch , (rangeStart,rangeStart+jobsInExtraBatch,int(sys.argv[3]),), (solovaystrassen,jacobi,gcd,), ("random","time",)) )
	#print "Extra:" , rangeStart , rangeStart+jobsInExtraBatch

if numJobs <= 0:
	for job in jobs:
		primesFound+=int(job())
	#print "No more batches needed."
	writeresults("solovaystrassen",str(rangeStart)+"to"+str(rangeEnd)+"_b"+sys.argv[3],int(primesFound))
	exit()

batchRangeStart = 0
if jobsInExtraBatch == 0:
	batchRangeStart = rangeStart
else:
	batchRangeStart = rangeStart+jobsInExtraBatch
batchRangeEnd = batchRangeStart+jobsPerBatch
if batchRangeEnd > rangeEnd: batchRangeEnd = rangeEnd
#print "Start of batch 1:" , batchRangeStart
#print "End of batch 1:" , batchRangeEnd
jobs.append( job_server.submit(batch , (batchRangeStart,batchRangeEnd,int(sys.argv[3]),), (solovaystrassen,jacobi,gcd,), ("random","time",)) )
batchesSent=1

#while (batchesSent*jobsPerBatch) < numJobs :
#!/usr/bin/env python

# Find all primes in the given range using the Solovay-Strassen Primality Test

import sys
from solovaystrassen import solovaystrassen
from writeresults import writeresults

args = xrange(int(sys.argv[1]),int(sys.argv[2])+1)

primesFound = 0

for num in args:
	if (solovaystrassen(num)):
		primesFound += 1

writeresults("solovaystrassen",int(sys.argv[2])-int(sys.argv[1])+1,int(primesFound))