-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.h
150 lines (126 loc) · 3.27 KB
/
settings.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef SETTINGS_H
#define SETTINGS_H
#include <iostream>
#include <time.h>
#include <math.h>
#include <mpi.h>
#include "allegro5/allegro.h"
#include "allegro5/allegro_primitives.h"
#include "allegro5/allegro_image.h"
#include <fstream>
#include <ios>
#define LIMITE 10
#define DEBUG 0
#define MASTER 0
#define WINDOWSIZE 600
// Grafica
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_COLOR color = al_map_rgb(255, 0, 0);
const int scala = WINDOWSIZE / 2;
bool showGraphic = false;
// Output
const char *nomeFile = "Timing.txt";
const char *inputFile = "input.txt";
int numeriDaStampare = 10;
// Variabili MPI
double timer_start, timer_end;
int process_rank, num_processes;
int *globalArray = NULL;
int size, arraySize, defaultSize = 100;
void printTime()
{
printf("Eseguito con %d processori, dimensione array pari a %d, tempo impiegato: %f secondi\n\n", num_processes, size, timer_end - timer_start);
}
std::string determineSort(int sortType)
{
std::string sortName = "Undefined";
switch (sortType)
{
case 1:
sortName = "Bitonic sort";
break;
case 2:
sortName = "Quick sort";
break;
case 3:
sortName = "Odd Even Transposition sort";
break;
default:
break;
}
return sortName;
}
void printInfo(int sortType, int *Print)
{
std::string sortName = determineSort(sortType);
printf("Visualizzo Array Ordinato (solo %d elementi per una verifica veloce del ", numeriDaStampare);
printf("%s)\n", sortName.c_str());
for (int i = 0; i < size; i++)
if ((i % (size / numeriDaStampare)) == 0)
printf("%d ", Print[i]);
printf("\n");
std::ofstream fout(nomeFile, std::ios::app);
fout << sortName << ": " << size << " " << num_processes << " " << (timer_end - timer_start) << std::endl;
fout.close();
}
void stampaArrayOrdinato(int *Print)
{
printf("Dimensione Array: %d\n", size);
printf("Numero Processori usati: %d\n", num_processes);
printf("Tempo (in sec): %f\n", timer_end - timer_start);
printf("Array Ordinato: ");
for (int i = 0; i < size; i++)
printf("%d ", Print[i]);
printf("\n");
}
void showGraphics(const int *local_A)
{
if (display == NULL)
return;
if (process_rank == MASTER)
{
al_clear_to_color(al_map_rgb(0, 0, 0));
int salto = 1;
int div = 1;
int filler = 2;
if (size > scala)
{
salto = (arraySize / scala) + 1;
div = size / scala;
}
else
filler = WINDOWSIZE / arraySize;
unsigned posizioneX = 0;
for (int i = 0; i < arraySize; i += salto)
{
int val = WINDOWSIZE - (local_A[i] / div);
al_draw_line(posizioneX, WINDOWSIZE, posizioneX, val, color, 1.0);
posizioneX += filler;
}
al_flip_display();
al_rest(0.2);
}
}
void scriviSuFile(int arr[])
{
std::ofstream fout(inputFile);
fout << size << std::endl;
for (int i = 0; i < size; i++)
fout << arr[i] << " ";
fout << "\n";
fout.close();
}
void leggiNumeriRandom(int *&a)
{
std::ifstream fin(inputFile);
fin >> size;
a = new int[size];
int x;
for (int i = 0; i < size; i++)
{
fin >> x;
a[i] = x;
}
fin.close();
}
#endif