コード例 #1
0
ファイル: grid_shmobj.py プロジェクト: davidells/pyshmobj
    def __init__(self):
        self.a = shmobj.SHMLST([])
        self.b = shmobj.SHMLST([])
        self.st = shmobj.SHMLST([])
        self.pq = shmobj.SHMLST([])

        for i in range(ROWS+2):
            self.a.append(shmobj.SHMLST([]))
            self.b.append(shmobj.SHMLST([]))
            self.st.append(shmobj.SHMDBL(0))
            for j in range(COLUMNS+2):
                self.a[i].append(shmobj.SHMDBL(0))
                self.b[i].append(shmobj.SHMDBL(0))

        for i in range(ROWS+1):
            self.pq.append(shmobj.SHMDBL(0))

        self.pqbeg = shmobj.SHMINT(0)
        self.pqend = shmobj.SHMINT(0)
        self.niters = shmobj.SHMINT(0)
        self.nprocs = shmobj.SHMINT(0)
        self.nrows = shmobj.SHMINT(0)
        self.ncols = shmobj.SHMINT(0)
        self.pq_mutex = shmobj.semaphore()
        #self.pq_cv = condition var???
        self.nbythread = shmobj.SHMLST([])
        for i in range(MAXTHREADS):
            self.nbythread.append(shmobj.SHMDBL(0))
        self.barrier_lock = shmobj.semaphore()
コード例 #2
0
ファイル: bucketsort.py プロジェクト: davidells/pyshmobj
    # for line in f:
    #    linenums = line.split(' ')
    #    nums.extend(linenums)
    # nums = map(int, nums)

    # nums = get_1k_nums()
    nums = get_random_num_list(4000)
    print "Initial mem: ", shmobj.freecount()

    n = len(nums)
    interval_size = n / numchildren
    remintervals = n % numchildren

    b = shmobj.barrier(numchildren)
    buckets = shmobj.SHMLST([])
    buckets_sem = shmobj.semaphore(val=1)

    for i in range(0, numchildren):
        rc = os.fork()
        if rc == 0:
            buckets_sem.wait()
            buckets.append(shmobj.SHMLST([]))
            buckets_sem.post()
            start = i * interval_size
            end = start + interval_size
            if i == (numchildren - 1):
                end = end + remintervals

            b.join()

            # print '%d: got interval [%d, %d)' % (os.getpid(), start, end)
コード例 #3
0
ファイル: semtest.py プロジェクト: davidells/pyshmobj
#!/usr/bin/env python

import os, sys, time
import shmobj

sem = shmobj.semaphore()

for i in range(0,5):
    rc = os.fork()
    if rc == 0:
        print "%s: new forked child started..." % os.getpid()
        sem.wait()
        print "%s: obtained lock" % os.getpid()
        time.sleep(1)
        print "%s: releasing lock" % os.getpid()
        sem.post()
        sys.exit(0)

for i in range(0,5):
    os.wait()

print "All children done, parent exiting..."
コード例 #4
0
ファイル: nqshmobj.py プロジェクト: davidells/pyshmobj
#!/usr/bin/env python

import sys, os, time, shmobj

global nsolutions, solution_sem, work_sem, wpool, nqueens, nprocs, quiet

nsolutions = shmobj.SHMINT(0)
solution_sem = shmobj.semaphore()
work_sem = shmobj.semaphore()
nqueens = 4
nprocs = 1
quiet = 0

def getwork():
    work_sem.wait()
    if len(wpool) == 0:
        work_sem.post()
        return None
    temp = wpool.pop()
    work_sem.post()
    return temp

def test_position(col, row, rows):
    for i in range(col):
        tempval = int(rows[i])
        if tempval+i == col+row  \
        or i-tempval == col-row  \
        or tempval == row:
            return 1
    return 0