예제 #1
0
파일: test.py 프로젝트: johannesHen/pyDOOMS
def BarrierTest(workerID):
    """
    Test barrier by incrementing a single value over multiple barriers
    """
    loops = 10
    increment = 1
    results = []

    if (workerID == 0):
        for i in range(PyDOOMS.getNumberOfWorkers()):
            TestObject(i)

    PyDOOMS.barrier()
    obj = PyDOOMS.get(workerID)
    PyDOOMS.barrier()

    for i in range(loops):
        results.append(obj.value)
        obj.value += increment

        PyDOOMS.objectUpdated(obj,"value")
        PyDOOMS.barrier()

    results.append(obj.value)

    if not (results[0] == 0*increment and results[1] == 1*increment and results[2] == 2*increment and
                results[3] == 3*increment and results[4] == 4*increment):
        logging.critical("Worker" + str(workerID) + ", results: " + str(results))
        raise Exception
예제 #2
0
def monteCarlo(workerID, myDarts):

    if (workerID == 0):
        for boardID in range(PyDOOMS.getNumberOfWorkers()):
            Board(boardID)

    PyDOOMS.barrier()

    start = time.time()
    board = PyDOOMS.get(workerID)

    # Compute
    while (myDarts > 0):
        x = random.random()
        y = random.random()
        dist = math.sqrt((x*x)+(y*y))
        if (dist <= 1.0):
            board.hit()
        else:
            board.miss()

        myDarts = myDarts - 1
    board.ready = True

    PyDOOMS.objectUpdated(board, "hits")
    PyDOOMS.objectUpdated(board, "darts")
    PyDOOMS.objectUpdated(board, "ready")


    PyDOOMS.barrier()

    # Sum result
    if (workerID == 0):
        pi = 0.0
        i = 0
        while i < PyDOOMS.getNumberOfWorkers():
            b = PyDOOMS.get(i)
            if b.ready:
                pi = pi + b.calc_pi()
                i = i + 1
            else:
                logging.critical("Board: " + str(i) + " - " + str(b.ready))
                time.sleep(1)

        logging.info("Pi: " + str(pi / PyDOOMS.getNumberOfWorkers()) + " calculated in " + str(time.time() - start) + " seconds.")

    logging.info("Worker: " + str(workerID) + " dead. Worked for " + str(time.time() - start) + " seconds.")
예제 #3
0
def gaussSeidel(workerID, matrixSize):
    global numberOfWorkers, matrixOffset
    numberOfWorkers = PyDOOMS.getNumberOfWorkers()
    matrixOffset = 100

    chunkSize = (matrixSize-2) / numberOfWorkers

    if workerID == 0:
        if ((matrixSize - 2) % numberOfWorkers) != 0:
            print "Warning: Matrix size incompatible with number of workers, some columns may not be calculated"

        matrix = generateMatrix(matrixSize)

        generateSharedRowChunks(matrix, chunkSize)

        for w in range(numberOfWorkers):
            WorkerInfo(w)

    PyDOOMS.barrier()

    logging.info("Worker: "  + str(workerID) + " assigned chunk " + str(workerID+1))

    start = time.time()
    for iteration in range(1):

        workerInfo = PyDOOMS.get(workerID)
        workerInfo.error = 0.0

        for row in range(1,matrixSize-1):
            if (workerID != 0):
                while (PyDOOMS.get(workerID - 1).progress < row):
                    PyDOOMS.barrier()

            workerChunk = workerID + 1

            westChunk = PyDOOMS.get(getChunkRowIndex(row,workerChunk-1))
            northChunk = PyDOOMS.get(getChunkRowIndex(row-1,workerChunk))
            eastChunk = PyDOOMS.get(getChunkRowIndex(row,workerChunk+1))
            southChunk = PyDOOMS.get(getChunkRowIndex(row+1,workerChunk))
            centerChunk = PyDOOMS.get(getChunkRowIndex(row,workerChunk))

            if chunkSize == 1:
                for column in range(len(centerChunk.rowChunk)):
                    newValue = 0.25 * (northChunk.rowChunk[column] + southChunk.rowChunk[column] +
                                       eastChunk.rowChunk[column] + westChunk.rowChunk[column])

                    workerInfo.error += abs(centerChunk.rowChunk[column] - newValue)
                    centerChunk.rowChunk[column] = newValue

            else:
                for column in range(len(centerChunk.rowChunk)):
                    if column == 0:
                        newValue = 0.25 * (northChunk.rowChunk[column] + southChunk.rowChunk[column] +
                                           westChunk.rowChunk[chunkSize-1] + centerChunk.rowChunk[column+1])

                    elif column == chunkSize-1:
                        newValue = 0.25 * (northChunk.rowChunk[column] + southChunk.rowChunk[column] +
                                           centerChunk.rowChunk[column-1] + eastChunk.rowChunk[0])

                    else:
                        newValue = 0.25 * (northChunk.rowChunk[column] + southChunk.rowChunk[column] +
                                           centerChunk.rowChunk[column-1] + centerChunk.rowChunk[column+1])

                    workerInfo.error += abs(centerChunk.rowChunk[column] - newValue)
                    centerChunk.rowChunk[column] = newValue

            workerInfo.progress = row
            PyDOOMS.objectUpdated(workerInfo, "progress")
            PyDOOMS.objectUpdated(workerInfo, "error")
            PyDOOMS.objectUpdated(centerChunk, "rowChunk")
            PyDOOMS.barrier()


        if (workerID != 0):
            previousWorker = PyDOOMS.get(workerID - 1)
            previousWorker.progress = 0
            #PyDOOMS._comm.addOutgoingUpdate(previousWorker.ID, "progress", previousWorker.progress)

        if (workerID == numberOfWorkers - 1):
            globalError = 0.0

            for w in range(numberOfWorkers):
                globalError += PyDOOMS.get(w).error

            logging.info("GlobalError: " + str(globalError))

        for i in range(workerID,numberOfWorkers):
            PyDOOMS.barrier()

    logging.info("Worker: " + str(workerID) + " done in " + str(time.time() - start) + " seconds")
