#!/bin/bash
#跑了4卡的TaoBao
# 定义数组变量
seed=$1
addr="192.168.1.105"
partition_params=("ours")
partition="ours"
#"metis" "ldg" "random")
#("ours" "metis" "ldg" "random")
partitions="8"
node_per="4"
nnodes="2"
node_rank="0"
sample_type_params=("recent" "recent" "recent" "recent" "boundery_recent_decay")
probability_params=("0.1")
neg_policy=("all" "local" "local" "local" "local")
topk_list=("0" "0" "0.1" "0.1" "0.1")
memory_type=("all_update" "all_update" "all_update" "all_update" "historical")
shared_memory_ssim=("0.3")
ssim="0.3"
neighbor_num=( "10" "20")
neighbor="10"
data_param=("LASTFM" "WikiTalk" "StackOverflow" "GDELT") 
#"GDELT")
#data_param=("WIKI" "REDDIT" "LASTFM" "DGraphFin" "WikiTalk" "StackOverflow")
#data_param=("WIKI" "REDDIT" "LASTFM" "WikiTalk" "StackOverflow")
#data_param=("REDDIT" "WikiTalk")
# 创建输出目录


# 遍历数组并执行命令

#seed=(( RANDOM % 1000000 + 1 ))
mkdir -p all_"$seed"
for data in "${data_param[@]}"; do
    model="TGN_large"
    neighbor="20"
    if [ "$data" = "WIKI" ] || [ "$data" = "REDDIT" ] || [ "$data" = "LASTFM" ]; then
        model="TGN"
        neighbor="10"
    fi
    mkdir all_"$seed"/"$data"
    mkdir all_"$seed"/"$data"/"$model"
    mkdir all_"$seed"/"$data"/"$model"/comm
    for i in "${!sample_type_params[@]}"; do
        topk="${topk_list[i]}"
        sample="${sample_type_params[i]}"
        neg_type="${neg_policy[i]}"
        mem="${memory_type[i]}"

        if [ "$sample" = "recent" ]; then
            if [ "$mem" = "historical" ]; then
                for ssim in "${shared_memory_ssim[@]}"; do
                    if [ "$partition" = "ours" ] || [ "$partition" = "metis" ]; then
                        torchrun --nnodes "$nnodes" --node_rank "$node_rank" --nproc-per-node "$node_per" --master-addr "$addr" --master-port 9445 train_boundery.py --dataname "$data" --mode "$model" --partition "$partition" --topk "$topk" --sample_type "$sample" --memory_type "$mem" --shared_memory_ssim "$ssim" --seed "$seed" --neighbor "$neighbor" --local_neg_sample "$neg_type" > all_"$seed"/"$data"/"$model"/"$partitions"-"$partition"-"$topk"-"$mem"-"$ssim"-"$sample"-"$neighbor"-"$neg_type".out &
                        wait
                    fi
                done
                    
            else
                            
                if [ "$partition" = "ours" ] && [ "$mem" != "all_local" ]; then
                    torchrun --nnodes "$nnodes" --node_rank "$node_rank" --nproc-per-node "$node_per" --master-addr "$addr" --master-port 9445 train_boundery.py --dataname "$data" --mode "$model" --partition "$partition" --topk "$topk" --sample_type "$sample" --memory_type "$mem" --seed "$seed" --neighbor "$neighbor" --local_neg_sample "$neg_type" > all_"$seed"/"$data"/"$model"/"$partitions"-"$partition"-"$topk"-"$mem"-"$ssim"-"$sample"-"$neighbor"-"$neg_type".out &
                    wait
                fi
            fi
        else
            for pro in "${probability_params[@]}"; do
                if [ "$mem" = "historical" ]; then
                    for ssim in "${shared_memory_ssim[@]}"; do
                        if [ "$partition" = "ours" ] || [ "$partition" = "metis" ]; then
                            torchrun --nnodes "$nnodes" --node_rank "$node_rank" --nproc-per-node "$node_per" --master-addr "$addr" --master-port 9445 train_boundery.py --dataname "$data" --mode "$model" --partition "$partition" --topk "$topk" --sample_type "$sample" --probability "$pro" --memory_type "$mem" --shared_memory_ssim "$ssim" --seed "$seed"  --neighbor "$neighbor" --local_neg_sample "$neg_type" > all_"$seed"/"$data"/"$model"/"$partitions"-"$partition"-"$topk"-"$mem"-"$ssim"-"$sample"-"$pro"-"$neighbor"-"$neg_type".out &
                            wait
                        fi
                    done
                else
                    if [ "$partition" = "ours" ] && [ "$mem" != "all_local" ]; then
                        torchrun --nnodes "$nnodes" --node_rank "$node_rank" --nproc-per-node "$node_per" --master-addr "$addr" --master-port 9445 train_boundery.py --dataname "$data" --mode "$model" --partition "$partition" --topk "$topk" --sample_type "$sample" --probability "$pro" --memory_type "$mem" --seed "$seed" --neighbor "$neighbor" --local_neg_sample "$neg_type" > all_"$seed"/"$data"/"$model"/"$partitions"-"$partition"-"$topk"-"$mem"-"$ssim"-"$sample"-"$pro"-"$neighbor"-"$neg_type".out &
                        wait
                    fi
                fi
            done
        fi
    done
done
