forked from microsoft/Multiverso
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
67 lines (56 loc) · 1.56 KB
/
init.lua
File metadata and controls
67 lines (56 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'torch'
local ffi = require 'ffi'
local util = require 'multiverso.util'
local mv = {}
ffi.cdef[[
typedef void* TableHandler;
void MV_Init(int* argc, char* argv[]);
void MV_ShutDown();
void MV_Barrier();
int MV_NumWorkers();
int MV_WorkerId();
int MV_ServerId();
]]
package.cpath = '/usr/local/lib/?.so;' .. package.cpath
libmv_path = package.searchpath('libmultiverso', package.cpath, '')
if libmv_path == nil then
print([[
[Error] Multiverso shared object, `libmultiverso.so`, NOT FOUND!
Please build & install `multiverso` according to the instruction [1].
[1] https://github.com/Microsoft/multiverso#build]])
return
end
libmv = ffi.load(libmv_path, 'true')
mv.ArrayTableHandler = require('multiverso.ArrayTableHandler')
mv.MatrixTableHandler = require('multiverso.MatrixTableHandler')
function mv.init(sync)
sync = sync or false -- false for the default value of sync
-- the first argument will be ignored. So we put a placeholder here
args = {""}
if sync then
table.insert(args, "-sync=true")
end
argc = ffi.new("int[1]", #args)
argv = ffi.new("char*[?]", #args)
for i = 1, #args do
argv[i - 1] = ffi.new("char[1]")
ffi.copy(argv[i - 1], args[i])
end
libmv.MV_Init(argc, argv)
end
function mv.barrier()
libmv.MV_Barrier()
end
function mv.shutdown()
libmv.MV_ShutDown()
end
function mv.num_workers()
return libmv.MV_NumWorkers()
end
function mv.worker_id()
return libmv.MV_WorkerId()
end
function mv.server_id()
return libmv.MV_ServerId()
end
return mv