예제 #4
0
    PyDOOMS.objectUpdated(board, "hits")
    PyDOOMS.objectUpdated(board, "darts")
    PyDOOMS.objectUpdated(board, "ready")


    PyDOOMS.barrier()

    # Sum result
    if (workerID == 0):
        pi = 0.0
        i = 0
        while i < PyDOOMS.getNumberOfWorkers():
            b = PyDOOMS.get(i)
            if b.ready:
                pi = pi + b.calc_pi()
                i = i + 1
            else:
                logging.critical("Board: " + str(i) + " - " + str(b.ready))
                time.sleep(1)

        logging.info("Pi: " + str(pi / PyDOOMS.getNumberOfWorkers()) + " calculated in " + str(time.time() - start) + " seconds.")

    logging.info("Worker: " + str(workerID) + " dead. Worked for " + str(time.time() - start) + " seconds.")



darts = 4000000 / PyDOOMS.getNumberOfWorkers()

PyDOOMS.execute(monteCarlo, darts)

예제 #5
0
def RedBlackGaussSeidel(workerID, matrixSize):

    global numberOfWorkers, matrixOffset
    numberOfWorkers = PyDOOMS.getNumberOfWorkers()
    matrixOffset = 100

    chunkSize = (matrixSize-2) / numberOfWorkers

    if workerID == 0:
        if ((matrixSize - 2) % numberOfWorkers) != 0:
            print "Warning: Matrix size - 2 is not divisible with number of workers, some columns may not be calculated"

        start = time.time()
        generateSharedMatrixRows(matrixSize)
        logging.info("Time to generate shared matrix rows: " + str(time.time()-start))

        for w in range(numberOfWorkers):
            WorkerInfo(w)


    PyDOOMS.barrier()

    logging.info("Worker: " + str(workerID) + " assigned rows " + str(workerID*chunkSize+1) + "-" + str(workerID*chunkSize + chunkSize + 1))


    start = time.time()
    for iteration in range(1):

        workerInfo = PyDOOMS.get(workerID)
        workerInfo.error = 0.0

        enum = dict(enumerate(['Red', 'Black']))
        for color in enum:

            for row in range(workerID*chunkSize + 1,workerID*chunkSize + chunkSize + 1):

                northRow = PyDOOMS.get(matrixOffset + row - 1)
                centerRow = PyDOOMS.get(matrixOffset + row)
                southRow = PyDOOMS.get(matrixOffset + row + 1)

                for column in range((color + row) % 2 + 1, matrixSize-1, 2):
                    newValue = 0.25 * (northRow.row[column] + southRow.row[column] +
                                       centerRow.row[column-1] + centerRow.row[column+1])

                    workerInfo.error += abs(centerRow.row[column] - newValue)
                    centerRow.row[column] = newValue

                PyDOOMS.    objectUpdated(centerRow, "row")

            PyDOOMS.objectUpdated(workerInfo, "error")
            PyDOOMS.barrier()

        if (workerID == numberOfWorkers - 1):
            globalError = 0.0

            for w in range(numberOfWorkers):
                globalError += PyDOOMS.get(w).error

            logging.info("Iteration " + str(iteration+1) + " global error = " + str(globalError))

    logging.info("Worker: " + str(workerID) + " done in " + str(time.time() - start) + " seconds")
예제 #6
0
파일: LU.py 프로젝트: johannesHen/pyDOOMS
def workerList(size):
    list = []
    for i in range(blocksPerSide+1):
        for j in range(i*i):
            list.append(j % PyDOOMS.getNumberOfWorkers())
    return list