lua-users home
lua-l archive

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


Am 29.11.2012 um 23:53 schrieb David Given:

> On 29/11/12 22:25, Philipp Kraus wrote:
> [...]
>> 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 );
>> }
> 
> I assume 'state' here is referring to a simulation state, and not to a
> Lua state (lua_State*)?

Yes, sorry. "state" in this case is a state of one individual element in the time step t
I have got on each time step t more million elements and each element must run
a lua function with its individual state.


> Look for the luac utility, which you get with your Lua distribution.
> This will allow you to precompile a Lua script into a bytecode file,
> which can then be loaded as if it were an ordinary script. Loading
> bytecode typically takes half to a third of the time of loading source.

Thanks for this hint, I don't work with Lua bytecode. My Lua script is
within a database and on simulation start I would check it (syntax checking)
and than I would like to compile it.

I link my C++ executable again the Lua library, so can I compile a Lua script
that is stored in a stream / string? How can I compile the script?

> Note that bytecode files are not portable across architectures --- you
> can't use bytecode that was compiled on ARM on MIPS, for example. So you
> need to compile it on the same kind of machine as one of your cluster nodes.

I think I can compile the script on each physical node on simulation start, so 
the script has got the correct architecture.


> However, this sounds like you have multiple persistent Lua states per
> thread? You don't have to destroy the Lua state and recreate it every
> time you execute a work unit?


I try to explain it in a short example:

The use of the simulation creates some (10-20) different Lua scripts, each script
represent a kind of individual. The simulation creates some millions of individuals,
so each individual calls one Lua script. On beginning the individuals are initialize
with random data. On each time step, the simulation call the Lua script with the dataset.
Eg: Each Lua script represented a car type and I would like to create some millions of cars.

> If this is the case, then you can just load all your scripts into the
> Lua state and then run_lua_script() just runs the appropriate one for
> the work unit. That way, you only have to initialise the Lua states
> once, when the thread is spawned.

I would like to create for each of my individuals an own script, so I need for each script
one Lua state, do I? I would like to use one Lua state on one thread, so I would like
to use the Lua state with different Lua scripts. Can I do this?


Phil