MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / main

Function main

cpp/5_Domain_Specific/binomialOptions/binomialOptions.cpp:74–189  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// Main program ///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

72// Main program
73////////////////////////////////////////////////////////////////////////////////
74int main(int argc, char **argv)
75{
76 printf("[%s] - Starting...\n", argv[0]);
77
78 int devID = findCudaDevice(argc, (const char **)argv);
79
80 const int OPT_N = MAX_OPTIONS;
81
82 TOptionData optionData[MAX_OPTIONS];
83 real callValueBS[MAX_OPTIONS], callValueGPU[MAX_OPTIONS], callValueCPU[MAX_OPTIONS];
84
85 real sumDelta, sumRef, gpuTime, errorVal;
86
87 StopWatchInterface *hTimer = NULL;
88 int i;
89
90 sdkCreateTimer(&hTimer);
91
92 printf("Generating input data...\n");
93 // Generate options set
94 srand(123);
95
96 for (i = 0; i < OPT_N; i++) {
97 optionData[i].S = randData(5.0f, 30.0f);
98 optionData[i].X = randData(1.0f, 100.0f);
99 optionData[i].T = randData(0.25f, 10.0f);
100 optionData[i].R = 0.06f;
101 optionData[i].V = 0.10f;
102 BlackScholesCall(callValueBS[i], optionData[i]);
103 }
104
105 printf("Running GPU binomial tree...\n");
106 checkCudaErrors(cudaDeviceSynchronize());
107 sdkResetTimer(&hTimer);
108 sdkStartTimer(&hTimer);
109
110 binomialOptionsGPU(callValueGPU, optionData, OPT_N);
111
112 checkCudaErrors(cudaDeviceSynchronize());
113 sdkStopTimer(&hTimer);
114 gpuTime = sdkGetTimerValue(&hTimer);
115 printf("Options count : %i \n", OPT_N);
116 printf("Time steps : %i \n", NUM_STEPS);
117 printf("binomialOptionsGPU() time: %f msec\n", gpuTime);
118 printf("Options per second : %f \n", OPT_N / (gpuTime * 0.001));
119
120 printf("Running CPU binomial tree...\n");
121
122 for (i = 0; i < OPT_N; i++) {
123 binomialOptionsCPU(callValueCPU[i], optionData[i]);
124 }
125
126 printf("Comparing the results...\n");
127 sumDelta = 0;
128 sumRef = 0;
129 printf("GPU binomial vs. Black-Scholes\n");
130
131 for (i = 0; i < OPT_N; i++) {

Callers

nothing calls this directly

Calls 12

findCudaDeviceFunction · 0.85
sdkCreateTimerFunction · 0.85
sdkResetTimerFunction · 0.85
sdkStartTimerFunction · 0.85
binomialOptionsGPUFunction · 0.85
sdkStopTimerFunction · 0.85
sdkGetTimerValueFunction · 0.85
fabsFunction · 0.85
sdkDeleteTimerFunction · 0.85
randDataFunction · 0.70
BlackScholesCallFunction · 0.70
binomialOptionsCPUFunction · 0.70

Tested by

no test coverage detected