lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 29.11.2012 um 22:11 schrieb David Given:

> On 29/11/12 20:57, Philipp Kraus wrote:
> [...]
>> So I think 10^12 LUA parser etc is not recommand, so I would read the LUA script first, parse it (with syntax checking) and create the stack call (lua_call).
> 
> I don't believe there's a way to duplicate a Lua state inside a single
> process. So you can't create a state, read the script, and then spawn
> multiple states to use in different threads.
> 
> However, you could create a state, read the script, and then *fork* ---
> by duplicating the entire process you also duplicate the Lua state in
> the master process.

I can not do this, because I have got a cluster with n nodes. The simulation
runs on each node and the execution is independed from the others. So I must
create a full Lua interpreter on each node (and each thread)

> I assume you're not running all 10^12 simulation steps concurrently,
> though, right? Won't you have a thread pool with a thread per core and
> then assign work to each thread as the thread is freed up?

No, all states should be independed. In a single process I would do this:

std::vector<state> l_state;
create_init_states( l_states, number_of_individuals );
for(std::size_t t=0; t < simulation_time; ++i {
	for (std::size_t i=0; i < l_state.size; ++i)
		l_state[i] = run_lua_script( l_state[i], environment, t );
}

> If so, you'd be best off creating a Lua state per thread, having the
> state read a script, and then each time you assign work to the thread
> reuse the existing state.

I would use MPI & threading, so on a MPI core I can have n threads, on each
thread I would create a Lua state. 
My call "run_lua_script" can be different of the l_state[i], so there can be 
different Lua scripts and on the state a special script is run, so if I don't order my states
I can have got on each thread p Lua states, for each script one Lua state.

Phil