Python3, multiprocessing shared memory for modules?
Go to solution
Solved by Poet129,
In case any future readers want the code used to figure this out, this is it:
def memorylocalseed(manual_seed): from time import time openfile = open("Results.txt", "a") start = time() z = manual_seed(1) end = time() - start openfile.write(str(manual_seed) + str(end) + "\n") openfile.close() def memorylocalrand(randint): from time import time openfile = open("Results.txt", "a") start = time() z = randint(9, (1, 100000000), device="cpu") z = z.tolist() z = str(z) z = z.replace("[[", "") z = z.replace("]]", "") z = z.replace(", " , "") end = time() - start openfile.write(str(randint) + str(end) + "\n") openfile.close() if __name__ == '__main__': from torch import manual_seed, randint from os import remove from multiprocessing import Process from threading import Thread from time import time start = time() openfile = open("Results.txt", "w") openfile.write("") openfile.close() memorylocalseed(manual_seed) memorylocalrand(randint) print("Local tasks Completed.") t1 = Thread(target=memorylocalseed, args=(manual_seed,), daemon=False) t2 = Thread(target=memorylocalrand, args=(randint,), daemon=False) t1.start() t1.join() t2.start() t2.join() print("Threading tasks Completed.") p1 = Process(target=memorylocalseed, args=(manual_seed,), daemon=False) p2 = Process(target=memorylocalrand, args=(randint,), daemon=False) p3 = Process(target=memorylocalseed, args=(manual_seed,), daemon=False) p4 = Process(target=memorylocalrand, args=(randint,), daemon=False) p1.start() p3.start() p1.join() p3.join() start1 = time() p2.start() p4.start() p2.join() p4.join() end1 = time() - start1 print("Processing tasks Completed.") openfile = open("Results.txt", "r") print(openfile.read()) openfile.close() remove("Results.txt") end = time() - start print("It took " + str(end1) + " seconds to run both randint processes at the same time.") print("It took " + str(end) + " seconds to complete all processes.")
This is the linux output I got:
This is the windows output I got (I used ssh):
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now