move openmp loop variable outside

This commit is contained in:
Krishna Vedala 2020-04-23 20:17:32 -04:00
parent bf1c367a62
commit dee56f7781
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
7 changed files with 48 additions and 36 deletions

View File

@ -25,7 +25,8 @@ int get_number(FILE *fp, char *buffer, uint8_t *out_int)
{
perror("found inavlid character in the number!");
return -1;
} else
}
else
out_int[L - i - 1] = buffer[i] - 0x30;
return 0;
@ -48,7 +49,8 @@ int add_numbers(uint8_t *a, uint8_t *b, uint8_t N)
{
carry = 1;
c[i] -= 10;
} else
}
else
carry = 0;
// printf("= %d, %d\n", carry, c[i]);
}
@ -63,7 +65,8 @@ int add_numbers(uint8_t *a, uint8_t *b, uint8_t N)
{
carry = 1;
c[i] -= 10;
} else
}
else
carry = 0;
// printf("= %d, %d\n", carry, c[i]);
}
@ -98,10 +101,12 @@ int print_number(uint8_t *number, uint8_t N, int8_t num_digits_to_print)
return 0;
}
#define N 10
#define N2 (N + 10)
int main(void)
{
const char N = 50, N2 = N+10; /* length of numbers */
// const char N = 50, N2 = N+10; /* length of numbers */
char txt_buffer[N + 5]; /* temporary buffer */
uint8_t number[N]; /* array to store digits of a large number */
uint8_t sum[N2]; /* array to store the sum of the large numbers. For
@ -118,7 +123,8 @@ int main(void)
int count = 0;
get_number(fp, txt_buffer, sum); /* 0 + = first_number = first_number */
do {
do
{
count++;
if (get_number(fp, txt_buffer, number) != 0)
break;

View File

@ -46,10 +46,11 @@ int main(int argc, char **argv)
*
* Automatically detects for OPENMP using the _OPENMP macro.
**/
long long i;
#ifdef _OPENMP
#pragma omp parallel for shared(max_len, max_len_num) schedule(guided)
#endif
for (long long i = 1; i < MAX_NUM; i++)
for (i = 1; i < MAX_NUM; i++)
{
long long L = collatz(i);
if (L > max_len)

View File

@ -52,12 +52,12 @@ int main(int argc, char **argv)
char *flags = (char *)calloc(MAX_N, sizeof(char));
clock_t start_time = clock();
unsigned int i;
#ifdef _OPENMP
#pragma omp for schedule(runtime)
#endif
/* there are no such numbers till 10. Lets search from there on */
for (unsigned int i = 10; i < MAX_N; i++)
for (i = 10; i < MAX_N; i++)
{
if (flags[i] != 0)
/* already processed, skip */

View File

@ -110,14 +110,16 @@ int main(int argc, char **argv)
long sum_score = 0;
clock_t start_time = clock();
unsigned int i;
#ifdef _OPENMP
#pragma omp parallel for schedule(runtime) reduction(+ \
: sum_score)
#endif
#ifdef DEBUG
for (unsigned int i = 935; i < 940; i++)
for (i = 935; i < 940; i++)
#else
for (unsigned int i = 0; i < COUNT; i++)
for (i = 0; i < COUNT; i++)
#endif
{
unsigned int score = 0;

View File

@ -92,12 +92,13 @@ int main(int argc, char **argv)
#endif
double total_duration = 0;
unsigned long i;
function_timer *timer = new_timer();
#ifdef _OPENMP
#pragma omp parallel for reduction(+ \
: sum) schedule(runtime)
#endif
for (unsigned long i = 1; i <= MAX_N; i++)
for (i = 1; i <= MAX_N; i++)
{
start_timer(timer);
if (!is_sum_of_abundant(i))

View File

@ -120,10 +120,11 @@ int main(int argc, char **argv)
clock_t start_time = clock();
/* Loop to set abundant flags */
unsigned long N;
#ifdef _OPENMP
#pragma omp for schedule(runtime)
#endif
for (unsigned long N = 1; N <= MAX_N; N++)
for (N = 1; N <= MAX_N; N++)
{
char ret = get_perfect_number(N);
if (ret == 1)

View File

@ -19,10 +19,11 @@ int main(int argc, char *argv[])
unsigned short max_digits = 0, max_idx_number = 0;
clock_t start_time = clock();
unsigned short deno;
#ifdef _OPENMP
#pragma omp for
#endif
for (unsigned short deno = 2; deno < MAX_DENO; deno++)
for (deno = 2; deno < MAX_DENO; deno++)
{
unsigned short remainders[MAX_LEN];
unsigned short rem = 1, *rem_ptr = remainders;