+++ /dev/null
-function Sender(...)
-
- simgrid.info("Hello From Sender")
- receiver = simgrid.host.get_by_name(arg[1])
- task_comp = arg[2]
- task_comm = arg[3]
- rec_alias = arg[4]
-
- size = 4
- m1 = mkmatrix(size, size)
- m2 = mkmatrix(size, size)
-
- if (#arg ~= 4) then
- error("Argc should be 4");
- end
- simgrid.info("Argc="..(#arg).." (should be 4)")
-
- -- Sending Task
- task = simgrid.task.new("matrix_task",task_comp,task_comm);
- task['matrix_1'] = m1;
- task['matrix_2'] = m2;
- task['size'] = size;
- simgrid.info("Sending "..simgrid.task.name(task).." to "..simgrid.host.name(receiver));
- simgrid.task.send(task,rec_alias);
- -- Read The Result
- mm = task['matrix_res']
- simgrid.info("Got the Multiplication result ...Bye");
- --mprint(size,size,mm);
-
-end
-------------------------------------------------------
-function Receiver(...)
-
- simgrid.info("Hello From Receiver")
- sender = simgrid.host.get_by_name(arg[1])
- send_alias = arg[2]
- recv_alias = "Receiver";
- simgrid.info("Receiving Task from "..simgrid.host.name(sender));
- task = simgrid.task.recv(recv_alias);
- mm = mmult(task['size'],task['size'],task['matrix_1'],task['matrix_2']);
- --mprint(task['size'],task['size'],mm)
- task['matrix_res'] = mm;
- simgrid.info("Calcul is done ... Bye");
-
-
-end
------------------------------------------------------
-
-local n = tonumber((arg and arg[1]) or 1)
-
-
-
-function mkmatrix(rows, cols)
- local count = 1
- local mx = {}
- for i=0,(rows - 1) do
- local row = {}
- for j=0,(cols - 1) do
- row[j] = count
- count = count + 1
- end
- mx[i] = row
- end
- return(mx)
-end
-
-function mmult(rows, cols, m1, m2)
- local m3 = {}
- for i=0,(rows-1) do
- m3[i] = {}
- for j=0,(cols-1) do
- local rowj = 0
- for k=0,(cols-1) do
- rowj = rowj + m1[i][k] * m2[k][j]
- end
- m3[i][j] = rowj
- end
- end
- return(m3)
-end
-
-function mprint(rows,cols,m)
- for i=0,(cols-1)do
- for j=0,(rows-1)do
- print (m[i][j])
- end
- end
-end
-
-
---end
-require "simgrid"
-simgrid.platform("quicksort_platform.xml")
-simgrid.application("quicksort_deployment.xml")
-simgrid.run()
-simgrid.info("Simulation's over.See you.")
-simgrid.clean()
-
-
* \param L a Lua state
* \return number of values returned to Lua
*/
-static int clean(lua_State * L)
+static int simgrid_gc(lua_State * L)
{
MSG_clean();
return 0;
{"debug", debug},
{"info", info},
{"run", run},
- {"clean", clean},
/* short names */
{"platform", create_environment},
{"application", launch_application},
*
* \param L a lua state
*/
-static void register_task_functions(lua_State* L) {
-
+static void register_task_functions(lua_State* L)
+{
/* create a table simgrid.task and fill it with task functions */
luaL_openlib(L, TASK_MODULE_NAME, task_functions, 0);
/* simgrid.task */
*
* \param L a lua state
*/
-static void register_host_functions(lua_State* L) {
-
+static void register_host_functions(lua_State* L)
+{
/* create a table simgrid.host and fill it with host functions */
luaL_openlib(L, HOST_MODULE_NAME, host_functions, 0);
/* simgrid.host */
* \brief Registers the platform functions into the table simgrid.platf.
* \param L a lua state
*/
-static void register_platf_functions(lua_State* L) {
-
+static void register_platf_functions(lua_State* L)
+{
luaL_openlib(L, PLATF_MODULE_NAME, platf_functions, 0);
/* simgrid.platf */
lua_pop(L, 1);
}
/**
- * \brief Makes the Simgrid functions available to the Lua world.
+ * \brief Makes the core functions available to the Lua world.
* \param L a Lua world
*/
-static void register_c_functions(lua_State *L) {
-
+static void register_core_functions(lua_State *L)
+{
/* register the core C functions to lua */
luaL_register(L, "simgrid", simgrid_functions);
/* simgrid */
+
+ /* set a finalizer that cleans simgrid, by adding to the simgrid module a
+ * dummy userdata whose __gc metamethod calls MSG_clean() */
+ lua_newuserdata(L, sizeof(void*));
+ /* simgrid udata */
+ lua_newtable(L);
+ /* simgrid udata mt */
+ lua_pushcfunction(L, simgrid_gc);
+ /* simgrid udata mt simgrid_gc */
+ lua_setfield(L, -2, "__gc");
+ /* simgrid udata mt */
+ lua_setmetatable(L, -2);
+ /* simgrid udata */
+ lua_setfield(L, -2, "__simgrid_loaded");
+ /* simgrid */
lua_pop(L, 1);
/* -- */
+}
+
+/**
+ * \brief Creates the simgrid module and make it available to Lua.
+ * \param L a Lua world
+ */
+static void register_c_functions(lua_State *L)
+{
+ register_core_functions(L);
register_task_functions(L);
register_host_functions(L);
register_platf_functions(L);