-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselective_threading_not_working.c
86 lines (60 loc) · 1.52 KB
/
selective_threading_not_working.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* include headers */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <omp.h>
/* defines */
#define false 0
#define true 1
#define boolean char
/* global variables */
/* function prototypes */
void backtrack(unsigned, unsigned, unsigned *, unsigned, unsigned);
/****************************************************/
int main(int argc, char *argv[])
{
unsigned *tuple;
unsigned size = 3;
unsigned alphabet = 3;
unsigned threading_depth = 1;
tuple = (unsigned *) calloc(size,sizeof(unsigned));
omp_set_num_threads(2);
backtrack(size,alphabet,tuple,0,threading_depth);
return(1);
}
void backtrack(unsigned size, unsigned alphabet, unsigned *tuple, unsigned ell, unsigned t_depth)
{
unsigned i,j;
boolean unused;
if(ell==size)
{
#pragma omp critical
{
fprintf(stdout,"solution from thread #%d = ",omp_get_thread_num());
for(i=0;i<size;i++)
fprintf(stdout,"%3d ",tuple[i]);
fprintf(stdout,"\n");
}
}
else
{
#pragma omp parallel for if(ell == t_depth) default(none) shared(alphabet,tuple,size,ell,t_depth) private(j,unused)
for(i=0;i<alphabet;i++)
{
unsigned *tuple_to_send;
if(ell == t_depth)
{
unsigned *local_tuple;
local_tuple = (unsigned *) calloc(size,sizeof(unsigned));
for(j=0;j<ell;j++) local_tuple[j] = tuple[j];
tuple_to_send = local_tuple;
}
else
{
tuple_to_send = tuple;
}
tuple_to_send[ell] = i;
backtrack(size,alphabet,tuple_to_send,ell+1,t_depth);
}
}
}