Beispiel #1
0
def main(argv):
    inputfile = ''
    outputfile = ''
    debug = False
    try:
        opts, args = getopt.getopt(argv,"hi:o:d",["ifile=","ofile="])
    except getopt.GetoptError:
        print 'single.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'single.py -i <inputfile> -o <outputfile> -d for debug'
            sys.exit()
        elif opt in ("-d", "--debug"):
            debug = True
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
        

    try:
        fi = open(inputfile,"r")
        fl = open(outputfile,"a")
    except IOError:
        print 'main.py -i <inputfile> -o <outputfile>'
        sys.exit(2)
    l = []
    pols = []
    files = [inputfile]
    for fileName in files:
        save = outputfile
        f = open(fileName,'r')

        #read, pols = recoverfile(save, f)
        if True:
            for line in f:
                try:
                    pol = Polynomial(line)
                    pols.append(pol)
                except Exception as e:
                    print line
                    sys.exit(2)
    result = defaultdict(list)
    print len(pols)
    for pol in pols:
        if len(pol.coefs()) > 1:
            red = Reduction(debug)
            count = red.reduction(pol.coefs())
            result =  str(pol.coefs()) + ":" + str(count)
            print result
            fl.write(result + "\n")
Beispiel #2
0
 def run(self):
     print "Starting thread: " + str(self.threadID) + '\n'
     for i in self.polynomials:
         reduc = Reduction()
         self.lockscreen.acquire()
         print 'Thread: '+ str(self.threadID) + ' Doing: ' + str(i.coefs())
         self.lockscreen.release()
         count = reduc.reduction(i.coefs())
         self.locker.acquire()
         r = str(i.coefs()) + ":" + str(count)
         f = open(self.save, "a")
         f.write(r + '\n')
         f.close()
         self.locker.release()
         self.lockscreen.acquire()
         #print r
         self.lockscreen.release()
         del reduc
Beispiel #3
0
		print "I am here"
		# threads = []
		# i = 0
		# j = 2
		# for temp in range(0, len(pols)/2):
		# 	if (j > len(pols)):
		# 		j = len(pols)
		# 		thread = ThreadCount(temp,lockScreen, lock, pols[i:j], save)
		# 		i = j+1
		# 		j += 2
		# 		threads.append(thread)
		# for thread in threads:
		# 	thread.start()
			# for current in threads:
		# 	current.join()
		for i in pols:
			print "doing pol: " + str(i.coefs())
			reduc = Reduction()
			count = reduc.reduction(i.coefs())
			r = str(i.coefs()) + ":" + str(count)
			f_save.write(r + '\n')
			del reduc