[35] | 1 | #include "NBody.hpp" |
---|
| 2 | |
---|
| 3 | /////////////////////////////////// NBody::cleanup Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
---|
| 4 | // |
---|
| 5 | // Releases OpenCL resources (Context, Memory etc.) |
---|
| 6 | // |
---|
| 7 | /////////////////////////////////// NBody::cleanup Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
---|
| 8 | |
---|
| 9 | int NBody::cleanup() |
---|
| 10 | { |
---|
| 11 | //================================================ |
---|
| 12 | // Resources common to all integrators: |
---|
| 13 | |
---|
| 14 | /* Releases OpenCL resources (Context, Memory etc.) */ |
---|
| 15 | cl_int status; |
---|
| 16 | |
---|
| 17 | status = clReleaseKernel(kernel); |
---|
| 18 | if (status != CL_SUCCESS){ |
---|
| 19 | std::cout << "clReleaseKernel failed." << std::endl; |
---|
| 20 | return 1; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | status = clReleaseProgram(program); |
---|
| 24 | if (status != CL_SUCCESS){ |
---|
| 25 | std::cout << "clReleaseProgram failed." << std::endl; |
---|
| 26 | return 1; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | status = clReleaseMemObject(updatedPos); |
---|
| 30 | if (status != CL_SUCCESS){ |
---|
| 31 | std::cout << "clReleaseMemObject failed." << std::endl; |
---|
| 32 | return 1; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | status = clReleaseMemObject(updatedVel); |
---|
| 36 | if (status != CL_SUCCESS){ |
---|
| 37 | std::cout << "clReleaseMemObject failed." << std::endl; |
---|
| 38 | return 1; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | status = clReleaseCommandQueue(commandQueue); |
---|
| 42 | if (status != CL_SUCCESS){ |
---|
| 43 | std::cout << "clReleaseMemObject failed." << std::endl; |
---|
| 44 | return 1; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | status = clReleaseContext(context); |
---|
| 48 | if (status != CL_SUCCESS){ |
---|
| 49 | std::cout << "clReleaseMemObject failed." << std::endl; |
---|
| 50 | return 1; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | //================================================ |
---|
| 54 | // Resources specific only for Leapfrog integrator: |
---|
| 55 | |
---|
| 56 | status = clReleaseMemObject(updatedAcc); |
---|
| 57 | if (status != CL_SUCCESS){ |
---|
| 58 | std::cout << "clReleaseMemObject failed." << std::endl; |
---|
| 59 | return 1; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | return 0; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /////////////////////////////////// NBody::~NBody() \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
---|
| 66 | // |
---|
| 67 | // Override the constructor of the NBody class, releasing |
---|
| 68 | // unreleased resources |
---|
| 69 | // |
---|
| 70 | /////////////////////////////////// NBody::~NBody() \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
---|
| 71 | |
---|
| 72 | NBody::~NBody() |
---|
| 73 | { |
---|
| 74 | //================================================ |
---|
| 75 | // Resources common to all integrators: |
---|
| 76 | |
---|
| 77 | /* release program resources */ |
---|
| 78 | if(initPos) |
---|
| 79 | { |
---|
| 80 | free(initPos); |
---|
| 81 | initPos = NULL; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | if(initVel) |
---|
| 85 | { |
---|
| 86 | free(initVel); |
---|
| 87 | initVel = NULL; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | if(pos) |
---|
| 91 | { |
---|
| 92 | #if defined (_WIN32) |
---|
| 93 | _aligned_free(pos); |
---|
| 94 | #else |
---|
| 95 | free(pos); |
---|
| 96 | #endif |
---|
| 97 | pos = NULL; |
---|
| 98 | } |
---|
| 99 | if(vel) |
---|
| 100 | { |
---|
| 101 | #if defined (_WIN32) |
---|
| 102 | _aligned_free(vel); |
---|
| 103 | #else |
---|
| 104 | free(vel); |
---|
| 105 | #endif |
---|
| 106 | vel = NULL; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | if(devices) |
---|
| 110 | { |
---|
| 111 | free(devices); |
---|
| 112 | devices = NULL; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | if(maxWorkItemSizes) |
---|
| 116 | { |
---|
| 117 | free(maxWorkItemSizes); |
---|
| 118 | maxWorkItemSizes = NULL; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | //================================================ |
---|
| 122 | // Resources specific only for Leapfrog integrator: |
---|
| 123 | |
---|
| 124 | if(acc) |
---|
| 125 | { |
---|
| 126 | #if defined (_WIN32) |
---|
| 127 | _aligned_free(acc); |
---|
| 128 | #else |
---|
| 129 | free(acc); |
---|
| 130 | #endif |
---|
| 131 | acc = NULL; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | } |
---|
| 135 | |
---|