-
Notifications
You must be signed in to change notification settings - Fork 0
/
workerstartup.r
140 lines (111 loc) · 3.64 KB
/
workerstartup.r
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# worker startup
print('#####-##### workerstartup start #####-#####')
print(date())
#process
args<-commandArgs(trailingOnly=TRUE)
redishost<-args[1]
pwd<-args[2]
nodespertask<-as.numeric(args[3])
procspernode<-as.numeric(args[4])
rpdir<-args[5]
redisdir<-args[6]
ownmpipre<-as.numeric(args[7])
if(ownmpipre==1){
ownmpi<-TRUE
} else {
ownmpi<-FALSE
}
print(args)
#check whether previous steps of startup succeded
homed<-Sys.getenv('HOME')
#source(paste(homed,'.redis/redisexec/internal.r',sep=''))
failfile<-paste(redisdir,'/fail.RData',sep='')
if(file.exists(failfile)){
load(failfile)
} else {
FAILURE<-FALSE }
failureenv<-as.numeric(Sys.getenv('FAILURE'))
if(FAILURE==TRUE | failureenv==1)
stop("Startup failed")
print(paste('FAILURE pre:',FAILURE,':',failureenv))
###get hostname (= host of redis-server)
if(redishost=='localhost'){
lrzsegment<-Sys.getenv('LRZ_SYSTEM_SEGMENT')
if(lrzsegment=='Medium_Node'){
redishost<-paste(Sys.info()[4],'ib',sep='')
} else {
redishost<-paste(Sys.info()[4],'-ib',sep='')
}
} else {
stop("Using a host other than 'localhost' for the redis-server is currently not implemented.")
}
#print(redishost)
###read job hosts
homed<-Sys.getenv('HOME')
hostcon <- file(paste(redisdir,"/hostfile",sep=''), "r", blocking = FALSE)
hosts<- readLines(hostcon)
hostsU<-unique(hosts)
#print(hostsU)
if(nodespertask==1 & ownmpi==FALSE){
#start one worker on each node
loopcounter<-1
for(i in 1:length(hostsU)){
system(paste("llspawn.stdio ",hostsU[loopcounter]," 'export MYIND=",i,";echo $MYIND;. $HOME/.redis/redisexec/worker.sh ",redishost," ",pwd," ",rpdir," ",redisdir,"' >> ",redisdir,"/logs/spawn.log 2>&1",sep=""),wait=F)
loopcounter<-loopcounter+1
}
#hostsU2<-setdiff(hostsU,redishost)
nodek<-1
while(nodek<=length(hostsU)){
hostf<-file(paste(redisdir,'/subhostfiles/hostf',nodek,sep=''),'w')
lines<-c()
for(jj in 1:procspernode)
lines<-c(lines,hostsU[nodek])
writeLines(lines,con=hostf)
close(hostf)
nodek<-nodek+1
}
} else if(ownmpi==TRUE){
if(nodespertask<=0)
stop('Invalid value for NODESPERTASK (<=0)')
nodek<-1
loopcounter<-1
while(nodek<length(hostsU)){
hostf<-file(paste(redisdir,'/subhostfiles/hostf',loopcounter,sep=''),'w')
lines<-c()
for(ii in nodek:(nodek+nodespertask-1))
for(jj in 1:procspernode)
lines<-c(lines,hostsU[ii])
writeLines(lines,con=hostf)
close(hostf)
system(paste("llspawn.stdio ",hostsU[nodek]," 'export MYIND=",loopcounter,";echo $MYIND;. $HOME/.redis/redisexec/worker.sh ",redishost," ",pwd," ",rpdir," ",redisdir,"' >> ",redisdir,"/logs/spawn.log 2>&1",sep=""),wait=F)
nodek<-nodek+nodespertask
loopcounter<-loopcounter+1
}
} else {
if((length(hostsU)-1)%%nodespertask!=0)
stop('After removal of masternode, the number of requested nodes is not divisible by NODESPERTASK.')
if(nodespertask<=0)
stop('Invalid value for NODESPERTASK (<=0)')
print(redishost)
print(hostsU)
hostsU2<-setdiff(hostsU,redishost)
print(hostsU2)
nodek<-1
loopcounter<-1
while(nodek<length(hostsU2)){
hostf<-file(paste(redisdir,'/subhostfiles/hostf',loopcounter,sep=''),'w')
lines<-c()
for(ii in nodek:(nodek+nodespertask-1))
for(jj in 1:procspernode)
lines<-c(lines,hostsU2[ii])
writeLines(lines,con=hostf)
close(hostf)
system(paste("llspawn.stdio ",hostsU2[nodek]," 'export MYIND=",loopcounter,";echo $MYIND;. $HOME/.redis/redisexec/worker.sh ",redishost," ",pwd," ",rpdir," ",redisdir,"' >> ",redisdir,"/logs/spawn.log 2>&1",sep=""),wait=F)
nodek<-nodek+nodespertask
loopcounter<-loopcounter+1
}
}
FAILURE<-FALSE
save(FAILURE,file=paste(redisdir,'/fail.RData',sep=''))
print('#####-##### workerstartup end #####-#####')
print(date())