# Writing data on a clustered file system

**URL:** <https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201>\
**Category:** General Discussion\
**Created:** [September 13, 2021, 7:28am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201 "2021-09-13T07:28:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 13, 2021, 7:28am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201/1 "2021-09-13T07:28:27Z")

</div>

Hello,

I have a code that runs on parallel and at the end it writes the solution on a file. When I run it on my Mac everything is ok however, when running it on a cluster I get each time a different result, I don’t get the global solution but a value that is stored on one of the procs. How can I force it to export only the global solution?

---

<div class="post-metadata">

**Author:** ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)\
**Post date:** [September 15, 2021, 2:43am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201/2 "2021-09-15T02:43:31Z")

</div>

Exporting the global solution is very expensive for large-scale problems. You can save the distributed solution as `vtu` format and view it by ParaView. If you exactly want to get the global solution, FreeFEM supports more than one way to deal with it. Here I just list one way: if you are using PETSc, you can add `-ksp_view_solution ascii:your_solution.m:ascii_matlab` to command line to put the global solution into the `.m` file.  
WIth the other way, you can refer to [FreeFem-sources/convect.edp at master · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/master/examples/hpddm/convect.edp)

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 15, 2021, 8:30am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201/3 "2021-09-15T08:30:53Z")

</div>

In addition to what Gang said, could you please put a small snippet of what you are currently doing and that is not working? Maybe this will help you to give you a more appropriate solution.

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 15, 2021, 9:09am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201/4 "2021-09-15T09:09:08Z")

</div>

Yes it works by saving the solution as a vtu format, however I’m trying to save the global value of a variable. For example when I run the code on 4 procs and save the variable to a .dat file I get each time a random value stored on one of the procs ![Screenshot 2021-09-15 at 11.05.19](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/7486debdde2277b0cdfec5d7c24c544c98e069bc.png). And one of these values is the global solution

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 15, 2021, 9:10am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201/5 "2021-09-15T09:10:23Z")

</div>

Something like this `if(mpirank == 0) { // do something only on rank 0 }` should work then?

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 15, 2021, 9:11am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201/6 "2021-09-15T09:11:00Z")

</div>

I added a screenshot below. this is the code running on 4 procs, one of the values stored at each iteration is the global value of a variable, when I try to save it on a file I get at random each time values stored at proc 1 , 2, 3 or 4

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 15, 2021, 9:13am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201/7 "2021-09-15T09:13:43Z")

</div>

Yes but the code writes values at each iteration in a parallel loop so if I add this condition before the write to file I also get a different answer each time

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 15, 2021, 9:18am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201/8 "2021-09-15T09:18:16Z")

</div>

Please post a code snippet, that doesn’t make sense to me so I can’t help you further right now.

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 15, 2021, 9:26am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201/9 "2021-09-15T09:26:49Z")

</div>

This is the time loop where im trying to save the values:

 ![Screenshot 2021-09-15 at 11.24.56](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/38ac18c0687ebe899cd16f032d99eb251cf7f820.png)

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [September 15, 2021, 9:31am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201/10 "2021-09-15T09:31:20Z")

</div>

If your `ww` is a distributed solution, you need to figure out which subdomain is in charge of the point `1, 0.05, 0` and then save only to disk for the identified subdomain with `if(mpirank == subdomain_in_charge_of_point) { // write to disk }`.

---

<div class="post-metadata">

**Author:** ![Markov](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Markov](https://community.freefem.org/u/Markov)\
**Post date:** [September 15, 2021, 9:51am UTC](https://community.freefem.org/t/writing-data-on-a-clustered-file-system/1201/11 "2021-09-15T09:51:39Z")

</div>

I see, thank you very much.
