| 84 | /////////////////////////////////////////////////////////////////////////////// |
| 85 | |
| 86 | extern "C" OSPError ospInit(int *_ac, const char **_av) OSPRAY_CATCH_BEGIN |
| 87 | { |
| 88 | auto ¤tDevice = Device::current; |
| 89 | |
| 90 | if (currentDevice) { |
| 91 | throw std::runtime_error("device already exists [ospInit() called twice?]"); |
| 92 | } |
| 93 | |
| 94 | loadModulesFromEnvironmentVar(); |
| 95 | |
| 96 | if (_ac && _av) { |
| 97 | for (int i = 1; i < *_ac;) { |
| 98 | std::string av(_av[i]); |
| 99 | |
| 100 | if (rkcommon::utility::beginsWith(av, "--osp:load-modules")) { |
| 101 | std::string modules = getArgString(av); |
| 102 | if (modules == "") { |
| 103 | throw std::runtime_error( |
| 104 | "Invalid module name(s) provided to --osp:load-modules. Must be " |
| 105 | "formatted as <module1>[,<module2>,...]"); |
| 106 | } |
| 107 | std::vector<std::string> moduleList = |
| 108 | rkcommon::utility::split(modules, ','); |
| 109 | for (std::string &moduleName : moduleList) { |
| 110 | loadLocalModule(moduleName); |
| 111 | } |
| 112 | removeArgs(*_ac, _av, i, 1); |
| 113 | } else if (rkcommon::utility::beginsWith(av, "--osp:device=")) { |
| 114 | // ALOK: explicitly checking with the equals sign so this does not get |
| 115 | // clobbered by --osp:device-param |
| 116 | std::string deviceName = getArgString(av); |
| 117 | try { |
| 118 | currentDevice = Device::createDevice(deviceName.c_str()); |
| 119 | } catch (const std::runtime_error &) { |
| 120 | throw std::runtime_error("Failed to create device of type '" + |
| 121 | deviceName + |
| 122 | "'! Perhaps you spelled the " |
| 123 | "device name wrong or didn't link the " |
| 124 | "library which defines the device?"); |
| 125 | } |
| 126 | removeArgs(*_ac, _av, i, 1); |
| 127 | } else { |
| 128 | // Ignore other arguments |
| 129 | ++i; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // no device created on cmd line, yet, so default to ISPCDevice |
| 135 | if (!deviceIsSet()) { |
| 136 | auto OSPRAY_DEVICE = utility::getEnvVar<std::string>("OSPRAY_DEVICE"); |
| 137 | |
| 138 | if (OSPRAY_DEVICE) { |
| 139 | const auto &device_name = OSPRAY_DEVICE.value(); |
| 140 | currentDevice = Device::createDevice(device_name.c_str()); |
| 141 | } else { |
| 142 | ospLoadModule("cpu"); |
| 143 | currentDevice = Device::createDevice("cpu"); |