diff --git a/cpp/particles/particles_output_hdf5.hpp b/cpp/particles/particles_output_hdf5.hpp
index 6978a45c351bdb0b80e844dbb4e4fd7832390cc4..4fbd16c98f44034491e7d6b02308d5fa8a32ead6 100644
--- a/cpp/particles/particles_output_hdf5.hpp
+++ b/cpp/particles/particles_output_hdf5.hpp
@@ -29,6 +29,7 @@
 #include <memory>
 #include <vector>
 #include <hdf5.h>
+#include <sys/stat.h>
 
 #include "abstract_particles_output.hpp"
 #include "scope_timer.hpp"
@@ -140,10 +141,23 @@ public:
         if(Parent::isInvolved()){
             if (Parent::getMyRank() == 0)
             {
-                hid_t file_id = H5Fopen(
+                bool file_exists = false;
+                {
+                    struct stat file_buffer;
+                    file_exists = (stat(filename.c_str(), &file_buffer) == 0);
+                }
+                hid_t file_id;
+                if (file_exists)
+                    file_id = H5Fopen(
                         filename.c_str(),
                         H5F_ACC_RDWR | H5F_ACC_DEBUG,
                         H5P_DEFAULT);
+                else
+                    file_id = H5Fcreate(
+                        filename.c_str(),
+                        H5F_ACC_EXCL | H5F_ACC_DEBUG,
+                        H5P_DEFAULT,
+                        H5P_DEFAULT);
                 assert(file_id >= 0);
                 bool group_exists = H5Lexists(
                         file_id,