source: proiecte/NBody/NBody 2.0/NBody_main.cpp @ 34

Last change on this file since 34 was 34, checked in by (none), 14 years ago

Iulian Milas: ultima versiune a NBody (17 dec 2009)

File size: 2.6 KB
Line 
1#include "NBody.hpp"
2
3//----------------------
4 extern int numBodies;                                 
5
6 void* me;                                                              // Pointing to NBody class;
7
8 FILE *snapshotsFile, *diagnosticsFile; // Represent the files that will retain the snapshots
9                                                                                // and diagnostics;
10 FILE *inputDataFile;                                   // Represents the file for inputData for paricles;
11
12//----------------------
13extern void startOpenGLSimulation(int argc, char * argv[]);
14
15
16/////////////////////////////////// MAIN Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
17//
18// Here starts the application
19//
20/////////////////////////////////// MAIN Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
21
22int main(int argc, char * argv[])
23{
24    NBody clNBody("OpenCL NBody");
25    me = &clNBody;
26       
27        //--------------------------------
28        // Open file for input data if this option is
29        // activated:
30        if (readInputData){
31                inputDataFile = fopen(inputDataFileName, "r");
32                if(inputDataFile == NULL)
33                {
34                        std::cout << "Error opening inputData file." << std::endl;
35                        return 1;
36                }
37        }
38
39        //--------------------------------
40        // Open files for output data:
41        snapshotsFile = fopen(snapshotFileName, "w");
42        if(snapshotsFile == NULL)
43        {
44                std::cout << "Error opening snapshots file." << std::endl;
45                return 1;
46        }
47
48        diagnosticsFile = fopen(diagnosticFileName, "w");
49        if(diagnosticsFile == NULL)
50        {
51                std::cout << "Error opening diagnostics file." << std::endl;
52                return 1;
53        }
54
55        //--------------------------------
56        // Initialize particles:
57        if(clNBody.setupNBody()!= 0){           // SDK_SUCCESS == 0;
58        return 1;
59        }
60
61        //--------------------------------
62        // Initialize OpenCL env:
63        if(clNBody.setupCL()!= 0){                      // SDK_SUCCESS == 0;
64        return 1;
65        }
66
67        //--------------------------------
68        // Build CL kernel program executable:
69        if(clNBody.setupCLProgram() != 0){      // SDK_SUCCESS == 0;
70        return 1;
71        }
72
73        //--------------------------------
74    // Create kernels and set arguments to Kernels:
75        if(clNBody.setupCLKernels()!= 0){       // SDK_SUCCESS == 0;
76                return 1;
77    }
78
79        //--------------------------------
80        // Start the simulation:
81        std::cout << std::endl;
82        std::cout << "============================" << std::endl;
83        std::cout << "Simulation started..." << std::endl;
84        std::cout << std::endl;
85
86        time ( &rawtime );
87        timeinfo = localtime ( &rawtime );
88        std::cout << "Start time and date: " << asctime (timeinfo) << std::endl;
89
90        startOpenGLSimulation(argc, argv);
91
92        //--------------------------------
93        // Clean memory allocation:
94        if(clNBody.cleanup() != 0){                     // SDK_SUCCESS == 0;
95                return 1;
96        }
97
98        fclose(snapshotsFile);
99        fclose(diagnosticsFile);
100
101        return 0;
102}
103
104
Note: See TracBrowser for help on using the repository browser.