# Auxiliary argument for map reduce in rstan

**URL:** https://discourse.mc-stan.org/t/auxiliary-argument-for-map-reduce-in-rstan/33824
**Category:** Modeling
**Tags:** techniques, rstan
**Created:** [January 13, 2024, 7:53pm UTC](https://discourse.mc-stan.org/t/auxiliary-argument-for-map-reduce-in-rstan/33824 "2024-01-13T19:53:55Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![luchinoprince](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/luchinoprince/32/16355_2.png) [@luchinoprince](https://discourse.mc-stan.org/u/luchinoprince)
#### Post date: [January 13, 2024, 7:53pm UTC](https://discourse.mc-stan.org/t/auxiliary-argument-for-map-reduce-in-rstan/33824/1 "2024-01-13T19:53:55Z")

</div>

Hello to everyone, I am looking to parallelise within chain some code in STAN to boost computation time. Unfortunately my target function cannot be aggregated trough a simple sum, i.e `reduce_sum` in this case does not work. I need some parallel code that returns a vector of known length `b` and then I have to post process that to get my desired likelihood.

The main issue I am having is that to compute this likelihood I need to pass 4 auxiliary matrices to the likelihood function, say A,B,C, Omega. From these I can the compute the likelihood. It seems to me that currently `map_rect` only accepts a pre-specified number of inputs;

```no-highlight
vector map_rect((vector, vector, array[] real, array[] int):vector f,
                vector phi, array[] vector thetas,
                data array[,] real x_rs, data array[,] int x_is);

```

From this source it seems I can only pass one auxiliary vector `phi` to the`map_rect` function, is it true? Ideally I would like to have something like:

```no-highlight
vector lp(matrix A, matrix B, matrix C, matrix Omega, array[] matrix Y){.....
.................
return lp'
}

```

Where my data is an array of matrices. Can I pass this type of data to `map_rect`, or does it only work for the data types presented in the Rstan documentation?

Best,  
Luca
