print 'Success' if __name__=='__main__': if (len(sys.argv) != 3): print 'Usage: %s n dim\n where n is the number of threads and dim is the dimension of the matrix' % sys.argv[0] sys.exit(1) n = int(sys.argv[1]) DIM = int(sys.argv[2]) for i in range(DIM): a.append([]) b.append([]) c.append(SHMLST([])) for j in range(DIM): a[i].append(i+j) b[i].append(i+j) c[i].append(SHMDBL(0)) stime = time.time() for i in range(n): rc = os.fork() if rc == 0: #print 'mm(%s,%s)' % (i, n) mm(i,n) sys.exit(0) for i in range(n):
# 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, # 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
errs += 1 if errs == 0: print 'Success' if __name__=='__main__': if (len(sys.argv) != 3): print 'Usage: %s n dim\n where n is the number of threads and dim is the dimension of the matrix' % sys.argv[0] sys.exit(1) n = int(sys.argv[1]) DIM = int(sys.argv[2]) for i in range(DIM): a.append(SHMLST([])) b.append(SHMLST([])) c.append(SHMLST([])) for j in range(DIM): a[i].append(SHMDBL(i+j)) b[i].append(SHMDBL(i+j)) c[i].append(SHMDBL(0)) stime = time.time() for i in range(n): rc = os.fork() if rc == 0: #print 'mm(%s,%s)' % (i, n) mm(i,n) sys.exit(0)