# Relations between batch\_size, ring dimension and array of values

**URL:** <https://openfhe.discourse.group/t/relations-between-batch-size-ring-dimension-and-array-of-values/1381>\
**Category:** FHE Questions\
**Created:** [June 26, 2024, 8:10am UTC](https://openfhe.discourse.group/t/relations-between-batch-size-ring-dimension-and-array-of-values/1381 "2024-06-26T08:10:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![evgen](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@evgen](https://openfhe.discourse.group/u/evgen)\
**Post date:** [June 26, 2024, 8:10am UTC](https://openfhe.discourse.group/t/relations-between-batch-size-ring-dimension-and-array-of-values/1381/1 "2024-06-26T08:10:59Z")

</div>

Hallo,  
i use your project for research and evaluate ckks. I don’t understand the connection between batch\_size, ring dimension and array of values  
If i want to encrypt 10 values of array, i should set batch\_size to 16, because number of slots cannot be smaller than value vector size. Is it right?  
Second question, if i change my batch\_size to 16, 32, my ring dimension doesnt change (ring dimension: 16384). Why?  
What is mention of batch\_size  
Why do not change my ring dimension. Can i change ring dimension without changing batch\_size?  
How can i encrypt many values of encoded vector

---

<div class="post-metadata">

**Author:** ![andreea.alexandru](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/andreea.alexandru/32/378_2.png) [@andreea.alexandru](https://openfhe.discourse.group/u/andreea.alexandru)\
**Post date:** [June 26, 2024, 9:40am UTC](https://openfhe.discourse.group/t/relations-between-batch-size-ring-dimension-and-array-of-values/1381/2 "2024-06-26T09:40:39Z")

</div>

In CKKS, a ciphertext can encrypt up to ring\_dim/2 values. For efficiency reasons, if the application requires fewer than ring\_dim/2 values, one can work in a subring whose size is specified by batch\_size.

As a rule, array\_to\_encrypt\_size \<= batch\_size \<= ring\_dim/2. The ring dimension is determined first by the security level specified and by the ciphertext modulus (determined by the number and size of moduli). If your specified batch\_size (number of values you want to encrypt) is less than the half of this determined ring dimension, then nothing changes. Otherwise, the ring dimension will increase to be able to support the batch\_size specified.

---

<div class="post-metadata">

**Author:** ![evgen](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@evgen](https://openfhe.discourse.group/u/evgen)\
**Post date:** [June 26, 2024, 11:03am UTC](https://openfhe.discourse.group/t/relations-between-batch-size-ring-dimension-and-array-of-values/1381/3 "2024-06-26T11:03:50Z")

</div>

@andreea.alexandru  
I thought that batch\_size define ring\_dim, like  
batch\_size \* 2 = ring\_dim  
How can i change security level and ciphertext modulus or can self set ring dimension?

---

<div class="post-metadata">

**Author:** ![andreea.alexandru](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/andreea.alexandru/32/378_2.png) [@andreea.alexandru](https://openfhe.discourse.group/u/andreea.alexandru)\
**Post date:** [June 26, 2024, 12:00pm UTC](https://openfhe.discourse.group/t/relations-between-batch-size-ring-dimension-and-array-of-values/1381/4 "2024-06-26T12:00:07Z")

</div>

What is your goal? To get a smaller ring dimension for a fixed security level and fixed batch size? Set the multiplicative depth to the lowest value you need for your computation, and set the firstModSize and scalingModSize to lower values than the default ones.

Please search the forum for this, as there are many discussions on choices for the CKKS parameters.

---

<div class="post-metadata">

**Author:** ![evgen](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@evgen](https://openfhe.discourse.group/u/evgen)\
**Post date:** [June 26, 2024, 12:13pm UTC](https://openfhe.discourse.group/t/relations-between-batch-size-ring-dimension-and-array-of-values/1381/5 "2024-06-26T12:13:53Z")

</div>

i wanted to vary ring dimension and security level to compare execution time of ckks

---

<div class="post-metadata">

**Author:** ![evgen](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@evgen](https://openfhe.discourse.group/u/evgen)\
**Post date:** [June 26, 2024, 10:08pm UTC](https://openfhe.discourse.group/t/relations-between-batch-size-ring-dimension-and-array-of-values/1381/6 "2024-06-26T22:08:50Z")

</div>

One question, if i set parameters like array\_to\_encrypt\_size \<= batch\_size, i get unknown values at the end of endcrypted array. Should i change something?  
i set:  
batch\_size = int(32768/2)  
RingDimValue=32768  
parameters.SetSecurityLevel(HEStd\_NotSet);  
parameters.SetRingDim( yourRingDimValue );

Output:  
Results of homomorphic computations:  
x1 = (0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, -6.99408e-12, -3.16094e-12, 1.33607e-12, 6.05779e-12, -2.50286e-12, -5.07379e-12, 3.38626e-12, -3.95326e-12, 1.13897e-11, -2.70856e-15, -4.80819e-12, 1.54104e-13, 5.91013e-13, -4.87261e-12, 1.71532e-12, -4.56572e-13, 7.63633e-12, 4.14733e-12, 6.18406e-12, 9.93665e-13, -4.38816e-12, -4.22277e-12, -1.51131e-12, -3.74516e-12, -4.21287e-12, …

---

<div class="post-metadata">

**Author:** ![andreea.alexandru](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/andreea.alexandru/32/378_2.png) [@andreea.alexandru](https://openfhe.discourse.group/u/andreea.alexandru)\
**Post date:** [June 27, 2024, 5:11pm UTC](https://openfhe.discourse.group/t/relations-between-batch-size-ring-dimension-and-array-of-values/1381/7 "2024-06-27T17:11:29Z")

</div>

A plaintext/ciphertext in CKKS encodes a vector. The expected behavior is to fill the plaintext vector up to the batch size with zeroes. This is what you observe. CKKS is an approximate scheme, so 0 is approximated by the small numbers that you see.

---

<div class="post-metadata">

**Author:** ![evgen](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@evgen](https://openfhe.discourse.group/u/evgen)\
**Post date:** [June 27, 2024, 7:31pm UTC](https://openfhe.discourse.group/t/relations-between-batch-size-ring-dimension-and-array-of-values/1381/8 "2024-06-27T19:31:56Z")

</div>

> [@andreea.alexandru](#):
>
> The expected behavior is to fill the plaintext vector up to the batch size with zeroes.

Can i set the value of batch\_size flexibel, without a concrete value

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [June 30, 2024, 6:11pm UTC](https://openfhe.discourse.group/t/relations-between-batch-size-ring-dimension-and-array-of-values/1381/9 "2024-06-30T18:11:05Z")

</div>

When the batch size is set to 0, it corresponds to full packing, i.e., the number of slots is automatically set to ring\_dim/2. If one sets it to a non-zero (a power of two), this custom value is used.
