Exemplo n.º 1
0
 def testClear(self):
     prev_mem = shmobj.freecount()
     newdict = shmobj.SHMDCT({})
     empty_d_size = prev_mem - shmobj.freecount()
     self.shmdict.clear()
     self.assertEqual(len(self.shmdict), 0)
     self.assertEqual(self.start_mem - shmobj.freecount(), 2 * empty_d_size)
     self.shmdict.delete()
     self.setUp()
Exemplo n.º 2
0
 def testDelete(self):
     self.shmdbl_a.delete()
     self.shmdbl_b.delete()
     self.shmdbl_c.delete()
     self.assertEqual(shmobj.freecount(), self.start_mem)
     #Make sure we don't throw an error when we call tearDown
     self.setUp()
Exemplo n.º 3
0
 def setUp(self):
     self.start_mem = shmobj.freecount()
     self.shmdbl_a = shmobj.SHMDBL(4.0)
     self.shmdbl_b = shmobj.SHMDBL(5.0)
     self.shmdbl_c = shmobj.SHMDBL(66.0)
     self.ldbl_a = 4.0
     self.ldbl_b = 5.0
     self.ldbl_c = 66.0
Exemplo n.º 4
0
 def setUp(self):
     self.start_mem = shmobj.freecount()
     self.localdict = {}
     for i in range(0,20):
         key = shmobj.SHMSTR('key%02d' % i)
         val = shmobj.SHMINT(i)
         self.localdict[key] = val
     self.shmdict = shmobj.SHMDCT(self.localdict)
Exemplo n.º 5
0
 def setUp(self):
     self.start_mem = shmobj.freecount()
     self.shmint_a = shmobj.SHMINT(4)
     self.shmint_b = shmobj.SHMINT(5)
     self.shmint_c = shmobj.SHMINT(66)
     self.lint_a = 4
     self.lint_b = 5
     self.lint_c = 66
Exemplo n.º 6
0
 def setUp(self):
     length = 20
     self.start_mem = shmobj.freecount()
     self.locallist = []
     for i in range(0, length):
         val = shmobj.SHMINT(i)
         self.locallist.append(val)
     self.shmlist = shmobj.SHMLST(self.locallist)
     self.last = length - 1
Exemplo n.º 7
0
 def setUp(self):
     self.start_mem = shmobj.freecount()
     self.lstr = "Hello World!"
     self.shmstr = shmobj.SHMSTR("Hello World!")
     self.last = len(self.shmstr) - 1
Exemplo n.º 8
0
#!/usr/bin/python

import shmobj, time, random

LENGTH = 10000

if __name__=='__main__':

    shmobj.add_shmem_pages(1000)
    print "Using %d bytes of memory" % shmobj.freecount()


    shmdict = shmobj.SHMDCT({})
    locdict = {}

    #We first allocate all the SHMINT objects ahead of time
    #to minimize overhead from that allocation
    otherdict1 = {}
    otherdict2 = {}
    shmkeylist = [shmobj.SHMSTR(str(i)) for i in range(LENGTH)]
    lockeylist = [str(i) for i in range(LENGTH)]
    for i in range(LENGTH):
        otherdict1[shmkeylist[i]] = shmobj.SHMINT(i)
        otherdict2[lockeylist[i]] = i


    stime = time.time()
    for i in range(LENGTH):
        shmdict[shmkeylist[i]] = otherdict1[shmkeylist[i]]
    etime = time.time()
    print "shmdict create time (set):", (etime - stime)
Exemplo n.º 9
0
    if len(argv) < 2:
        print "Usage: %s [-d] [number of children (buckets)]" % argv[0]
        sys.exit(-1)

    numchildren = int(argv[-1])

    # f = open(argv[2])
    # nums = []
    # 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()
Exemplo n.º 10
0
 def testDelete(self):
     self.shmint_a.delete()
     self.shmint_b.delete()
     self.shmint_c.delete()
     self.assertEqual(shmobj.freecount(), self.start_mem)
Exemplo n.º 11
0
# explicitly call for the same reasons as stated above for an explicit delete.
# The delitem call also takes a 'shallow' parameter that acts just as the
# one in delete. By default it is not shallow, and will truly delete the item.
shared_list.delitem(0)

# For lists and dictionaries, the delete call takes an optional named
# parameter 'shallow' that will only delete the list and it's references,
# but not the actual variables. By default, the delete calls are not shallow,
# meaning every variable and sublist or subdictionary is also deleted recursively.
a, b, c = SHMINT(1), SHMINT(2), SHMINT(3)
for x in [a, b, c]: shared_list.append(x)
print 'shared_list = %s' % shared_list

# You can check the amount of memory available to you (in bytes)
# at any time using the freecount method in the shmobj module.
print 'freecount = %d' % shmobj.freecount()

# So now let's say we (deep) delete shared_list. We should then see a
# higher amount of available shared mem.
shared_list.delete()
print 'freecount after shared_list.delete() = %d' % shmobj.freecount()

# Again, we see that a different local reference pointing to a 
# deleted shared memory value will return the python None object
print 'a = %s' % a

# However, if we explicitly call delete using a reference to a variable
# and try to access it using that reference, shmobj throws an Exception.
a = SHMINT(99)
a.delete()
try: print 'a = %s' % a
Exemplo n.º 12
0
#!/usr/bin/python -i

import shmobj

shmobj.add_shmem_pages(10000)
print 'init mem', shmobj.freecount()

ll = []
ld = {}
shml = shmobj.SHMLST([])
shmd = shmobj.SHMDCT({})

for i in range(64):

    ll.append(i)
    ld[str(i)] = i

    shml.append( shmobj.SHMINT(i) )
    shmd[shmobj.SHMSTR(str(i))] = shmobj.SHMINT(i)


a = shmobj.SHMINT(20)
b = shmobj.SHMDBL(34.4)
c = shmobj.SHMDBL(18.2)
shmstr = shmobj.SHMSTR('Shared Memory!!!')
lstr = 'Local Memory!!!'

shmstr = shmobj.SHMSTR("Hello World!")
lstr = "Hello World!"

shml.append(a)
Exemplo n.º 13
0
def printCurrentMemUse():
    print ''
    print '========================='
    print "Current free mem :", shmobj.freecount()
    print '========================='
    print ''
Exemplo n.º 14
0
#!/usr/bin/python

import shmobj, os, sys, time
from shmobj import SHMLST, SHMDBL

shmobj.add_shmem_pages(32000)
print shmobj.freecount()

MAX_PROC = 20
DIM = 10

a = []
b = []
c = SHMLST([])

def mm(rank, numprocs):
    i = rank
    while i < DIM:
        for j in range(DIM):
            sum = 0.0
            for k in range(DIM):
                sum = sum + (a[i][k] * b[k][j])
            c[i][j].set(sum)
        i = i + numprocs


def checkmatrix():
    errs = 0
    for i in range(DIM):
        for j in range(DIM):
            e = 0.0