1

Topic: Flows in Lua, how?

There is such code: - how the fuck make it parallel in lua?! cutorch.withDevice (1, function () for i = 1, l1g do goOGroup (i) end end) cutorch.withDevice (2, function () for i = l1g+1, oGroups do goOGroup (i) end end) Now it, certainly, becomes sequentially. But it would be desirable, that both  worked simultaneously. Functions write everyone to the area of storage, therefore it is not necessary to coordinate them. I open it: https://github.com/torch/threads and I  already on an example function (idx) - This code will crash require ' nn ' - because the upvalue ' model ' local myModel = model:clone () - is of unknown type before deserialization end Why if to space apart this code on two functions all , and if to fulfill in the form of one there any  with visibility area? What for flow deserialising? It is mandatory? In With ++ such hogwash is not present. I  to the logician of this example not . I write such code: require ' torch ' require ' cutorch ' function main (a) print (a.tensor:size ()) local threads = require ' threads ' local pool = threads. Threads (2) pool:addjob (function () - local a how to transfer? print (a.tensor:size ()) end) pool:synchronize () pool:terminate () end a = {} a.tensor = torch. CudaTensor (100,100,100,100) main (a) Tred  any. The class is unknown. Global variables and the classes added by a word require, from  are not visible to function. It that for delirium? In With ++ flows of the logician here is any, global variables all are visible, it is clear why, local are not present, it is clear why, but it is possible to transfer them in a stream function, it is clear as. And here generally it is not clear as how to do.

2

Re: Flows in Lua, how?

Hello, T4r4sB, you wrote:... TB> Tred  any. The class is unknown. Global variables and the classes added by a word require, from  are not visible to function. It that for delirium? In With ++ flows of the logician here is any, global variables all are visible, it is clear why, local are not present, it is clear why, but it is possible to transfer them in a stream function, it is clear as. And here generally it is not clear as how to do. You  read? The magic of the threads package lies in the seven following points: Threads are created on demand (usually once in the program). Jobs are submitted to the threading system in the form of a callback function. The job will be executed on the first free thread. If provided, an ending callback will be executed in the main thread, when a job finishes. Job callback are fully serialized (including upvalues!) which allows transparent copy of data to any thread. Values returned by a job callback will be passed to the ending callback (serialized transparently). As ending callbacks stay on the main thread, they can directly "play" with upvalues of the main thread. Synchronization between threads is easy. https://github.com/torch/torch7/wiki/Cheatsheet https://www.cs.ox.ac.uk/people/nando.de … elearning/

3

Re: Flows in Lua, how?

Hello, kov_serg, you wrote: _> Hello, T4r4sB, you wrote: _>... TB>> Tred  any. The class is unknown. Global variables and the classes added by a word require, from  are not visible to function. It that for delirium? In With ++ flows of the logician here is any, global variables all are visible, it is clear why, local are not present, it is clear why, but it is possible to transfer them in a stream function, it is clear as. And here generally it is not clear as how to do. _> you  read? Yes, but I  did not understand, how  to transfer, and on which horse-radish  a flow?

4

Re: Flows in Lua, how?

Hello, T4r4sB, you wrote: TB> Hello, kov_serg, you wrote: _>> Hello, T4r4sB, you wrote: _>>... TB>>> Tred  any. The class is unknown. Global variables and the classes added by a word require, from  are not visible to function. It that for delirium? In With ++ flows of the logician here is any, global variables all are visible, it is clear why, local are not present, it is clear why, but it is possible to transfer them in a stream function, it is clear as. And here generally it is not clear as how to do. _>> you  read? TB> yes, but I  did not understand, how  to transfer, and on which horse-radish  a flow? At first we look on upvalues function dump (x) for k, v in pairs (x) do print (k. ' = '. v) end end function get_fn (x, y) local a, b=10,20 g1=x - not upvalue local l1=y local fn=function () print (' a = '. a, ' b = '. b, ' l1 = '. l1, ' g1 = '. . g1) end return fn end function get_upvalues (fn) local i, res=1, {} while true do local name, value=debug.getupvalue (fn, i) if not name then break end if name ~ = ' _ENV ' then res [name] =value end i=i+1 end return res end fn=get_fn (1,2) dump (get_upvalues (fn)) - print upvalues fn () a=10 b=20 l1=2 a=10 b=20 l1=2 g1=1 Then on introduction "... callback are fully serialized (including upvalues!)..." function main (a) print (a.tensor:size() local threads = require ' threads ' local pool = threads. Threads (2) local aa=a - it is added upvalue pool:addjob (function () - - local a how to transfer upvalue print (aa.tensor:size ()) -  end) It is conceived somehow so the Example https://github.com/soumith/dcgan.torch/ … ua#L30-L43

5

Re: Flows in Lua, how?

Hello, T4r4sB, you wrote: TB> Yes, but I  did not understand, how  to transfer, How closed value probably (not in an implementation subject) TB> and on which horse-radish  a flow? And here it is just simple. LuaVM it is not calculated for multi-threaded execution in itself (no, for example, global object of synchronization as in Python, effectively braking parallel performance). But also there are no restrictions on an amount of these VM. They can really work parallely, without hindering each other. Probably flows are organized as a pool of virtual machines to which it is transferred  the job ( - the code too it is possible ). If expenditures on code serialization are considerable - make the pool VM with beforehand loaded code (this can  so already is able, ) and the exterior manager. Drive only the data (them it is possible  inside VM) and jobs for handling.