-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFFTDScriptAssistant.cpp
More file actions
375 lines (304 loc) · 11.3 KB
/
FFTDScriptAssistant.cpp
File metadata and controls
375 lines (304 loc) · 11.3 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#include "/import/home/u1/uaf/amoore/Working/Headers/standardIncludes.h"
#include "/import/home/u1/uaf/amoore/Working/Headers/sanityChecks.h"
//#include <signal.h> //Will be used to catch the signal interrupt in order to kill the while loop in fftTransform
/* To Do list
1. Get the signal handling to work so it doesn't go into an infinite loop anymore.
2. Implement user specification of script locations
3. Design a GUI interface to wrap it in (OpenGL, OSG or QT4)
*/
using namespace std;
void oneDimensionalTransform(int[],stringstream[]); // Will be called if you are performing one dimensional Fourier Transforms
void twoDimensionalTransform(int[],stringstream[]); // Will be called if you are performing two dimensional Fourier Transforms
void fftTransform(int); // This function will perform the majority of the work with preparing the command line.
void instructions(); // Will display instructions about what the program is asking for.
void mainMenu(); //This will display a menu containing the user options associated with the script.
void testFunction();
/**************************************************Flags for the Sanity Check **************************************************************/
#define MAIN_MENU 0
#define FFT_1D 1
#define FFT_2D 2
int main() // Starts up the main menu
{
system("clear");
mainMenu();
return 0;
}
void mainMenu () // Displays the main menu and lets the user decide what to do
{
string tempChoice = "/0"; // Temporarily holds choice to prevent ugly crashes.
string fftPath = "/0"; // Will hold the user specified path for the FFT program.
int choice = 0; // Used for the real choice.
int sanity = 0;
while (choice != 4) // This will be the main menu loop
{
cout << setw(56) << "Fast Fourier Transform Assistant" << endl << endl;
cout << "\t1. One dimensional Fast Fourier transforms." << endl;
cout << "\t2. Two dimensional Fast Fourier transforms." << endl;
cout << "\t3. Instructions" << endl;
cout << "\t4. Quit" << endl;
cout << "\tPlease make a choice (1 - 4): ";
cout << "\n\t5. Test Function" << endl; //Sample function made for testing.
cin >> tempChoice;
choice = atoi(tempChoice.c_str());
switch (choice)
{
case 1: // One dimensional transform
{
system("clear");
cout << "Please enter the path for the one dimensional Fourier Transform code: ";
cin >> fftPath;
sanity = fftSanityCheck(MAIN_MENU,choice,fftPath); //Make sure the program exists in the specified directory
if (sanity == 0) // Everything is cool, no insanity here.
{
fftTransform(choice);
}
}
case 2: // Two dimensional transform
{
system("clear");
cout << "Please enter the path for the two dimensional Fourier Transform code: ";
cin >> fftPath;
sanity = fftSanityCheck(MAIN_MENU,choice,fftPath); // Make sure the program exists in the specified directory
if (sanity == 0) // Everything is cool, no insanity here.
{
fftTransform(choice);
}
break;
}
case 3: // Call up the instructions
{
system("clear");
instructions();
break;
}
case 4: //Quit
{
system("clear");
cout << "Thank you for using this assistant. Have a nice day." << endl << endl;
break;
}
case 5: //Test Function
{
cout << "Please enter the path to the HelloWorld program: ";
cin >> fftPath;
sanity = fftSanityCheck(MAIN_MENU,choice,fftPath);
if (sanity == 0)
system("./HelloWorld >& test.txt");
break;
}
default: //Invalid choice, display error message.
cout << "\nThat is not a valid option, please make a choice 1 - 4." << endl << endl;
cout << "Press Enter to continue.";
cin.ignore();
cin.get();
system("clear");
break;
}
}
return;
}
void instructions () //Function Displays instructions about how to use the program.
{
// General instructions
cout << "\n\nBefore using this application, be sure that the executable is in the same\n"
<< "directory as the scripts you are trying to run, or an error will occur." << endl << endl;
//Instructions for the one dimensional Fourier Transforms
cout << "\tThe following is an example of the input format: " << endl << endl
<< "\t\tOne Dimensional Fourier Transforms: \n\n\n"
<< "\t\t\t ./FFT1D_sample c2c X1 X2 X3 X4 \n\n"
<< "\t\t\tWhere:\n\t\t\t\t-c2c is the FFT_Type (not neccasarily c2c)\n\t\t\t\t-X1 is the number of FFT's\n"
<< "\t\t\t\t-X2 is the number of SPU's to use\n\t\t\t\t-X3 is the size of the FFT's\n"
<< "\t\t\t\t-X4 is the hugepage_flag." << endl << endl << endl;
//Instructions for the two dimensional Fourier Transforms.
cout << "\t\tTwo Dimensional >&Fourier Transforms: \n\n\n"
<< "\t\t\t ./FFT2D_sample X1 X2 X3 X4 X5 X6 X7 X8 X9 \n\n"
<< "\t\t\tWhere:\n\t\t\t\t-X1 is the tile_flag\n\t\t\t\t-X2 is the "
<< "inplace_flag\n\t\t\t\t-X3 is the log_size_x\n\t\t\t\t-X4"
<< " is the log_size_y\n\t\t\t\t-X5 is ncycles, how many cycles"
<< " you wish to run\n\t\t\t\t-X6 is the log2_nspus, the number"
<< " of SPU's as a log base 2, options are 3 or 4 \n\t\t\t\t"
<< "-X7 is the numa_flag\n\t\t\t\t-X8 is the largepage_flag"
<< endl << endl;
cout << "Press Enter to continue.";
cin.ignore();
cin.get();
system("clear");
return;
}
void fftTransform (int choice) // Sets up the command that will start the tests.
{
string charParameter; // Will hold the character parameter (such as 'c2c')
string command; // This string will contain the command line.
string outputFilePrefix, outFileName; // These will hold the prefix and the output file name.
string timeStamp; // This will let us add a time stamp to the output file.
string systemMessage;
std::stringstream convert[8]; // Array for converting the integers array into strings for use in the command line.
//char exit; // Will allow you to nicely exit if the FFTD script is not in the proper directory.
int numericVariables[8]; // Holds the numeric parameters of the FFT.
system("clear");
timeStamp = "date 1>> ";
cout << "Please enter today's date (no /'s or \'s please!): ";
cin >> outputFilePrefix;
switch (choice)
{
case 1:
{
cout << "Please enter the type of Fourier Transform to be performed (i.e. c2c): ";
cin >> charParameter;
oneDimensionalTransform(numericVariables,convert); // Set up the parameters for the one dimensional FFT
outFileName = "FFT1D-" + outputFilePrefix; // The name of the file that will be storing the output.
timeStamp += outFileName + ".txt && ";
command += timeStamp + "./FFT1D_sample " + charParameter + " ";
for (int i = 0; i < 4; i++) // Add numeric parameters to the command line.
command += convert[i].str() + " ";
break;
}
case 2:
{
twoDimensionalTransform(numericVariables,convert); // Set up the parameters for the two dimensional FFT
outFileName = "FFT2D-" + outputFilePrefix; // The name of the file that will be storing the output.
timeStamp += outFileName + ".txt && ";
command += timeStamp + "./FFT2D_sample " + charParameter + " ";
for (int i = 0; i < 8; i++) // Add numeric parameters to the command line.
command += convert[i].str() + " ";
break;
}
}
command += " 2>> " + outFileName + ".txt"; // This will cause the output to be put in the file you have specified.
/**********************************************************Start of file Header ****************************************************************/
systemMessage = "printf 'This run began on ' 1>> " + outFileName + ".txt";
system(systemMessage.c_str());
systemMessage = "date 1>>" + outFileName + ".txt && printf 'Using the command:\n\n' 1>> " + outFileName + ".txt && printf '\n\n'";
system(systemMessage.c_str());
systemMessage = "printf '" + command + "\n\n' 1>> " + outFileName + ".txt";
system(systemMessage.c_str());
systemMessage = "printf 'BEGIN'";
system(systemMessage.c_str());
/*********************************************************************************************************************************************/
system("clear");
// cout << "The current command is:\n\n\t" << command << endl << endl << endl; //Check to make sure the command was assembled correctly.
while (true) // Run the command in a loop until the program is killed manually (going to fix this eventually)
{
//cout << "Is looping" << endl; //Test to make sure we're in the loop.
system(command.c_str()); //Send the command as a system call.
sleep(1); //Pause one second between loops.
}
/****************************************************************End of file Header ******************************************************************/
systemMessage = "printf 'End Time:' 1>> " + outFileName + ".txt";
system(systemMessage.c_str());
systemMessage = "date 1>> " + outFileName + ".txt";
system(systemMessage.c_str());
systemMessage = "printf 'END'";
system(systemMessage.c_str());
/******************************************************************************************************************************************************/
return;
}
void oneDimensionalTransform(int number[], stringstream conv[]) // Gets the parameters for a one dimensional Fourier Transform.
{
int temp = 0;
int valid = 0;
for (int i = 0; i < 4; i++) //Loop will get all of the numeric parameters from the user (instead of using a bunch of cout-cin pairs).
{
valid = 0;
while (valid == 0)
{
cout << "Please enter the ";
switch (i) // Switch on i to get the parameters for the script
{
case 0:
{
cout << "number of FFT's: ";
break;
}
case 1:
{
cout << "SPU's to use: ";
break;
}
case 2:
{
cout << "size of the FFT's: ";
break;
}
case 3:
{
cout <<"hugepage_flag: ";
break;
}
default:
{
cout << "ERROR! Loop index out of range!";
break;
}
}
valid = fftSanityCheck(FFT_1D,0,""); //Check to make sure the input is an integer.
}
number[i] = valid;
conv[i] << number[i]; //Convert all of the integer parameters into string streams.
}
return;
}
void twoDimensionalTransform (int number[], stringstream conv[]) //Gets the parameters for a two dimensional Fourier Transform.
{
int valid = 0;
for (int i = 0; i < 8; i++) //Loop will get all of the numeric parameters from the user (instead of using a bunch of cout-cin pairs).
{
valid = 0;
while (valid == 0)
{
cout << "Please enter the ";
switch (i) //Switch on i to get the parameters for the script
{
case 0:
{
cout << "tile_flag: ";
break;
}
case 1:
{
cout << "inplace_flag: ";
break;
}
case 2:
{
cout << "log_size_x: ";
break;
}
case 3:
{
cout << "log_size_y: ";
break;
}
case 4:
{
cout << "ncycles: ";
break;
}
case 5:
{
cout << "log2_nspus: ";
break;
}
case 6:
{
cout << "numa_flag: ";
break;
}
case 7:
{
cout << "largepage_flag: ";
break;
}
default:
{
cout << "ERROR! Loop index out of range!";
break;
}
}
valid = fftSanityCheck(FFT_2D,0,""); //Check to make sure the input is an integer.
}
number[i] = valid;
conv[i] << number[i]; //Convert all of the integer parameters into string streams, convert them to strings and add them to the command variable.
}
return;
}