forked from pepsi2222/GREB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctrwlm_all.sh
71 lines (55 loc) · 1.28 KB
/
ctrwlm_all.sh
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
categories=(
"Arts_Crafts_and_Sewing"
"Automotive"
"Baby_Products"
"Cell_Phones_and_Accessories"
"Industrial_and_Scientific"
"Musical_Instruments"
"Office_Products"
"Patio_Lawn_and_Garden"
"Sports_and_Outdoors"
"Tools_and_Home_Improvement"
"OnlineRetail"
"Beauty_and_Personal_Care"
"Goodreads"
"Books"
"Toys_and_Games"
"Video_Games"
"Bili_Cartoon"
"Bili_Dance"
"Bili_Food"
"Bili_Movie"
"Bili_Music"
"DY"
"KU"
"QB"
"TN"
"Yelp"
"Maine_Food"
)
num_processes=8
python_script="script/run_ctr_with_text.py"
cudas="0,1,2,3,1,0,3,2"
cuda_array=(${cudas//,/ })
run_parallel() {
cuda_id="$1"
c="$2"
# echo $cuda_id $c && sleep 10s &
CUDA_VISIBLE_DEVICES=$cuda_id python $python_script $c &
}
index=0
for c in "${categories[@]}"; do
# 限制并行进程的数量
while [ $(jobs | wc -l) -ge $num_processes ]; do
wait -n
done
# 确保index不会超过cuda_array的长度
if ((index + 1 >= ${#cuda_array[@]})); then
index=0
fi
# 拿两个CUDA ID
cuda_ids="${cuda_array[index]},${cuda_array[index+1]}"
run_parallel "$cuda_ids" "$c"
# 每次增加2以确保每个任务都获取一对新的CUDA ID
((index += 2))
done