POSTS
C# Parallel.For / Python multiprocess
Parallel 可以並行處理,並無法跟 map() 畫上等號。這跟 Python 的 multiprocess 比較相似。
// c# Parallel.For example.
using System;
using System.Threading.Tasks;
public class Program {
public static void Main(string[] args) {
Parallel.For(0, 5, i=> { // 表示從 0~4,共五次。
Console.WriteLine(i.ToString());
});
}
}
# Python multiprocess example.
import multiprocessing
def foo(i):
print(i)
if __name__ == '__main__':
pool = Pool()
result = pool.map(foo, range(4))
參考資料: * Parallel Class (System.Threading.Tasks)”) * HOW TO:撰寫簡單的 Parallel.For 迴圈 * [C#]隨筆手扎 - Parallel & Lock - 非非碼不可- 點部落 * Python multiprocess