Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EAMxx: rely more on Field methods in scorpio output #6965

Open
bartgol opened this issue Feb 1, 2025 · 1 comment
Open

EAMxx: rely more on Field methods in scorpio output #6965

bartgol opened this issue Feb 1, 2025 · 1 comment
Assignees
Labels
code cleanup EAMxx PRs focused on capabilities for EAMxx

Comments

@bartgol
Copy link
Contributor

bartgol commented Feb 1, 2025

The output class is gigantic, but a lot of lines are to deal with update of the views. Instead, we can realy more on the Field class, to perform update, including masking.

@bartgol bartgol added code cleanup EAMxx PRs focused on capabilities for EAMxx labels Feb 1, 2025
@bartgol bartgol self-assigned this Feb 1, 2025
@bartgol
Copy link
Contributor Author

bartgol commented Feb 1, 2025

I already started to do some work on this, and one hour already got me quite a lot of work done. I think I'll be able to have something ready for a draft PR early next week. A little sneak-peak: this is the core of the output class update of the tallies, average handling, and call to scorpio. Some methods (like Field::max) will be introduced in the branch.

  for (auto const& name : m_fields_names) {
    // Get all the info for this field.
    const auto& f_in  = m_field_mgrs[AfterHRemap]->get_field(name);
    const auto& f_out = m_field_mgrs[Scorpio]->get_field(name);

    switch (m_avg_type) {
      case OutputAvgType::Instant:
        f_out.deep_copy(f_in);  break;
      case OutputAvgType::Max:
        f_out.max(f_in);        break;
      case OutputAvgType::Min:
        f_out.min(f_in);        break;
      case OutputAvgType::Average:
        f_out.update(f_in,1,1); break;
      default:
        EKAT_ERROR_MSG ("Unexpected/unsupported averaging type.\n");
    }

    if (is_write_step) {
      if (output_step and avg_type==OutputAvgType::Average) {
        // NOTE: we don't divide by the avg cnt for checkpoint output
        if (m_track_avg_cnt) {
          const auto avg_cnt = m_field_to_avg_cnt_map.at(name);

          // We update f_out as "f_out*avg_cnt_inv + avg_cnt_mask" where
          // 
          // avg_cnt_int[i] is
          //   1/avg_cnt[i]    if  avg_cnt[i]>threshold
          //   0               otherwise
          // avg_cnt_mask[i] is
          //   0               if  avg_cnt[i]>threshold
          //   fill_value      otherwise
          // NOTE: the part "+avg_cnt_mask" is only done if the percentage threshold is >0.
          //       If threshold=0, it means we are not worrying about that

          f_out.scale(avg_cnt_inv);
          if (m_avg_coeff_threshold>0) {
            f_out.update(avg_cnt_mask);
          }
        } else {
          // Divide by steps count only when the summation is complete
          f_out.scale(1.0 / nsteps_since_last_output);
        }
      }

      // Bring data to host
      f_out.sync_to_host();

      // Write
      auto func_start = std::chrono::steady_clock::now();
      scorpio::write_var(filename,name,f_out.get_internal_view_data<Real,Host>());
      auto func_finish = std::chrono::steady_clock::now();
      auto duration_loc = std::chrono::duration_cast<std::chrono::milliseconds>(func_finish - func_start);
      duration_write += duration_loc.count();
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code cleanup EAMxx PRs focused on capabilities for EAMxx
Projects
None yet
Development

No branches or pull requests

1 participant