/** Create an EventWorkspace containing fake data * of single-crystal diffraction. * Instrument is MINITOPAZ * * @return EventWorkspace_sptr */ EventWorkspace_sptr createDiffractionEventWorkspace(int numEvents, int numPixels, int numBins) { double binDelta = 10.0; auto retVal = boost::make_shared<EventWorkspace>(); retVal->initialize(numPixels, 1, 1); // --------- Load the instrument ----------- const std::string filename = FileFinder::Instance().getFullPath( "IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml"); InstrumentDefinitionParser parser(filename, "MINITOPAZ", Strings::loadFile(filename)); auto instrument = parser.parseXML(nullptr); retVal->populateInstrumentParameters(); retVal->setInstrument(instrument); DateAndTime run_start("2010-01-01T00:00:00"); for (int pix = 0; pix < numPixels; pix++) { for (int i = 0; i < numEvents; i++) { retVal->getSpectrum(pix) += Mantid::DataObjects::TofEvent( (i + 0.5) * binDelta, run_start + double(i)); } retVal->getSpectrum(pix).addDetectorID(pix); } // Create the x-axis for histogramming. HistogramData::BinEdges x1(numBins); auto &xRef = x1.mutableData(); for (int i = 0; i < numBins; ++i) { xRef[i] = i * binDelta; } // Set all the histograms at once. retVal->setAllX(x1); // Default unit: TOF. retVal->getAxis(0)->setUnit("TOF"); // Give it a crystal and goniometer WorkspaceCreationHelper::setGoniometer(retVal, 0., 0., 0.); WorkspaceCreationHelper::setOrientedLattice(retVal, 1., 1., 1.); // Some sanity checks if (retVal->getInstrument()->getName() != "MINITOPAZ") throw std::runtime_error("MDEventsTestHelper::" "createDiffractionEventWorkspace(): Wrong " "instrument loaded."); Mantid::detid2det_map dets; retVal->getInstrument()->getDetectors(dets); if (dets.size() != 100 * 100) throw std::runtime_error("MDEventsTestHelper::" "createDiffractionEventWorkspace(): Wrong " "instrument size."); return retVal; }
/** Create event workspace */ EventWorkspace_sptr CreateSampleWorkspace::createEventWorkspace( int numPixels, int numBins, int numEvents, double x0, double binDelta, int start_at_pixelID, Geometry::Instrument_sptr inst, const std::string &functionString, bool isRandom) { DateAndTime run_start("2010-01-01T00:00:00"); // add one to the number of bins as this is histogram int numXBins = numBins + 1; EventWorkspace_sptr retVal(new EventWorkspace); retVal->initialize(numPixels, 1, 1); retVal->setInstrument(inst); // Create the x-axis for histogramming. MantidVecPtr x1; MantidVec &xRef = x1.access(); xRef.resize(numXBins); for (int i = 0; i < numXBins; ++i) { xRef[i] = x0 + i * binDelta; } // Set all the histograms at once. retVal->setAllX(x1); std::vector<double> xValues(xRef.begin(), xRef.end() - 1); std::vector<double> yValues = evalFunction(functionString, xValues, isRandom ? 1 : 0); // we need to normalise the results and then multiply by the number of events // to find the events per bin double sum_of_elems = std::accumulate(yValues.begin(), yValues.end(), 0.0); double event_distrib_factor = numEvents / sum_of_elems; std::transform(yValues.begin(), yValues.end(), yValues.begin(), std::bind1st(std::multiplies<double>(), event_distrib_factor)); // the array should now contain the number of events required per bin // Make fake events size_t workspaceIndex = 0; const double hourInSeconds = 60 * 60; for (int wi = 0; wi < numPixels; wi++) { EventList &el = retVal->getEventList(workspaceIndex); el.setSpectrumNo(wi + 1); el.setDetectorID(wi + start_at_pixelID); // for each bin for (int i = 0; i < numBins; ++i) { // create randomised events within the bin to match the number required - // calculated in yValues earlier int eventsInBin = static_cast<int>(yValues[i]); for (int q = 0; q < eventsInBin; q++) { DateAndTime pulseTime = run_start + (m_randGen->nextValue() * hourInSeconds); el += TofEvent((i + m_randGen->nextValue()) * binDelta, pulseTime); } } workspaceIndex++; } return retVal; }
// Main entry point, distinct from the External entry point. Intended to by // called from python with ctypes (but can also, of course, be called from c) void setup(int num_devices_requested, int* devices_to_use, float dt, int num_items, int dimension, int** index_vectors, int** stored_vectors, float tau, float* decoders, int neurons_per_item, float* gain, float* bias, float tau_ref, float tau_rc, float radius, int identical_ensembles, int print_data, int* probe_indices, int num_probes, int do_spikes, int num_steps) { int i, j, k; int num_available_devices = getGPUDeviceCount(); do_print = print_data; printf("NeuralAssocGPU: SETUP\n"); num_devices = num_devices_requested > num_available_devices ? num_available_devices : num_devices_requested; if(do_print) printf("Using %d devices. %d available\n", num_devices, num_available_devices); nengo_data_array = (NengoGPUData**) malloc(sizeof(NengoGPUData*) * num_devices); NengoGPUData* current_data; // Create the NengoGPUData structs, one per device. for(i = 0; i < num_devices; i++) { nengo_data_array[i] = getNewNengoGPUData(); } if(do_print) printf("About to create the NengoGPUData structures\n"); int items_per_device = num_items / num_devices; int leftover = num_items % num_devices; int item_index = 0; int items_for_current_device = 0; int probe_count = 0; // Now we start to load the data into the NengoGPUData struct for each device. // (though the data doesn't get put on the actual device just yet). // Because of the CUDA architecture, we have to do some weird things to get a good speedup // These arrays that store the transforms, decoders, are setup in a non-intuitive way so // that memory accesses can be parallelized in CUDA kernels. For more information, see // the NengoGPU user manual. for(i = 0; i < num_devices; i++) { // set values current_data = nengo_data_array[i]; current_data->device = devices_to_use[i]; current_data->do_print = do_print; current_data->neurons_per_item = neurons_per_item; current_data->dimension = dimension; current_data->tau = tau; current_data->tau_ref = tau_ref; current_data->tau_rc = tau_rc; current_data->radius = radius; current_data->dt = dt; current_data->num_steps = num_steps; printf("Num STEPS: %d\n", num_steps); items_for_current_device = items_per_device + (leftover > 0 ? 1 : 0); leftover--; current_data->num_items = items_for_current_device; current_data->identical_ensembles = identical_ensembles; // find the number of probes on current device probe_count = 0; for(j = 0; j < num_probes; j++) { if(probe_indices[j] >= item_index && probe_indices[j] < item_index + items_for_current_device) { probe_count++; } } current_data->num_probes = probe_count; if(do_spikes) { current_data->num_spikes = probe_count * neurons_per_item; } // create the arrays initializeNengoGPUData(current_data); // populate the arrays for(j = 0; j < items_for_current_device; j++) { memcpy(current_data->index_vectors->array + j * dimension, index_vectors[item_index + j], dimension * sizeof(float)); memcpy(current_data->stored_vectors->array + j * dimension, stored_vectors[item_index + j], dimension * sizeof(float)); } memcpy(current_data->decoders->array, decoders, neurons_per_item * sizeof(float)); memcpy(current_data->gain->array, gain, neurons_per_item * sizeof(float)); memcpy(current_data->bias->array, bias, neurons_per_item * sizeof(float)); // populate the probe map probe_count = 0; for(j = 0; j < num_probes; j++) { if(probe_indices[j] >= item_index && probe_indices[j] < item_index + items_for_current_device) { current_data->probe_map->array[probe_count] = probe_indices[j] - item_index; if(do_spikes) { for(k = 0; k < neurons_per_item; k++) { current_data->spike_map->array[probe_count * neurons_per_item + k] = (probe_indices[j] - item_index) * neurons_per_item + k; } } probe_count++; } } item_index += items_for_current_device; //printf("printing nengo gpu data\n"); //printNengoGPUData(current_data, 1); } // We have all the data we need, now start the worker threads which control // the GPU's directly. run_start(); }
int main(int argc,char *argv[]){ if(argc != 3){ std::cout << "Usage: " << argv[0] << " [input file] [output file]" << std::endl; exit(1); } std::cout << "This is the LiSA open shop branch and bound module." << std::endl; std::cout << "PID= " << getpid() << std::endl; G_ExceptionList.set_output_to_cout(); struct BranchList *DeleteBranch; Initialize(); Read_Data(argv[1]); run_start(); if ( Compute_Head_Tail() ){ Heuristic_Schedule(); if ((SonNode->lower_bound = Additional_Arcs()) < UpperBound){ Compute_Blocks(); Compute_BranchList(); ActualNode = SonNode; Push(); if ( (SonNode = new struct NodeType) == NIL ) { G_ExceptionList.lthrow("main,SonNode: kein Speicherplatz", Lisa_ExceptionList::NO_MORE_MEMORY); exit(1); } SonNode->blocks = NIL; SonNode->order = NIL; } } while (FirstOfStack != NIL && !abort_algorithm){ Pop(); Update_Arcs(); while (ActualNode->order != NIL && ActualNode->lower_bound < UpperBound){ Fix_Arcs(ActualNode->order->branch_op, ActualNode->order->before_or_after, ActualNode->order->kind_of_block); DeleteBranch = ActualNode->order; ActualNode->order = ActualNode->order->next; delete DeleteBranch; if ( Compute_Head_Tail() && Compute_LowerBound() < UpperBound && (SonNode->lower_bound = Additional_Arcs()) < UpperBound){ Heuristic_Schedule(); if ( SonNode->lower_bound < UpperBound ){ Compute_Blocks(); Compute_BranchList(); SearchTreeNodes++; Push(); ActualNode = SonNode; if ( (SonNode = new struct NodeType)== NIL ){ G_ExceptionList.lthrow("main,SonNode: kein Speicherplatz", Lisa_ExceptionList::NO_MORE_MEMORY); exit(1); } SonNode->blocks = NIL; SonNode->order = NIL; }else{ Update_Arcs(); } }else{ Update_Arcs(); } } } run_stop(); Write_Solution(argv[2]); return(0); }
/** Create an EventWorkspace containing fake data * of single-crystal diffraction. * Instrument is MINITOPAZ * * @return EventWorkspace_sptr */ EventWorkspace_sptr createDiffractionEventWorkspace(int numEvents) { FacilityHelper::ScopedFacilities loadTESTFacility("IDFs_for_UNIT_TESTING/UnitTestFacilities.xml", "TEST"); int numPixels = 10000; int numBins = 1600; double binDelta = 10.0; EventWorkspace_sptr retVal(new EventWorkspace); retVal->initialize(numPixels,1,1); // --------- Load the instrument ----------- LoadInstrument * loadInst = new LoadInstrument(); loadInst->initialize(); loadInst->setPropertyValue("Filename", "IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml"); loadInst->setProperty<Mantid::API::MatrixWorkspace_sptr> ("Workspace", retVal); loadInst->execute(); delete loadInst; // Populate the instrument parameters in this workspace - this works around a bug retVal->populateInstrumentParameters(); DateAndTime run_start("2010-01-01T00:00:00"); for (int pix = 0; pix < numPixels; pix++) { for (int i=0; i<numEvents; i++) { retVal->getEventList(pix) += Mantid::DataObjects::TofEvent((i+0.5)*binDelta, run_start+double(i)); } retVal->getEventList(pix).addDetectorID(pix); } //Create the x-axis for histogramming. Mantid::MantidVecPtr x1; Mantid::MantidVec& xRef = x1.access(); xRef.resize(numBins); for (int i = 0; i < numBins; ++i) { xRef[i] = i*binDelta; } //Set all the histograms at once. retVal->setAllX(x1); // Default unit: TOF. retVal->getAxis(0)->setUnit("TOF"); // Give it a crystal and goniometer WorkspaceCreationHelper::SetGoniometer(retVal, 0., 0., 0.); WorkspaceCreationHelper::SetOrientedLattice(retVal, 1., 1., 1.); // Some sanity checks if (retVal->getInstrument()->getName() != "MINITOPAZ") throw std::runtime_error("MDEventsTestHelper::createDiffractionEventWorkspace(): Wrong instrument loaded."); Mantid::detid2det_map dets; retVal->getInstrument()->getDetectors(dets); if ( dets.size() != 100*100) throw std::runtime_error("MDEventsTestHelper::createDiffractionEventWorkspace(): Wrong instrument size."); return retVal; }