-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallel_pi.c
81 lines (63 loc) · 1.95 KB
/
parallel_pi.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
#include "cmsis.h"
#include "gap_common.h"
#include "mbed_wait_api.h"
// FEATURE_CLUSTER
#include "gap_cluster.h"
#include "gap_dmamchan.h"
#include <stdlib.h>
#include <time.h>
#define FC_FREQ (300000000)
#define CLUSTER_FREQ (200000000)
#define F_DIV (1000000)
#define NPOINTS (10000000)
#define NUM_THREADS (8)
#define CORE_NUMBER (8)
uint32_t current_voltage(void)
{
return DCDC_TO_mV(PMU_State.DCDC_Settings[READ_PMU_REGULATOR_STATE(PMU_State.State)]);
}
void pi(void *arg){
float random1, random2;
int i, *hit_pointer, count=0;
unsigned int seed;
hit_pointer = (int *) arg;
seed = (unsigned int) FLL_GetFrequency(uFLL_SOC);
for(i = 0; i < (NPOINTS/NUM_THREADS); i++){
random1 = (float)(2*rand_r(&seed))/RAND_MAX;
random2 = (float)(2*rand_r(&seed))/RAND_MAX;
if(random1*random1+random2*random2 <= 1){
count++;
}
}
printf("%d - %d - %d\n",__core_ID(), seed, i);
hit_pointer[__core_ID()] = count;
}
void Master_Entry(int * L1_mem)
{
CLUSTER_CoresFork(pi, (void *) L1_mem);
}
int main(){
float random1, random2;
int i, count=0;
FLL_SetFrequency(uFLL_SOC, FC_FREQ, 0);
/* Cluster Start - Power on */
CLUSTER_Start(0, CORE_NUMBER);
int *L1_mem = L1_Malloc(8);
if (FLL_SetFrequency(uFLL_CLUSTER, CLUSTER_FREQ, 0) == -1) {
printf("Error of changing frequency, check Voltage value!\n");
}
printf("FC Frequency: %d MHz - Cluster Frequency: %d MHz - Voltage: %lu mV\n",
FLL_GetFrequency(uFLL_SOC)/F_DIV, FLL_GetFrequency(uFLL_CLUSTER)/F_DIV, current_voltage());
CLUSTER_SendTask(0, Master_Entry, (void *) L1_mem, 0);
printf("Waiting...\n");
CLUSTER_Wait(0);
for (int i = 0; i < 8; i++) {
count += L1_mem[i];
printf("CORE %d - count = %d\n", i, L1_mem[i]);
}
/* Cluster Stop - Power down */
CLUSTER_Stop(0);
printf("DONE!\n");
printf("Pi: %d\n", (int) (100000*((float)(4*count)/NPOINTS)));
exit(0);
}