diff --git a/src/space.c b/src/space.c
index 09667d949677b9203664d22bc341fbe4b5d3f1e9..89acf0603441a86aa53b130ede841f4f074bbfdf 100644
--- a/src/space.c
+++ b/src/space.c
@@ -1158,6 +1158,21 @@ void space_init ( struct space *s , double dim[3] , struct part *parts , int N ,
     s->nr_queues = 1;
     s->size_parts_foreign = 0;
     
+    /* Check that all the particle positions are reasonable, wrap if periodic. */
+    if ( periodic ) {
+      for ( int k = 0 ; k < N ; k++ )
+        for ( int j = 0 ; j < 3 ; j++ ) {
+          while ( parts[k].x[j] < 0 ) parts[k].x[j] += dim[j];
+          while ( parts[k].x[j] >= dim[j] ) parts[k].x[j] -= dim[j];
+          }
+      }
+    else {
+      for ( int k = 0 ; k < N ; k++ )
+        for ( int j = 0 ; j < 3 ; j++ )
+          if ( parts[k].x[j] < 0 || parts[k].x[j] >= dim[j] )
+            error( "Not all particles are within the specified domain." );
+      }
+    
     /* Allocate the xtra parts array. */
     if ( posix_memalign( (void *)&s->xparts , 32 , N * sizeof(struct xpart) ) != 0 )
         error( "Failed to allocate xparts." );