AMReX-Astro / AMReX-Astro/Castro

`read_particle_params` unconditionally creates `particles::timestamp_dir` even when timestamping is disabled/empty

Open Beginner friendly
#3,225 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ai-code-audit particles
Dominant language
C++
Stars
340
Forks
105
Avg merge
3d 8h
Merged PRs (30d)
8

Description

Summary

Castro::read_particle_params() always calls UtilCreateDirectory(particles::timestamp_dir, 0755) on IO rank, without checking whether timestamp_dir is non-empty or whether tracer timestamping is enabled. If timestamp_dir is empty, this can fail during startup before any particle work is done.

Location

  • Source/particles/CastroParticles.cpp:29

Problem Details

Current code:

if (ParallelDescriptor::IOProcessor())
    if (!amrex::UtilCreateDirectory(particles::timestamp_dir, 0755))
        amrex::CreateDirectoryFailed(particles::timestamp_dir);
ParallelDescriptor::Barrier();

But later timestamp writes are guarded with !particles::timestamp_dir.empty(), so directory creation is inconsistent with usage.

Impact

  • Possible startup abort when particles::timestamp_dir is empty or unset.
  • Unnecessary filesystem operations when timestamp output is not requested.

Suggested Patch

diff --git a/Source/particles/CastroParticles.cpp b/Source/particles/CastroParticles.cpp
--- a/Source/particles/CastroParticles.cpp
+++ b/Source/particles/CastroParticles.cpp
@@
-    if (ParallelDescriptor::IOProcessor())
-        if (!amrex::UtilCreateDirectory(particles::timestamp_dir, 0755))
-            amrex::CreateDirectoryFailed(particles::timestamp_dir);
-    //
-    // Force other processors to wait till directory is built.
-    //
-    ParallelDescriptor::Barrier();
+    if (!particles::timestamp_dir.empty()) {
+        if (ParallelDescriptor::IOProcessor()) {
+            if (!amrex::UtilCreateDirectory(particles::timestamp_dir, 0755)) {
+                amrex::CreateDirectoryFailed(particles::timestamp_dir);
+            }
+        }
+        //
+        // Force other processors to wait till directory is built.
+        //
+        ParallelDescriptor::Barrier();
+    }

Prepared by Codex

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Source/particles/CastroParticles.cpp:29 and read Castro::read_particle_params(), including the existing timestamp-directory checks described in the issue. Verify that startup with an empty timestamp_dir avoids directory creation and that configured timestamp output still creates its directory before the barrier.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
hpc
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.