string StringParserandInvoker:: addSamples(vector<string> tokens) { vector<float> numbers; if(tokens.size()==3) { str=(char*)tokens[1].c_str(); numbers=splitNumbers(tokens[2]); bool isTrue=rvs->addRollingValues(str,&numbers); if(isTrue) { return "Successful"; } else { return "Value not found"; } } return "Invalid number of parameters. /n Usage DECLSAMPLES <data> <value>"; }
int main(int argc, char const* argv[]) { std::string line; std::ifstream file(argv[1]); while(getline(file, line)) { if(!line.empty()) { std::string words, sequence; std::stringstream stream(line); //splitting up words and sequence of numbers getline(stream, words, ';'); getline(stream, sequence, '\n'); //splitting into arrays of elements std::vector<std::string> shuffled = splitWords(words); std::vector<int> numbers = splitNumbers(sequence); //associating each word with correct index std::map<int, std::string> message; for(int i = 0; i < numbers.size(); i++) { message.insert(std::pair<int, std::string>(numbers[i], shuffled[i])); } //finding missing index and adding to map //the word with the missing index will always //be the last word in the shuffled vector int missing_index = find_missing_index(numbers, shuffled.size()); message.insert(std::pair<int, std::string>(missing_index, shuffled.back())); for (const auto & itr : message) { std::cout << itr.second << " "; } std::cout << std::endl; } } file.close(); return 0; }
int main(int argc, char **argv){ int amountForFirst; int amountFound; unsigned amountNumbers; int amountPcs; int amountPerPC; int counter; int rank; int target; int totalFound; char *content; int *founds; int **numbers; int *slaveNumbers; MPI_Status status; if(argc != 3) goto ERROR; MPI_Init(&argc, &argv); amountForFirst = 0; amountFound = 0; amountNumbers = 0; amountPcs = 0; amountPerPC = 0; counter = 0; rank = 0; target = 0; totalFound = 0; content = NULL; founds = NULL; numbers = NULL; slaveNumbers = NULL; memset(&status, 0, sizeof(MPI_Status)); MPI_Comm_size(MPI_COMM_WORLD, &amountPcs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); target = atoi(argv[2]); if(rank == 0){ if(getContent(argv[1], &content)){ amountNumbers = splitNumbers(content, amountPcs, &amountForFirst, &amountPerPC, &numbers); if(amountNumbers){ for(counter = 1; counter < amountPcs; counter++){ MPI_Send(&amountPerPC, 1, MPI_INT, counter, 0, MPI_COMM_WORLD); MPI_Send(numbers[counter], amountPerPC, MPI_INT, counter, 0, MPI_COMM_WORLD); } /* Search and save in node 0 */ if(searchNumber(numbers[0], amountForFirst, target, &founds, &amountFound)){ if(!savePositions(founds, amountFound, 0)) goto ERROR; printf("Rank %d found %d\n", rank, amountFound); }else{ goto ERROR; } totalFound += amountFound; /* Receive founds in other nodes and save. */ for(counter = 1; counter < amountPcs; counter++){ amountFound = 0; free(founds); MPI_Recv(&amountFound, 1, MPI_INT, counter, 0, MPI_COMM_WORLD, &status); totalFound += amountFound; founds = (int*) calloc(amountFound, sizeof(int)); if(!founds) goto ERROR; MPI_Recv(founds, amountFound, MPI_INT, counter, 0, MPI_COMM_WORLD, &status); if(!savePositions(founds, amountFound, amountForFirst + (counter * amountPerPC))) goto ERROR; printf("Rank %d found %d\n", status.MPI_SOURCE, amountFound); } printf("Total found: %d\n", totalFound); }else{ goto ERROR; } }else{ goto ERROR; } }else{ MPI_Recv(&amountPerPC, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status); slaveNumbers = (int*) calloc(amountPerPC, sizeof(int)); if(!slaveNumbers) goto ERROR; MPI_Recv(slaveNumbers, amountPerPC, MPI_INT, 0, 0, MPI_COMM_WORLD, &status); if(searchNumber(slaveNumbers, amountPerPC, target, &founds, &amountFound)){ MPI_Send(&amountFound, 1, MPI_INT, 0, 0, MPI_COMM_WORLD); MPI_Send(slaveNumbers, amountFound, MPI_INT, 0, 0, MPI_COMM_WORLD); }else{ goto ERROR; } } goto END; ERROR: printf("%d - Deu ruim!!!\n", rank); END: if(content) free(content); if(founds) free(founds); if(slaveNumbers) free(slaveNumbers); memset(&status, 0, sizeof(MPI_Status)); for(counter = 0; counter < amountPcs; counter++){ if(numbers){ if(numbers[counter]) free(numbers[counter]); } } if(numbers) free(numbers); MPI_Finalize(); return 0; }