# Garfield program not running at 100% cpu load

**URL:** <https://root-forum.cern.ch/t/garfield-program-not-running-at-100-cpu-load/44522>\
**Category:** Garfield++\
**Created:** [April 21, 2021, 9:09pm UTC](https://root-forum.cern.ch/t/garfield-program-not-running-at-100-cpu-load/44522 "2021-04-21T21:09:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henry\_Billiot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/henry_billiot/32/25659_2.png) [@Henry\_Billiot](https://root-forum.cern.ch/u/Henry_Billiot)\
**Post date:** [April 21, 2021, 9:09pm UTC](https://root-forum.cern.ch/t/garfield-program-not-running-at-100-cpu-load/44522/1 "2021-04-21T21:09:02Z")

</div>

Hi,

As the title suggests, I have recently come across an issue where the execution of a Garfield++ code does not run at 100% of CPU load. This problem causes the program to take longer to execute as well as wasting “resources” when run on a supercomputer. So, any suggestion on how I can alleviate this problem is greatly appreciated.

Previously, this is the typical running load of my code (display from htop):

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/1/3/1342ed7e0c22ea2354c2b6f37783c0fbd76093e0.png)

As one can see, all threads are utilized at 100%, and this is kept up throughout the execution. However, at this point, this is no longer the case. As I increase the number of electrodes to be calculated for signals, the running load becomes like this

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/3/a/3a14b8da0d99263bda028df2c14d30a3c296bad2.png)

So, the load for all threads just drops by ~30%. I was able to narrow down to this part of my code that causes this issue

```auto
  double xe1, ye1, ze1, te1, e1;
  double xe2, ye2, ze2, te2, e2;
  double xi1, yi1, zi1, ti1;
  double xi2, yi2, zi2, ti2;
  int status;
  int Aright = 0, Aleft = 0;
  int count = index;
  bool calculate_signal = true;
  int max = omp_get_max_threads();
  std::cout << "Maximum number of threads: " << max << std::endl;
  omp_set_dynamic(0);
  omp_set_num_threads(max);
  #pragma omp parallel for
  for (int k = 0; k < index; k++) {
    AvalancheMicroscopic aval;
    aval.SetSensor(&sensor);
    aval.EnableSignalCalculation(calculate_signal); 
    aval.AvalancheElectron(electrons.at(k*4 + 0),electrons.at(k*4 + 1),electrons.at(k*4 + 2),electrons.at(k*4 + 3), 0.1, 0,0,0);
    const int np = aval.GetNumberOfElectronEndpoints();
    DriftLineRKF drift;
    drift.SetSensor(&sensor);
    drift.EnableSignalCalculation(calculate_signal);
    for (int j = np; j--;) {
      aval.GetElectronEndpoint(j, xe1, ye1, ze1, te1, e1, 
                                  xe2, ye2, ze2, te2, e2, status);
      drift.DriftIon(xe1, ye1, ze1, te1);
    }
  }

```

Specifically, it is the second for loop (the inside for loop) that causes this issue (when I comment out the second for loop, all thread runs at ~100%). If anyone has come across this issue or knows how to fix it, please let me know.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [April 22, 2021, 7:59am UTC](https://root-forum.cern.ch/t/garfield-program-not-running-at-100-cpu-load/44522/2 "2021-04-22T07:59:42Z")

</div>

Perhaps a Garfield++ developer could answer? Not sure who to cite @Axel

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [April 22, 2021, 8:11am UTC](https://root-forum.cern.ch/t/garfield-program-not-running-at-100-cpu-load/44522/3 "2021-04-22T08:11:55Z")

</div>

I’ll look into it, but I’m afraid I won’t have time in the next two days…

---

<div class="post-metadata">

**Author:** ![Henry\_Billiot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/henry_billiot/32/25659_2.png) [@Henry\_Billiot](https://root-forum.cern.ch/u/Henry_Billiot)\
**Post date:** [April 22, 2021, 3:13pm UTC](https://root-forum.cern.ch/t/garfield-program-not-running-at-100-cpu-load/44522/4 "2021-04-22T15:13:18Z")

</div>

Hi,

Thank you for the reply. It would be great if you can look at it when you get the chance. In the meantime, I am doing some profiling and trying different solutions. I will post my progress here once I get some sort of update on my end. Thank you again.

---

<div class="post-metadata">

**Author:** ![Henry\_Billiot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/henry_billiot/32/25659_2.png) [@Henry\_Billiot](https://root-forum.cern.ch/u/Henry_Billiot)\
**Post date:** [April 25, 2021, 5:14pm UTC](https://root-forum.cern.ch/t/garfield-program-not-running-at-100-cpu-load/44522/5 "2021-04-25T17:14:35Z")

</div>

Hi,

I have not found any solution so far, but here are some behaviors that I have noticed:

1. The reduction in utilization can be alleviated (only slightly) by decreasing the number of threads used.

2. Since the second loop has a rather large range (np can be between 1 to ~2000), this may be causing load imbalance? (This is only a guess).

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 9, 2021, 5:14pm UTC](https://root-forum.cern.ch/t/garfield-program-not-running-at-100-cpu-load/44522/6 "2021-05-09T17:14:48Z")

</div>

Closed on May 9, 2021, 5:14pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
