An easy example on Parallel Computing

import multiprocessing as mp
from time import sleep as s

print(mp.cpu_count())

def p1(queue, arg1):
    print(f"Process 1 Starts with {arg1}.")
    s(10)
    print('Wait 5 sec. for P1.')
    s(5)
    print('Process 1 ends.')
    queue.put(f"Result from p1 with {arg1}")

def p2(queue, arg2):
    print(f'Process 2 runs with {arg2}.')
    s(4)
    print('In the middle of process 2.')
    for i in range(10):
        s(1.5)
        print(i)
    print("P2 is terminated.")
    queue.put(f"Result from p2 with {arg2}")

if __name__ == "__main__":
    queue = mp.Queue()
    p1_process, p2_process = mp.Process(target=p1, args=(queue, "argument1")), mp.Process(target=p2, args=(queue, "argument2"))
    p1_process.start(), p2_process.start()
    p1_process.join(), p2_process.join()
    result1 = queue.get()
    result2 = queue.get()
    print(result1)
    print(result2)

More experiments can be carried out to explore what the factors are that impact execution time.

1. memory

2. data type

3. variable names (length, the complexity of identifying it)

4. the order to execute

tf.config.list_logical_devices(), tf.config.list_physical_devices()
with tf.device('gpu:0'):
    tf.print(1)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值