// public IList<string> GetSplit(split split) { IList<string> ret = new List<string>(); // uses the lines between l[0] (inclusive) and l[1] (exclusive) for (int i = split.from; i <= split.to; i++) { // just in case if (i >= inputFile.Count) { break; } ret.Add(inputFile[i]); } return ret; }
// public IList <string> GetSplit(split split) { IList <string> ret = new List <string>(); // uses the lines between l[0] (inclusive) and l[1] (exclusive) for (int i = split.from; i <= split.to; i++) { // just in case if (i >= inputFile.Count) { break; } ret.Add(inputFile[i]); } return(ret); }
/// <summary> /// This function is called by the client application to /// the master worker/tracker so that the size of each /// split can be calculated and the list of jobs be /// prepared to give to the other workers. /// </summary> /// <param name="fileSize"></param> /// <param name="nSplits"></param> public void CalculateJobList(int fileSize, int nSplits) { logger.Log("Calculating job list on fileSize: " + fileSize + " with " + nSplits + " splits."); checkForFrozenCommunication(); jobList = new List <split>(); // Calculate partition size, i.e. number of lines per split double partitionSize = 0; if (fileSize >= nSplits) { partitionSize = (1.0 * fileSize) / nSplits; partitionSize = Math.Ceiling(partitionSize); } else // if number of splits is bigger than the number of lines... { partitionSize = 1; // each worker will process just 1 line nSplits = fileSize; // the number of splits will not exceed the number of lines } int splitId = 0; for (int i = 0; i < fileSize; i += (int)partitionSize) { split workerJob; int lastLine = i + (int)partitionSize - 1; if (lastLine >= fileSize) // final case when last element cant get as many lines { lastLine = fileSize - 1; } workerJob = new split(splitId, i, lastLine); jobList.Add(workerJob); //logger.Log("Job " + splitId + " { " + workerJob.from + ", " + workerJob.to + " }"); splitId++; } }
/// <summary> /// This function is called by the client application to /// the master worker/tracker so that the size of each /// split can be calculated and the list of jobs be /// prepared to give to the other workers. /// </summary> /// <param name="fileSize"></param> /// <param name="nSplits"></param> public void CalculateJobList(int fileSize, int nSplits) { logger.Log("Calculating job list on fileSize: " + fileSize + " with " + nSplits + " splits."); checkForFrozenCommunication(); jobList = new List<split>(); // Calculate partition size, i.e. number of lines per split double partitionSize = 0; if (fileSize >= nSplits) { partitionSize = (1.0 * fileSize) / nSplits; partitionSize = Math.Ceiling(partitionSize); } else { // if number of splits is bigger than the number of lines... partitionSize = 1; // each worker will process just 1 line nSplits = fileSize; // the number of splits will not exceed the number of lines } int splitId = 0; for (int i = 0; i < fileSize; i += (int)partitionSize) { split workerJob; int lastLine = i + (int)partitionSize - 1; if (lastLine >= fileSize) { // final case when last element cant get as many lines lastLine = fileSize - 1; } workerJob = new split(splitId, i, lastLine); jobList.Add(workerJob); //logger.Log("Job " + splitId + " { " + workerJob.from + ", " + workerJob.to + " }"); splitId++; } }