Created
April 25, 2024 10:17
-
-
Save annms2021/76a7299574073c1ee6b131832fd898f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkTools | |
using HDF5 | |
function Kudo_prob_ver06Apr2024(pos_list :: Vector{Vector{Int16}}) :: Vector{Vector{Int16}} | |
temp_list :: Vector{Int64} = [] | |
temp_pos_list :: Vector{Vector{Int16}} = [] | |
for i_list in pos_list | |
for i in 2:length(pos_list[1])-1 | |
temp_list = convert(Vector{Int64},deleteat!(copy(i_list),i)) | |
if sum([j^3 for j in temp_list]) % sum(temp_list) == 0 | |
push!(temp_pos_list,temp_list) | |
end | |
end | |
end | |
return temp_pos_list | |
end | |
function main_Kudo_prob_ver06Apr2024(n :: Int64,mmin :: Int64,mmax :: Int64, n_threads:: Int64, pos_list :: Vector{Vector{Int16}}) | |
println("n_threads: ",n_threads) | |
println("") | |
list_length_pos_list = [] | |
m_count = 0 | |
for m in mmin:mmax | |
m_count += 1 | |
length_pos_list = length(pos_list) | |
if length_pos_list > 100 | |
pos_list_next :: Vector{Vector{Vector{Int16}}} = [[] for i in 1:n_threads] | |
pos_list_each :: Vector{Vector{Vector{Int16}}} = [[] for i in 1:n_threads] | |
n_pos_list_each_init :: Vector{Int64} = [0 for i in 1:n_threads] | |
n_pos_list_each_finl :: Vector{Int64} = [0 for i in 1:n_threads] | |
length_pos_list_each = div(length_pos_list,n_threads) | |
for i in 1:n_threads | |
n_pos_list_each_init[i] = (i-1)*(length_pos_list_each+1)+1 | |
n_pos_list_each_finl[i] = i*(length_pos_list_each+1) | |
end | |
n_pos_list_each_finl[n_threads] = length_pos_list | |
Threads.@threads for i in 1:n_threads | |
pos_list_next[i] = Kudo_prob_ver06Apr2024(pos_list[n_pos_list_each_init[i]:n_pos_list_each_finl[i]]) | |
end | |
pos_list = [pos_list_next[i][j] for i in 1:length(pos_list_next) for j in 1:length(pos_list_next[i])] | |
else | |
pos_list = Kudo_prob_ver06Apr2024(pos_list) | |
end | |
pos_list = unique(pos_list) | |
length_pos_list :: Int64 = length(pos_list) | |
push!(list_length_pos_list,[m,length_pos_list]) | |
println("m: ",m," no: ",length_pos_list) | |
if length_pos_list == 0 | |
break | |
end # if | |
end # for | |
println("") | |
println("Last m: ",m_count+mmin-1) | |
return m_count+mmin-1, pos_list, list_length_pos_list | |
end # function | |
function print_params(n_threads,n,mmin_file,mmax_file,mmax) | |
println("") | |
println("##### parameters #####") | |
println("n_threads =",n_threads) | |
println("") | |
println("n = ",n) | |
println("") | |
println("mmin_file = ",mmin_file) | |
println("mmax_file = ",mmax_file) | |
println("") | |
println("mmin = ",mmin) | |
println("mmax = ",mmax) | |
println("######################") | |
println("") | |
println("- start: n= ",n) | |
println("") | |
end | |
function StandardInput() | |
println("Input n_threads:") | |
n_threads = parse(Int,readline()) | |
println("Input n:") | |
n = parse(Int,readline()) | |
println("Input mmin_file and mmax_file of the file to be read:") | |
println("(if no data file, input mmin_file =1, mmaxi_file = 1)") | |
mmin_file, mmax_file = parse.(Int,split(readline())) | |
println("Input mmax:") | |
mmax = parse(Int,readline()) | |
return n_threads,n,mmin_file,mmax_file,mmax | |
end | |
function ArgInput() | |
if length(ARGS) != 5 | |
println("input 5 args!:") | |
println("n_threads, n, mmin_file, mmax_file, mmax") | |
println("exit") | |
exit() | |
else | |
n_threads = parse(Int,ARGS[1]) | |
n = parse(Int,ARGS[2]) | |
mmin_file = parse(Int,ARGS[3]) | |
mmax_file = parse(Int,ARGS[4]) | |
mmax = parse(Int,ARGS[5]) | |
end | |
return n_threads,n,mmin_file,mmax_file,mmax | |
end | |
function DirectInput() | |
##### parameters ##### | |
n_threads = 4 | |
n = 1082 | |
mmin_file = 1 | |
mmax_file = 100 | |
mmax = 200 | |
##### | |
return n_threads,n,mmin_file,mmax_file,mmax | |
end | |
##################### Main ####################### | |
#runtime = @elapsed begin | |
##### choose one of them: | |
#n_threads,n,mmin_file,mmax_file,mmax = DirectInput() | |
n_threads,n,mmin_file,mmax_file,mmax = ArgInput() | |
#n_threads,n,mmin_file,mmax_file,mmax = StandardInput() | |
path_file = "(file_path)" ## change ## | |
################################################## | |
mmin = mmax_file | |
print_params(n_threads,n,mmin_file,mmax_file,mmax) | |
if mmin == 1 | |
println("No input file.") | |
pos_list :: Vector{Vector{Int16}}= [[i for i in 1:n]] | |
m = mmin | |
m_orig = 0 | |
else | |
global filenm_read = string(path_file,"KudoProb_n-",n,"_mmin-",mmin_file,"_mmax-",mmax_file,".dat") | |
println("file to be read: ",filenm_read) | |
file = h5open(filenm_read,"r") | |
m_orig = read(file,"m_final") | |
pos_list_read = read(file,"pos_list") | |
close(file) | |
m = m_orig + 1 | |
pos_list = convert(Vector{Vector{Int16}},[[pos_list_read[j,i] for j in 1:size(pos_list_read)[1]] for i in 1:size(pos_list_read)[2]]) | |
end | |
println("m_orig: ",m_orig) | |
println("length(pos_list): ",length(pos_list)) | |
##### MAIN ##### | |
m, pos_list, list_length_pos_list = @time main_Kudo_prob_ver06Apr2024(n,m,mmax,n_threads,pos_list) | |
################ | |
if length(pos_list) != 0 | |
# "vector" is treated as VERTICAL (column) vector: | |
##### convert is added ##### | |
pos_list_write :: Matrix{Int16} = convert(Matrix{Int16},[pos_list[i][j] for j in 1:length(pos_list[1]), i in 1:length(pos_list)]) | |
list_length_pos_list_write = [list_length_pos_list[i][j] for j in 1:length(list_length_pos_list[1]), i in 1:length(list_length_pos_list)] | |
println("size(pos_list_write): ",size(pos_list_write)) | |
filenm = string(path_file,"KudoProb_n-",n,"_mmin-",mmin,"_mmax-",mmax,".dat") | |
# filenm = "julia -t 4 ./temp.dat" | |
h5open(filenm,"w") do iow | |
write(iow,"m_final",m) | |
write(iow,"pos_list",pos_list_write) | |
write(iow,"list_length_pos_list",list_length_pos_list_write) | |
end | |
println("") | |
println("pos_list at m = ",m," is stored in data file: ",filenm) | |
else | |
list_length_pos_list_write = [list_length_pos_list[i][j] for j in 1:length(list_length_pos_list[1]), i in 1:length(list_length_pos_list)] | |
filenm = string(path_file,"KudoProb_n-",n,"_mmin-",mmin,"_mmax-",mmax,"_finished.dat") | |
h5open(filenm,"w") do iow | |
write(iow,"m_final",m) | |
write(iow,"list_length_pos_list",list_length_pos_list_write) | |
end | |
println("") | |
println("pos_list at m = ",m," is empty. data file: ",filenm) | |
end | |
println("##### end #####") | |
println("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment