Exemple #1
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
Exemple #2
0
# by the garbage collector, because some other process may have references to it.

# Instead, we are explicitly in charge of deleting shared memory variables
# by using delete calls.
shared_int = SHMINT(10)
shared_int.delete()

# So we must define different semantics for local references pointing to 
# deleted shared memory variables, since when we delete shared_int, the variable
# is truly gone. In this case, a reference (stored in shared memory) stored
# in a list (also in shared memory) still exists, but now returns the Python
# None object.

# So the following print statement should show shared_list = [None]
shared_int = SHMINT(10)
shared_list = SHMLST([shared_int])
shared_int.delete()
print 'shared_list = %s' % shared_list

# Note that this also means that shared_list still has a length of 1.
print 'len(shared_list) = %d' % len(shared_list)

# We must still delete the reference from the list to free the shared
# memory used for it. We do this with the delitem call, which we must
# 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,
Exemple #3
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 = SHMLST([])
b = SHMLST([])
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