-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum_subset.c
More file actions
33 lines (28 loc) · 840 Bytes
/
sum_subset.c
File metadata and controls
33 lines (28 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* Sum Parallelisation using Threads
* Thread Function
*
* Copyright (C) 2021 Richi Dubey <richidubey@gmail.com>
*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the LICENSE file in the top-level directory.
*/
#include "main.h"
void *sum_subset(void *arg)
{
int begin = ((thread_data *)arg)->begin;
int size = ((thread_data *)arg)->size;
long long int sum=0;
#if DEBUG_MODE
printf("Inside thread with starting point %d\n",((thread_data *)arg)->begin);
#endif
for (int i=0; i< size; i++) {
sum += arr[i+begin];
}
#if DEBUG_MODE
printf("Leaving thread with starting point %d and size %d: returned sum %lld\n",((thread_data *)arg)->begin, ((thread_data *)arg)->size, sum);
fflush(stdout);
#endif
((thread_data *)arg)->subset_sum = sum;
pthread_exit(NULL);
}