“foreach” loop : Using all cores in R (especially if we are sending sql queries inside foreach loop)

后端 未结 1 1789
有刺的猬
有刺的猬 2021-01-06 10:14

I intend to use \"foreach\" to uitlize all the cores in my CPU. The catch is i need to send a sql query inside the loop. The script is working fine with normal \'for\' loop,

相关标签:
1条回答
  • 2021-01-06 10:49

    My suggestion is this: Move the database queries outside the loop, and lock access so you dont do parallel database queries. I think that will speed things up too, as you won't have parallel disk access, while still being able to do parallel processing.

    Meaning (pseudo code) db = connect to database threadlock = lock();

    parfor { threadlock.lock result = db query (pull all data here, as you cant process while you load without keeping the database locked) thread.unlock process resulting data (which is now just data, and not a sql object). }

    0 讨论(0)
提交回复
热议问题