Crooked array saving to files

Hello everyone, I need to write two random matrices to txt files and read them later, but every time I try to do this, I notice that the files were written very crookedly, my program does not work from this.
As I have read, it is not possible to write a two-dimensional array (matrix) to a txt file, so the question is how to do it right?

using DelimitedFiles
using LinearAlgebra
using MPI
MPI.Init()
comm = MPI.COMM_WORLD
rank = MPI.Comm_rank(comm)
size = MPI.Comm_size(comm)
N = 100
function create_random_matrices()
    A = rand(Float64, N, N)
    B = rand(Float64, N, N)
    writedlm("matrix_A.csv", A, ',')
    writedlm("matrix_B.csv", B, ',')
end

function multiply_matrices()
    MPI.Init()

    comm = MPI.COMM_WORLD
    rank = MPI.Comm_rank(comm)
    size = MPI.Comm_size(comm)

    if rank == 0
        A = readdlm("matrix_A.csv", ',', Float64)
        B = readdlm("matrix_B.csv", ',', Float64) 
        start_time = MPI.Wtime()
    else
        A = zeros(N, N)
        B = zeros(N, N)
    end

    block_size = Int64(N // size)
    local_A = zeros(block_size, N)
    local_B = zeros(N, block_size)
    local_C = zeros(block_size, block_size)
    MPI.Scatter!(A, local_A, comm)
    MPI.Scatter!(B, local_B, comm)

    for i in 1:block_size
        for j in 1:block_size
            for k in 1:block_size
                local_C[i, j] += dot(local_A[i, k], local_B[k, j])
            end
        end
    end

    C = MPI.Gather(local_C, comm)
   if rank == 0
       elapse_time=MPI.Wtime()-start_time
       return(elapse_time)
    end

    MPI.Finalize()
end
create_random_matrices()
elapse_time = multiply_matrices()
println(elapse_time)

Hi @k.kirshin123, what do you mean by “crookedly”? Are you referring to the missing spaces / line breaks between the rows of your matrix in the text file?
I just tried create_random_matrices() and it worked properly on my laptop. Maybe your text editor autoformatted the CSVs?

Where did you read this?

I think the issue is that you are calling MPI.Init() at the start of the script, and not inside the multiply_matrices function, like you did here Help me pls with method error
Hence, multiple processors are trying to write to the same file at the same time.

I think this happens regardless of whether you have called MPI.Init().

Either move MPI.Init() inside the function or Do something like this to only create the matrices once:

MPI.Init()
if rank == 0
   create_random_matrices()
end
MPI.Barrier()