// Msg Includes
#include <stdio.h>
-#include "msg/msg.h"
+#include "msg/msg.h"
+#include "msg/datatypes.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
#include "xbt/asserts.h"
=============================================
*/
+XBT_LOG_NEW_DEFAULT_CATEGORY(lua,"Lua bindings");
-
-#define TASK "Task"
-#define HOST "Host"
-#define PROCESS "Process"
+#define TASK "Msg.Task"
+#define HOST "Msg.Host"
+#define PROCESS "Msg.Process"
typedef m_task_t Task;
typedef m_host_t Host;
typedef m_process_t Process;
+
+static void stackDump (lua_State *L) {
+ int i;
+ int top = lua_gettop(L);
+ void *p;
+ fflush(stdout);
+ return;
+ INFO0("That's me");
+ printf("STACK(top=%d): ",top);
+ for (i = 1; i <= top; i++) { /* repeat for each level */
+ int t = lua_type(L, i);
+ switch (t) {
+
+ case LUA_TSTRING: /* strings */
+ printf("`%s'", lua_tostring(L, i));
+ break;
+
+ case LUA_TBOOLEAN: /* booleans */
+ printf(lua_toboolean(L, i) ? "true" : "false");
+ break;
+
+ case LUA_TNUMBER: /* numbers */
+ printf("%g", lua_tonumber(L, i));
+ break;
+
+ default: /* other values */
+ if ((p = luaL_checkudata(L,i,TASK))) {
+ printf("task");
+ } else {
+ printf("%s", lua_typename(L, t));
+ }
+ break;
+
+ }
+ printf(" "); /* put a separator */
+ }
+ printf("\n"); /* end the listing */
+ fflush(stdout);
+}
+
//**********************************************************TASK SECTION***************************************************
static int Task_new(lua_State* L)
{
- char *name=luaL_checkstring(L,1);
+ const char *name=luaL_checkstring(L,1);
int comp_size = luaL_checkint(L,2);
int msg_size = luaL_checkint(L,3);
// We Will Set The Data as a Null for The Moment
static int Host_new(lua_State* L)
{
- char *host_name=luaL_checkstring(L,1);
+ const char *host_name=luaL_checkstring(L,1);
pushHost(L,MSG_get_host_by_name(host_name));
return 1;
}
static int Process_new(lua_State* L)
{
- char *name=luaL_checkstring(L,1);
+ const char *name=luaL_checkstring(L,1);
//int code = luaL_checkint(L,2);
//xbt_main_func_t << code
// We Will Set The Data as a Null for The Moment
/**
* Function to Send a Task
*/
-static void Task_send(lua_State *L) {
+static int Task_send(lua_State *L) {
Task tk = checkTask(L,1);
- char *mailbox = luaL_checkstring(L,2);
-
+ const char *mailbox = luaL_checkstring(L,2);
+ stackDump(L);
int res = MSG_task_send(tk,mailbox);
+ stackDump(L);
+ return 0;
}
/**
-* Function to Get ( Recieve !! ) a Task
+* Function Recieve a Task
*/
-static int Task_recv(lua_State *L) {
- m_task_t tk = NULL;
+static int Task_recv2(lua_State *L) {
- char *mailbox = luaL_checkstring(L,1);
+ Task *tk = (Task *)checkTask(L,1);
+ const char *mailbox = luaL_checkstring(L,2);
+ MSG_task_receive(tk,mailbox);
+ printf("Task Name Within Receive Fct: >>>%s\n",MSG_task_get_name(*tk));
+
+ return 0;
+}
+
+
+static int Task_recv(lua_State *L) {
+ Task tk = NULL;
+ //stackDump(L);
+ const char *mailbox = luaL_checkstring(L,1);
int res = MSG_task_receive(&tk,mailbox);
+ INFO1("Task Name : >>>%s",MSG_task_get_name(tk));
pushTask(L,tk);
+// stackDump(L);
return 1;
}
-
//******************************************************* PLATFORM & APPLICATION SECTION ****************************************************************
{"destroy", Task_destroy},
{"send", Task_send},
{"recv", Task_recv},
+{"recv2", Task_recv2},
{0,0}
};
static int Task_gc(lua_State *L)
{
Task tk=toTask(L,1);
- if (tk) MSG_task_destroy(tk);
- printf("GoodBye Task(%p)\n",lua_touserdata(L,1));
+ //if (tk) MSG_task_destroy(tk);
+ //printf("GoodBye Task(%p)\n",lua_touserdata(L,1));
return 0;
}
--- /dev/null
+set -e
+make -C ../../
+gcc -g3 -o runner tasktest.c Msglua.c -I ../../../include/ -I /usr/include/lua5.1/ -I . -L../../.libs -ldl -llua5.1 -lsimgrid
+valgrind -q ./runner ../../../examples/msg/small_platform.xml deploy.xml tasklua.lua
-function getn(t)
- if type(t.n) == "number" then return t.n end
- local max=0
- for i,_ in to do
- if type(i) == "number" and i>max then max=i end
- end
- t.n = max
- return max
-end
--Master Function
function master(...)
for i,v in ipairs(arg) do
print("Got "..v)
end
-t_tasks={} --tasks table
-t_slaves={} --slaves table
nb_task = arg[1];
comp_size = arg[2];
comm_size = arg[3];
-
--- Let's Create the tasks to dispatch
-for i=1,nb_task do
- t_tasks[i] = Task.new("Task "..i,comp_size,comm_size); --data set to NULL
-end
+slave_count = arg[4]
--- Process Organisation
+argc=#arg
+print("Argc="..argc.." (should be 4)")
-argc=getn(arg)
-print("Argc="..argc.." (should be 8)")
+-- Dispatch the tasks
-slave_count = getn(arg) -3;
-
-for i=4,argc do
-slv_name = arg[i];
-t_slaves[i - 3] = Host.new(slv_name);
--- do not do directly that : t_slaves[i - 4] = Host.new(argv[i]);
+for i=1,nb_task do
+ tk = Msg.Task.new("Task "..i,comp_size,comm_size);
+ alias = "slave "..(i%slave_count);
+ print("Master sending '" .. Msg.Task.name(tk) .."' To '" .. alias .."'");
+ Msg.Task.send(tk,alias); -- C user data set to NULL
+ print("Master done sending '".. Msg.Task.name(tk) .."' To '" .. alias .."'");
end
-
-
-
--- Print List Of Tasks / Slaves
--[[
-for i=1,nb_task do
-todo = Task.name(t_tasks[i]);
-print(i % slave_count+1);
-slv = Host.name(t_slaves[i % slave_count+1]);
-print ( "Sending : " .. todo .. " To : " .. slv);
-end
-]]--
-
-
+Sending Finalize Message To Others
+--]]
-for i=1,nb_task do
-tk_name = Task.name(t_tasks[i]);
-ht_name = Host.name(t_slaves[i]);
-print("Sending " .. tk_name .." To " .. ht_name);
-Task.send(t_task[i],"slave "..(i%slave_count));
-print("Sent");
+print("Master: All tasks have been dispatched. Let's tell everybody the computation is over.");
+for i=0,slave_count-1 do
+ alias = "slave "..i;
+ print("Master: sending finalize to "..alias);
+ Msg.Task.send(Msg.Task.new("finalize",0,0),alias);
end
+print("Master: Everything's done.");
+
end
my_mailbox="slave "..arg[1]
print("Hello from lua, I'm a poor slave with mbox: "..my_mailbox)
+
while true do
- tk = Task.recv(my_mailbox);
- print("Got something");
- --testing res !!!!
- tk_name = Task.name(tk)
+-- tk = Msg.Task.new("",0,0); --??
+-- Msg.Task.recv2(tk,my_mailbox);
+ tk = Msg.Task.recv(my_mailbox);
+
+ tk_name = Msg.Task.name(tk)
if (tk_name == "finalize") then
- Task.destroy(tk);
- end
+ print("Slave '" ..my_mailbox.."' got finalize msg");
+ break
+ end
- print("Processing "..Task.name(tk))
- Task.execute(tk);
+ print("Slave '" ..my_mailbox.."' processing "..Msg.Task.name(tk))
+ Msg.Task.execute(tk);
- print(Task.name(tk) .. "Done")
- Task.destroy(tk);
+ print("Slave '" ..my_mailbox.."': task "..Msg.Task.name(tk) .. " done")
end -- while
-print("I'm Done . See You !!");
+print("Slave '" ..my_mailbox.."': I'm Done . See You !!");
end -- function ----------------------------------------------------------
--]]
-#include "Msglua.h"
+#include <stdio.h>
+#include "lauxlib.h"
+#include "lualib.h"
+
+// Msg Includes
+#include <stdio.h>
+#include "msg/msg.h"
+#include "msg/datatypes.h"
+#include "xbt/sysdep.h"
+#include "xbt/log.h"
+#include "xbt/asserts.h"
int master_lua(int argc, char *argv[]);
int slave_lua(int argc, char *argv[]);
-int load_lua(char * file);
+//int load_lua(char * file);
//int forwarder(int argc, char *argv[]); LUA
MSG_error_t test_all(const char *platform_file, const char *application_file);
} channel_t;
-lua_State *L;
-
+char *lua_file;
//***************************** LOAD LUA *************************************************
-int load_lua(char * luaFile) {
- L = lua_open();
-
+static int load_lua(char * luaFile, lua_State *L) {
luaL_openlibs(L);
// Lua Stuff
}
int lua_wrapper(int argc, char *argv[]) {
- // Table that Lua will read to read Arguments
- lua_newtable(L);
+ lua_State *L = lua_open();
+ load_lua(lua_file, L);
// Seek the right lua function
lua_getglobal(L,argv[0]);
// User process terminated
lua_pop(L, 1);
+ lua_close(L);
return 0;
}
}
- load_lua(argv[3]);
+ lua_file=argv[3];
+// load_lua(argv[3]);
/* MSG_config("surf_workstation_model","KCCFLN05"); */
MSG_create_environment(argv[1]);
MSG_function_register_default(&lua_wrapper);
MSG_launch_application(argv[2]);
- MSG_set_channel_number(10);
res = MSG_main();
+ fflush(stdout);
INFO1("Simulation time %g", MSG_get_clock());
MSG_clean();
- lua_close(L);
if (res == MSG_OK)
return 0;