void LU( int numBlocks) { printf("LU\n"); hpx::naming::id_type here = hpx::find_here(); vector<vector<block> > blockList; getBlockList(blockList, numBlocks); vector<vector<vector<shared_future<block> > > > dfArray(numBlocks); shared_future<block> *diag_block, *first_col; for(int i = 0; i < numBlocks; i++){ dfArray[i].resize(numBlocks); for(int j = 0; j < numBlocks; j++){ dfArray[i][j].resize(numBlocks, hpx::make_ready_future(block())); } } //first iteration through matrix, initialized vector of futures dfArray[0][0][0] = async( ProcessDiagonalBlock, blockList[0][0] ); diag_block = &dfArray[0][0][0]; for(int i = 1; i < numBlocks; i++) { dfArray[0][0][i] = dataflow( unwrapped( &ProcessBlockOnRow ), hpx::make_ready_future( blockList[0][i] ), *diag_block); } for(int i = 1; i < numBlocks; i++) { dfArray[0][i][0] = dataflow( unwrapped( &ProcessBlockOnColumn ), hpx::make_ready_future( blockList[i][0] ), *diag_block); first_col = &dfArray[0][i][0]; for(int j = 1; j < numBlocks; j++) { dfArray[0][i][j] = dataflow( unwrapped( &ProcessInnerBlock ), hpx::make_ready_future( blockList[i][j]), dfArray[0][0][j], *first_col ); } } //all calculation after initialization. Each iteration, //the number of tasks/blocks spawned is decreased. for(int i = 1; i < numBlocks; i++) { dfArray[i][i][i] = dataflow( unwrapped( &ProcessDiagonalBlock ), dfArray[i-1][i][i]); diag_block = &dfArray[i][i][i]; for(int j = i + 1; j < numBlocks; j++){ dfArray[i][i][j] = dataflow( unwrapped(&ProcessBlockOnRow), dfArray[i-1][i][j], *diag_block); } for(int j = i + 1; j < numBlocks; j++){ dfArray[i][j][i] = dataflow( unwrapped( &ProcessBlockOnColumn ), dfArray[i-1][j][i], *diag_block); first_col = &dfArray[i][j][i]; for(int k = i + 1; k < numBlocks; k++) { dfArray[i][j][k] = dataflow( unwrapped( &ProcessInnerBlock ), dfArray[i-1][j][k], dfArray[i][i][k], *first_col ); } } } wait_all(dfArray[numBlocks-1][numBlocks-1][numBlocks-1]); }
void InitMatrix3() { vector<shared_future<void> > futures; futures.reserve(size); for(int i = 0; i < size; i++) for(int j = 0; j < size; j++){ if(i >= j) L[i*size + j] = i-j+1; else L[i*size + j] = 0; if(i <= j) U[i*size + j] = j-i+1; else U[i*size + j] = 0; } for(int i = 0; i < size; i++) { futures.push_back( async( initLoop, i)); } wait_all(futures); }
int hpx_main() { BMP SetImage; SetImage.SetBitDepth(24); SetImage.SetSize(sizeX * 2,sizeY); hpx::util::high_resolution_timer t; { using namespace std; using hpx::future; using hpx::async; using hpx::wait_all; int const max_iteration = 255; vector<future<int> > iteration; iteration.reserve(sizeX*sizeY); hpx::cout << "Initial setup completed in " << t.elapsed() << "s. Initializing and running futures...\n"; t.restart(); hpx::id_type const here = hpx::find_here(); fractals_action fractal_pixel; for (int i = 0; i < sizeX; i++) { for (int j = 0; j < sizeY; j++) { float x0 = (float)i * 3.5f / (float)sizeX - 2.5f; float y0 = (float)j * 2.0f / (float)sizeY - 1.0f; iteration.push_back(async(fractal_pixel, here, x0, y0, max_iteration)); } } wait_all(iteration); hpx::cout << sizeX*sizeY << " calculations run in " << t.elapsed() << "s. Transferring from futures to general memory...\n"; t.restart(); for (int i = 0; i < sizeX; ++i) { for (int j = 0; j < sizeY; ++j) { int it = iteration[i*sizeX + j].get(); for (int k = 0; k < 2; ++k) { int p = (it * 255) / max_iteration; SetImage.SetPixel(i * 2 + k, j, RGBApixel(p, p, p)); } } } } hpx::cout << "Transfer process completed in " << t.elapsed() << "s. Writing to hard disk...\n"; t.restart(); SetImage.WriteToFile("out.bmp"); hpx::cout << "Fractal image written to file \"out.bmp\" from memory in " << t.elapsed() << "s.\nInitializing shutdown process.\n"; return hpx::finalize(); // Handles HPX shutdown }
int hpx_main() { { using namespace std; ifstream fin; string path = __FILE__; string wordlist_path; string remove = "spell_check.cpp"; for (int i = 0; i < path.length() - remove.length(); i++) { wordlist_path.push_back(path[i]); if (path[i] == '\\') { wordlist_path.push_back(path[i]); } } //list of American English words in alphabetical order. Provided by Kevin at http://wordlist.sourceforge.net/ wordlist_path = wordlist_path + "5desk.txt"; fin.open(wordlist_path); int wordcount = 0; cout << "Reading dictionary file to memory...\n"; hpx::util::high_resolution_timer t; if(fin.is_open()) { string temp; while (fin.good()) { getline(fin, temp); for (int i = 0; i < temp.length(); i++) temp[i] = tolower(temp[i]); words.push_back(temp); wordcount++; } cout << wordcount << " words loaded in " << t.elapsed() << "s.\n"; } else { cout << "Error: Unable to open file.\n"; return hpx::finalize(); } fin.close(); char* word = new char[1024]; cout << "Enter the words you would like to spellcheck, separated by a \"Space\", and then press \"Enter\".\n"; cin.getline(word,1024, '\n'); vector<bool> contraction; vector<string> strs; { vector<string> temp; boost::split(temp, word, boost::is_any_of("\n\t -")); for (int i = 0; i < temp.size(); i++) { bool isContraction = false; string holder; for (int j = 0; j < temp[i].size(); j++) { //a size check to avoid errors if (temp[i].size() - j - 1 == 2) { //if this is a contraction, ignore the rest of it... if (temp[i][j+1] == '\'' && temp[i][j] == 'n' && temp[i][j+2] == 't') { //but label this as a contraction isContraction = true; break; } } //remove any garbage characters if (toupper(temp[i][j]) >= 'A' && toupper(temp[i][j]) <= 'Z') holder.push_back(tolower(temp[i][j])); } if (holder.size() > 0) { contraction.push_back(isContraction); strs.push_back(holder); } } } t.restart(); { using hpx::lcos::future; using hpx::async; using hpx::wait_all; vector<search_action> sAct;//[sizeX * sizeY]; vector<future<string>> wordRun; wordRun.reserve(strs.size()); for (int i = 0; i < strs.size(); ++i) { string& single = strs[i]; int start = 0; hpx::naming::id_type const locality_id = hpx::find_here(); search_action temp; wordRun.push_back(async(temp, locality_id, start, wordcount, single)); sAct.push_back(temp); //cout << search(0, wordcount, single) << endl; } wait_all(wordRun); cout << "Search completed in " << t.elapsed() << "s.\n"; for (int i = 0; i < strs.size(); i++) { cout << "Word number " << i + 1 << ":\n"; if (contraction[i]) cout << "Note: This word seems to be a contraction.\nThe last two letters have been ignored.\n"; cout << wordRun[i].get(); } } } return hpx::finalize(); // Handles HPX shutdown }