Skip to content

Commit

Permalink
add cores documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Aug 10, 2024
1 parent 674595d commit bc374ea
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 30 deletions.
33 changes: 28 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,34 @@ Memory allocation for the same models
| **Capybara** | 27MB | 32MB | 20MB | 23MB | 29MB | 43MB |
| Fixest | 44MB | 36MB | 27MB | 32MB | 41MB | 63MB |

# Debugging
## Changing the number of cores

I run `r_valgrind "dev/test_get_alpha.r"` or the corresponding test from the
project's root in a new terminal (bash).
Note that you can edit the `Makevars` file to change the number of cores that
capybara uses, here is an example of how it affects the performance

| cores | PPML | Trade Diversion | Endogeneity | Reverse Causality | Non-linear/Phasing Effects | Globalization |
|:------|-------:|-----------------:|------------:|------------------:|---------------------------:|--------------:|
| 2 | 1.8s | 16.2s | 7.7s | 9.6s | 13.0s | 24.0s |
| 4 | 1.7s | 16.0s | 7.4s | 9.3s | 12.3s | 23.6s |
| 6 | 0.7s | 2.4s | 2.0s | 2.0s | 2.5s | 4.0s |
| 8 | 0.3s | 2.0s | 1.2s | 1.4s | 1.7s | 3.4s |

## Testing and debugging

## Testing

I use `testthat` (e.g., `devtools::test()`) to compare the results with base R.
These tests are about the correctness of the results.

### Debuging

I run `r_valgrind "dev/valgrind-kendall-correlation.r"` or the corresponding
test from the project's root in a new terminal (bash) after running
`devtools::install()`. These tests are about memory leaks (e.g., I use
repeteated computations and sometimes things such as "pi = 3").

This works because I previously defined this in `.bashrc`, to make it work you
need to run `source ~/.bashrc` or reboot:
need to run `source ~/.bashrc` or reboot your computer.

```
function r_debug_symbols () {
Expand Down Expand Up @@ -209,4 +230,6 @@ When you are ready testing, you need to remove `-UDEBUG` from `src/Makevars`.

## Code of Conduct

Please note that the capybara project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
Please note that the capybara project is released with a
[Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,35 @@ Memory allocation for the same models
| **Capybara** | 27MB | 32MB | 20MB | 23MB | 29MB | 43MB |
| Fixest | 44MB | 36MB | 27MB | 32MB | 41MB | 63MB |

# Debugging
## Changing the number of cores

I run `r_valgrind "dev/test_get_alpha.r"` or the corresponding test from
the project’s root in a new terminal (bash).
Note that you can edit the `Makevars` file to change the number of cores
that capybara uses, here is an example of how it affects the performance

| cores | PPML | Trade Diversion | Endogeneity | Reverse Causality | Non-linear/Phasing Effects | Globalization |
| :---- | ---: | --------------: | ----------: | ----------------: | -------------------------: | ------------: |
| 2 | 1.8s | 16.2s | 7.7s | 9.6s | 13.0s | 24.0s |
| 4 | 1.7s | 16.0s | 7.4s | 9.3s | 12.3s | 23.6s |
| 6 | 0.7s | 2.4s | 2.0s | 2.0s | 2.5s | 4.0s |
| 8 | 0.3s | 2.0s | 1.2s | 1.4s | 1.7s | 3.4s |

## Testing and debugging

## Testing

I use `testthat` (e.g., `devtools::test()`) to compare the results with
base R. These tests are about the correctness of the results.

### Debuging

I run `r_valgrind "dev/valgrind-kendall-correlation.r"` or the
corresponding test from the project’s root in a new terminal (bash)
after running `devtools::install()`. These tests are about memory leaks
(e.g., I use repeteated computations and sometimes things such as “pi =
3”).

This works because I previously defined this in `.bashrc`, to make it
work you need to run `source ~/.bashrc` or reboot:
work you need to run `source ~/.bashrc` or reboot your computer.

function r_debug_symbols () {
# if src/Makevars does not exist, exit
Expand Down
2 changes: 1 addition & 1 deletion dev/benchmarks_tests_agtpa_capybara_only.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# this is not just about speed/memory, but also about obtaining the same
# slopes as in base R

library(capybara)
devtools::load_all()
library(dplyr)
library(tidyr)
library(janitor)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions dev/valgrind-kendall-correlation.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# this is also tested in /tests

set.seed(123)
x <- rnorm(100)
y <- rpois(100, 2)

for (i in 1:100) {
kendall_cor(x, y)
}
82 changes: 75 additions & 7 deletions docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pkgdown: 2.0.7
pkgdown_sha: ~
articles:
intro: intro.html
last_built: 2024-08-08T15:09Z
last_built: 2024-08-10T20:44Z

2 changes: 1 addition & 1 deletion docs/reference/apes.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/bias_corr.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/reference/feglm.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/felm.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/fenegbin.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/fepoisson.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/00_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cmath>
#include <cpp11.hpp>
#include <numeric>
#include <r_armadillo_bindings.hpp>
#include <cpp11armadillo.hpp>
#include <vector>

// #include <iostream>
Expand Down
2 changes: 0 additions & 2 deletions src/06_glm_offset_fit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ feglm_offset_fit_(const doubles &eta_r, const doubles &y_r,
const int n = y.n_elem;
Col<double> mu_eta(n), yadj(n);
Mat<double> w(n, 1);
bool conv = false;

bool dev_crit, val_crit, imp_crit;
double dev_old, dev_ratio, dev_ratio_inner, rho;
Expand Down Expand Up @@ -90,7 +89,6 @@ feglm_offset_fit_(const doubles &eta_r, const doubles &y_r,
dev_ratio = fabs(dev - dev_old) / (0.1 + fabs(dev));

if (dev_ratio < dev_tol) {
conv = true;
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Makevars
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_OPENMP_THREADS=8
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
2 changes: 1 addition & 1 deletion src/Makevars.win
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_OPENMP_THREADS=8
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

0 comments on commit bc374ea

Please sign in to comment.