示例#1
0
		f = open(fileName,'r')
		read, pols = recoverfile(save, f)
		if read:
			for line in f:
				pol = Polynomial(line)
				pols.append(pol)
		
		print len(pols)
		threads = []
		i = 0
		j = 1
		print "starting...."
		for temp in range(0, len(pols)):
			if (j > len(pols)):
				j = len(pols)
			thread = ThreadCount(temp,lockScreen, lock, pols[i:j], save)
			i = j+1
			j += 1
			threads.append(thread)

		for thread in threads:
			thread.start()
		for current in threads:
			current.join()






示例#2
0
def main(argv):
   inputfile = ''
   outputfile = ''
   n_threads = 4
   try:
      opts, args = getopt.getopt(argv,"hi:o:t:",["ifile=","ofile=", "threads="])
   except getopt.GetoptError:
      print 'main.py -i <inputfile> -o <outputfile> -t <numberofthreads>'
      sys.exit(2)
   for opt, arg in opts:
    print opt
    if opt == '-h':
        print 'main.py -i <inputfile> -o <outputfile> -t <numberofthreads>'
        sys.exit()
    elif opt in ("-i", "--ifile"):
        inputfile = arg
    elif opt in ("-o", "--ofile"):
        outputfile = arg
    elif opt in ("-t", "--threads"):
        n_threads = int(arg)
   try:
    fi = open(inputfile,"r")
   except IOError:
        print 'Error to open the file'
        print 'main.py -i <inputfile> -o <outputfile> -t <numberofthreads>'
        sys.exit(2)
   fl = open(outputfile,"a")
   print 'Input file is "', inputfile
   print 'Output file is "', outputfile
   print "number of threds " + str(n_threads)
   lock = threading.Lock()
   lockScreen = threading.Lock()
   files = [inputfile]
   for fileName in files:
    save = outputfile
    f = open(fileName,'r')
    read, pols = recoverfile(save, f)
    if read:
        for line in f:
            try:
              pol = Polynomial(line)
              pols.append(pol)
            except Exception as e:
              print line
              sys.exit(2)

    print len(pols)
    threads = []
    si = int(math.ceil(float(len(pols))/float(n_threads)))
    print "si + " + str(si)
    if si == 0:
      si = 1

    i = 0
    j = si
    print "starting...."
    for temp in range(0, n_threads):
        if (j > len(pols)):
            j = len(pols)
        print "i = " + str(i)
        print "j = " + str(j)
        thread = ThreadCount(temp,lockScreen, lock, pols[i:j], save)
        i = j
        j += si
        threads.append(thread)

    for thread in threads:
        thread.start()
    for current in threads:
        current.join()

    print "Finished."