Skip to content

Storing data in a csv file error (running code in parallel)

OpenLB – Open Source Lattice Boltzmann Code Forums on OpenLB General Topics Storing data in a csv file error (running code in parallel)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5813
    achodankar
    Participant

    Hello Developers,
    The values in the csv file are random and don’t make sense. I am using the same code for storing data in csv file. It stores the correct values when the code is not run parallelly.

    The code snippet:

    {
    SuperLatticePhysVelocity2D<T,DESCRIPTOR> velocityF(sLattice, converter);
    BlockReduction2D2D<T> velocityPlane(velocityF,12, BlockDataSyncMode::ReduceOnly);
    ofstream myfile1;
    myfile1.open(“velocity_”+ std::to_string(iT) + “.csv”);
    myfile1 << “i,” << “j,” << “Ux,” <<“Uy”<< std::endl;
    int latticeR[2] { };
    for (latticeR[0]=0; latticeR[0] < velocityPlane.getBlockStructure().getNx(); ++latticeR[0])
    {
    for (latticeR[1]=0; latticeR[1] < velocityPlane.getBlockStructure().getNy(); ++latticeR[1])
    {
    T vel[2] { };
    velocityPlane(vel, latticeR);
    myfile1 << latticeR[0] << “,” << latticeR[1] << “,”<< vel[0] << “,”<< vel[1] << std::endl;
    }
    }
    myfile1.close();

    }

    I would really appreciate feedback on this matter.

    Thank you.

    Yours sincerely,

    Abhijeet

    #5815
    Adrian
    Keymaster

    You have to ensure that the IO only happens in the main process (where BlockDataSyncMode::ReduceOnly syncs to). Otherwise each process will write to the same file in parallel and in addition not even have the correct data.

    #5822
    achodankar
    Participant

    Hello Adrian,
    What do you mean by “IO only happens in the main process”? The code snippet is included in the getResults function and called in the main program. I would really appreciate help in this matter.

    Thank you.

    Yours sincerely,

    Abhijeet

    #5823
    Adrian
    Keymaster

    The snippet performs filesystem write operations using std::ofstream. As far as I can tell without seeing the full code, this is not restricted to the rank 0 process (where the reduced data is communicated to by BlockReduction2D2D). Thus all processes execute this the std::ofstream code and write to the same file. When using e.g. OpenLB’s default VTK writer this is resolved transparently in the background.

    #5824
    achodankar
    Participant

    Hello Adrian,
    Thank you for your feedback. I will try to work it out and meanwhile use the default VTK results temporarily.

    Thank you.

    Yours sincerely,

    Abhijeet

    #7095
    syed
    Participant

    Did you solve the problem? I am stuck with the same problem.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.