---
# System prepended metadata

title: CAOS Exercise Session Lecture 7

---

# CAOS Exercise Session Lecture 7

![](https://i.imgur.com/PDTxovr.png)
![](https://i.imgur.com/SjH8CU2.png)

![](https://i.imgur.com/6mCflw8.png)
![](https://i.imgur.com/W2Y7KmU.png)

```
1234567890
MMMMM
     AAA
     MMMMM
     MMMMM              //Nyt loop
          AAA
          MMMMM
          MMMMM         //Nyt loop
               AAA
               MMMMM
               MMMMM    //Nyt loop
```


![](https://i.imgur.com/ZmCYuk3.png)
![](https://i.imgur.com/objZz5m.png)

```c
void combine5(vec_ptr v, data_t *dest) {
    long i;
    long length = vec_length(v);
    long limit = length-1;
    data_t *data = get_vec_start(v);
    data_t acc = IDENT;
    
    
    for (i = 0; i < limit; i+=2) {
        acc = (acc OP data[i]) OP data[i+1];
    }
    
    for(;i < length; i++) {
        acc = acc OP data[i];
    }
    
    *dest = acc;
}
```
$k=5$ version
```c
void combine5(vec_ptr v, data_t *dest) {
    long i;
    long length = vec_length(v);
    long limit = length-4;
    data_t *data = get_vec_start(v);
    data_t acc = IDENT;
    
    
    for (i = 0; i < limit; i+=5) {
        acc = ((((acc OP data[i]) 
            OP data[i+1]) OP data[i+2]) 
            OP data[i+3]) OP data[i+4];
    }
    
    for(;i < length; i++) {
        acc = acc OP data[i];
    }
    
    *dest = acc;
}
```
