Hello, I would appreciate some advice on a multi thread code causing a segmentation fault with my workstation Dell Inc. Precision 7960 Tower (Intel® Xeon® w9-3495X × 112), running Ubuntu 24.04.2 LTS. Here you find a simplified situation. I have a matrix, which I update inside a multi thread for cycle. I have also divided the total number of samples to process into chunks.
# classify the trajectories. parallel version
m = size(orbit_array,1)
output_report = zeros(m,6)
num_threads = Threads.nthreads() #I use 32 out of 112
chunk_size = 100
start_num = 1
selected_elements = range(start_num,m)
# Total number of elements to process
total_elements = length(selected_elements)
# the orbits are processed in chunks. At the end of the chunk, results are saved
num_chunks = ceil(Int, length(selected_elements) / chunk_size)
# Calculate chunk size (total elements divided by the number of chunks)
chunk_size = ceil(Int, total_elements / num_chunks)
# Create a list of ranges for each chunk
chunks = [(chunk_id - 1) * chunk_size + 1: min(chunk_id * chunk_size, total_elements) for chunk_id in 1:num_chunks]
npzwrite("output.npy", output_report)
for chunk_id in 1:num_chunks
# Get the range of elements for this chunk
range_start, range_end = chunks[chunk_id][1], chunks[chunk_id][end]
# Load intermediate results
output_report = npzread("output.npy")
@threads for i in range_start:range_end
j = selected_elements[i]
println(" Thread $(threadid()). orbit $j, element $i of $total_elements")
output_report[j,6] = classifier(orbit_array[j,:,:])
end
println("Finished chunk $chunk_id, saving intermediate results...\n")
npzwrite("output.npy", output_report)
end
The classifier function just provides a float number, which I add at the last column at the corresponding row. The classifier (a complex function) is not important in this discussion: the error arises also when substituting it with a simpler output_report[j,6] = 1
.
When running this code on VSCode a segmentation fault is produced on this machine. I am not able to report the error output, as the julia terminal crashes right after. I have also tried another version of this code by using the @spawn
method, but the result is the same. However, whenever I run this code on my Windows laptop, everything works as expected, without bugs.
What can be the issue with the workstation? Thank you for your help.