EpetraExt  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_CrsMatrixIn.cpp
Go to the documentation of this file.
1 //@HEADER
2 // ***********************************************************************
3 //
4 // EpetraExt: Epetra Extended - Linear Algebra Services Package
5 // Copyright (2011) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 #include "EpetraExt_CrsMatrixIn.h"
42 #include "Epetra_Comm.h"
43 #include "Epetra_CrsMatrix.h"
44 #include "Epetra_Map.h"
45 #include "Epetra_IntVector.h"
46 #include "Epetra_IntSerialDenseVector.h"
47 #include "Epetra_Import.h"
48 #include "Epetra_Time.h"
49 #include "Epetra_Util.h"
50 
53 // Functions to read a MatrixMarket file and load it into a matrix.
54 // Adapted from
55 // Trilinos/packages/epetraext/src/inout/EpetraExt_CrsMatrixIn.cpp
56 // Modified by Jon Berry and Karen Devine to make matrix reallocations
57 // more efficient; rather than insert each non-zero separately, we
58 // collect rows of non-zeros for insertion.
59 // Modified by Karen Devine and Steve Plimpton to prevent all processors
60 // from reading the same file at the same time (ouch!); chunks of the file
61 // are read and broadcast by processor zero; each processor then extracts
62 // its nonzeros from the chunk, sorts them by row, and inserts them into
63 // the matrix.
64 // The variable "chunk_read" can be changed to modify the size of the chunks
65 // read from the file. Larger values of chunk_read lead to faster execution
66 // and greater memory use.
69 
70 using namespace EpetraExt;
71 namespace EpetraExt {
72 
73 static void sort_three(int* list, int *parlista, double *parlistb,
74  int start, int end);
76 int MatrixMarketFileToCrsMatrix(const char *filename,
77  const Epetra_Comm & comm, Epetra_CrsMatrix * & A)
78 {
79  EPETRA_CHK_ERR(MatrixMarketFileToCrsMatrixHandle(filename, comm, A));
80  return(0);
81 }
82 
84 int MatrixMarketFileToCrsMatrix(const char *filename,
85  const Epetra_Comm & comm, Epetra_CrsMatrix * & A, const bool transpose)
86 {
87  EPETRA_CHK_ERR(MatrixMarketFileToCrsMatrixHandle(filename, comm, A,
88  0, 0, 0, 0, transpose));
89  return(0);
90 }
92 
93 int MatrixMarketFileToCrsMatrix(const char *filename,
94  const Epetra_Comm & comm, Epetra_CrsMatrix * & A, const bool transpose,
95  const bool verbose)
96 {
97  EPETRA_CHK_ERR(MatrixMarketFileToCrsMatrixHandle(filename, comm, A,
98  0, 0, 0, 0,
99  transpose, verbose));
100  return(0);
101 }
102 
104 int MatrixMarketFileToCrsMatrix(const char *filename,
105  const Epetra_Map & rowMap, const Epetra_Map& rangeMap,
106  const Epetra_Map& domainMap, Epetra_CrsMatrix * & A, const bool transpose,
107  const bool verbose)
108 {
109  EPETRA_CHK_ERR(MatrixMarketFileToCrsMatrixHandle(filename,
110  rowMap.Comm(), A,
111  &rowMap, 0,
112  &rangeMap, &domainMap,
113  transpose, verbose));
114  return(0);
115 }
116 
118 int MatrixMarketFileToCrsMatrix(const char *filename,
119  const Epetra_Map & rowMap, Epetra_CrsMatrix * & A, const bool transpose,
120  const bool verbose)
121 {
122  EPETRA_CHK_ERR(MatrixMarketFileToCrsMatrixHandle(filename,
123  rowMap.Comm(), A,
124  &rowMap, 0, 0, 0,
125  transpose, verbose));
126  return(0);
127 }
128 
130 int MatrixMarketFileToCrsMatrix(const char *filename,
131  const Epetra_Map & rowMap, const Epetra_Map & colMap,
132  Epetra_CrsMatrix * & A, const bool transpose,
133  const bool verbose)
134 {
135  EPETRA_CHK_ERR(MatrixMarketFileToCrsMatrixHandle(filename,
136  rowMap.Comm(), A,
137  &rowMap, &colMap, 0, 0,
138  transpose, verbose));
139  return(0);
140 }
141 
143 int MatrixMarketFileToCrsMatrix(const char *filename,
144  const Epetra_Map & rowMap, const Epetra_Map & colMap,
145  const Epetra_Map& rangeMap, const Epetra_Map& domainMap,
146  Epetra_CrsMatrix * & A, const bool transpose,
147  const bool verbose)
148 {
149  EPETRA_CHK_ERR(MatrixMarketFileToCrsMatrixHandle(filename,
150  rowMap.Comm(), A,
151  &rowMap, &colMap,
152  &rangeMap, &domainMap,
153  transpose, verbose));
154  return(0);
155 }
156 
158 int MatrixMarketFileToCrsMatrixHandle(const char *filename,
159  const Epetra_Comm & comm,
160  Epetra_CrsMatrix * & A,
161  const Epetra_Map * rowMap,
162  const Epetra_Map * colMap,
163  const Epetra_Map * rangeMap,
164  const Epetra_Map * domainMap,
165  const bool transpose,
166  const bool verbose
167 )
168 {
169  const int chunk_read = 500000; // Modify this variable to change the
170  // size of the chunks read from the file.
171  const int headerlineLength = 257;
172  const int lineLength = 81;
173  const int tokenLength = 35;
174  char line[headerlineLength];
175  char token1[tokenLength];
176  char token2[tokenLength];
177  char token3[tokenLength];
178  char token4[tokenLength];
179  char token5[tokenLength];
180  int M, N, NZ; // Matrix dimensions
181  int i;
182  int me = comm.MyPID();
183 
184  Epetra_Time timer(comm);
185 
186  // Make sure domain and range maps are either both defined or undefined
187  if ((domainMap!=0 && rangeMap==0) || (domainMap==0 && rangeMap!=0)) {
188  EPETRA_CHK_ERR(-3);
189  }
190 
191  // check maps to see if domain and range are 1-to-1
192 
193  if (domainMap!=0) {
194  if (!domainMap->UniqueGIDs()) {EPETRA_CHK_ERR(-2);}
195  if (!rangeMap->UniqueGIDs()) {EPETRA_CHK_ERR(-2);}
196  }
197  else {
198  // If domain and range are not specified,
199  // rowMap becomes both and must be 1-to-1 if specified
200  if (rowMap!=0) {
201  if (!rowMap->UniqueGIDs()) {EPETRA_CHK_ERR(-2);}
202  }
203  }
204 
205  FILE * handle = 0;
206  if (me == 0) {
207  if (verbose) cout << "Reading MatrixMarket file " << filename << endl;
208  handle = fopen(filename,"r"); // Open file
209  if (handle == 0)
210  EPETRA_CHK_ERR(-1); // file not found
211 
212  // Check first line, which should be
213  // %%MatrixMarket matrix coordinate real general
214  if(fgets(line, headerlineLength, handle)==0) {
215  if (handle!=0) fclose(handle);
216  EPETRA_CHK_ERR(-1);
217  }
218  if(sscanf(line, "%s %s %s %s %s", token1,token2,token3,token4,token5)==0) {
219  if (handle!=0) fclose(handle);
220  EPETRA_CHK_ERR(-1);
221  }
222  if (strcmp(token1, "%%MatrixMarket") ||
223  strcmp(token2, "matrix") ||
224  strcmp(token3, "coordinate") ||
225  strcmp(token4, "real") ||
226  strcmp(token5, "general")) {
227  if (handle!=0) fclose(handle);
228  EPETRA_CHK_ERR(-1);
229  }
230 
231  // Next, strip off header lines (which start with "%")
232  do {
233  if(fgets(line, headerlineLength, handle)==0) {
234  if (handle!=0) fclose(handle);
235  EPETRA_CHK_ERR(-1);
236  }
237  } while (line[0] == '%');
238 
239  // Next get problem dimensions: M, N, NZ
240  if(sscanf(line, "%d %d %d", &M, &N, &NZ)==0) {
241  if (handle!=0) fclose(handle);
242  EPETRA_CHK_ERR(-1);
243  }
244  }
245  comm.Broadcast(&M, 1, 0);
246  comm.Broadcast(&N, 1, 0);
247  comm.Broadcast(&NZ, 1, 0);
248 
249  // Now create matrix using user maps if provided.
250 
251 
252  // Now read in chunks of triplets and broadcast them to other processors.
253  char *buffer = new char[chunk_read*lineLength];
254  int nchunk;
255  int nmillion = 0;
256  int nread = 0;
257  int rlen;
258 
259  // Storage for this processor's nonzeros.
260  const int localblock = 100000;
261  int localsize = NZ / comm.NumProc() + localblock;
262  int *iv = (int *) malloc(localsize * sizeof(int));
263  int *jv = (int *) malloc(localsize * sizeof(int));
264  double *vv = (double *) malloc(localsize * sizeof(double));
265  int lnz = 0; // Number of non-zeros on this processor.
266 
267  if (!iv || !jv || !vv)
268  EPETRA_CHK_ERR(-1);
269 
270  Epetra_Map *rowMap1;
271  bool allocatedHere=false;
272  if (rowMap != 0)
273  rowMap1 = const_cast<Epetra_Map *>(rowMap);
274  else {
275  rowMap1 = new Epetra_Map(M, 0, comm);
276  allocatedHere = true;
277  }
278  int ioffset = rowMap1->IndexBase()-1;
279  int joffset = (colMap != 0 ? colMap->IndexBase()-1 : ioffset);
280 
281  int rowmajor = 1; // Assume non-zeros are listed in row-major order,
282  int prevrow = -1; // but test to detect otherwise. If non-zeros
283  // are row-major, we can avoid the sort.
284 
285  while (nread < NZ) {
286  if (NZ-nread > chunk_read) nchunk = chunk_read;
287  else nchunk = NZ - nread;
288 
289  if (me == 0) {
290  char *eof;
291  rlen = 0;
292  for (int i = 0; i < nchunk; i++) {
293  eof = fgets(&buffer[rlen],lineLength,handle);
294  if (eof == NULL) {
295  fprintf(stderr, "%s", "Unexpected end of matrix file.");
296  EPETRA_CHK_ERR(-1);
297  }
298  rlen += strlen(&buffer[rlen]);
299  }
300  buffer[rlen++]='\n';
301  }
302  comm.Broadcast(&rlen, 1, 0);
303  comm.Broadcast(buffer, rlen, 0);
304 
305  buffer[rlen++] = '\0';
306  nread += nchunk;
307 
308  // Process the received data, saving non-zeros belonging on this proc.
309  char *lineptr = buffer;
310  for (rlen = 0; rlen < nchunk; rlen++) {
311  char *next = strchr(lineptr,'\n');
312  int I = atoi(strtok(lineptr," \t\n")) + ioffset;
313  int J = atoi(strtok(NULL," \t\n")) + joffset;
314  double V = atof(strtok(NULL," \t\n"));
315  lineptr = next + 1;
316  if (transpose) {
317  // swap I and J indices.
318  int tmp = I;
319  I = J;
320  J = tmp;
321  }
322  if (rowMap1->MyGID(I)) {
323  // This processor keeps this non-zero.
324  if (lnz >= localsize) {
325  // Need more memory to store nonzeros.
326  localsize += localblock;
327  iv = (int *) realloc(iv, localsize * sizeof(int));
328  jv = (int *) realloc(jv, localsize * sizeof(int));
329  vv = (double *) realloc(vv, localsize * sizeof(double));
330  }
331  iv[lnz] = I;
332  jv[lnz] = J;
333  vv[lnz] = V;
334  lnz++;
335  if (I < prevrow) rowmajor = 0;
336  prevrow = I;
337  }
338  }
339 
340  // Status check
341  if (nread / 1000000 > nmillion) {
342  nmillion++;
343  if (verbose && me == 0) cout << nmillion << "M ";
344  }
345  }
346 
347  delete [] buffer;
348 
349  if (!rowmajor) {
350  // Sort into row-major order (by iv) so can insert entire rows at once.
351  // Reorder jv and vv to parallel iv.
352  if (verbose && me == 0) cout << endl << " Sorting local nonzeros" << endl;
353  sort_three(iv, jv, vv, 0, lnz-1);
354  }
355 
356  // Compute number of entries per local row for use in constructor;
357  // saves reallocs in FillComplete.
358 
359  // Now construct the matrix.
360  // Count number of entries in each row so can use StaticProfile=2.
361  if (verbose && me == 0) cout << endl << " Constructing the matrix" << endl;
362  int numRows = rowMap1->NumMyElements();
363  int *numNonzerosPerRow = new int[numRows];
364  for (i = 0; i < numRows; i++) numNonzerosPerRow[i] = 0;
365  for (i = 0; i < lnz; i++)
366  numNonzerosPerRow[rowMap1->LID(iv[i])]++;
367 
368  if (rowMap!=0 && colMap !=0)
369  A = new Epetra_CrsMatrix(Copy, *rowMap, *colMap, numNonzerosPerRow);
370  else if (rowMap!=0) {
371  // Construct with StaticProfile=true since we know numNonzerosPerRow.
372  // Less memory will be needed in FillComplete.
373  A = new Epetra_CrsMatrix(Copy, *rowMap, numNonzerosPerRow, true);
374  }
375  else {
376  // Construct with StaticProfile=true since we know numNonzerosPerRow.
377  // Less memory will be needed in FillComplete.
378  A = new Epetra_CrsMatrix(Copy, *rowMap1, numNonzerosPerRow, true);
379  }
380  A->SetTracebackMode(1);
381 
382  // Rows are inserted in ascending global number, and the insertion uses numNonzerosPerRow.
383  // Therefore numNonzerosPerRow must be permuted, as it was created in ascending local order.
384  int *gidList = new int[numRows];
385  for (i = 0; i < numRows; i++) gidList[i] = rowMap1->GID(i);
386  Epetra_Util::Sort(true,numRows,gidList,0,0,1,&numNonzerosPerRow);
387  delete [] gidList;
388 
389  // Insert the global values into the matrix row-by-row.
390  if (verbose && me == 0) cout << " Inserting global values" << endl;
391  for (int sum = 0, i = 0; i < numRows; i++) {
392  if (numNonzerosPerRow[i]) {
393  int ierr = A->InsertGlobalValues(iv[sum], numNonzerosPerRow[i],
394  &vv[sum], &jv[sum]);
395  if (ierr<0) EPETRA_CHK_ERR(ierr);
396  sum += numNonzerosPerRow[i];
397  }
398  }
399 
400  delete [] numNonzerosPerRow;
401  free(iv);
402  free(jv);
403  free(vv);
404 
405  if (verbose && me == 0) cout << " Completing matrix fill" << endl;
406  if (rangeMap != 0 && domainMap != 0) {
407  EPETRA_CHK_ERR(A->FillComplete(*domainMap, *rangeMap));
408  }
409  else if (M!=N) {
410  Epetra_Map newDomainMap(N,rowMap1->IndexBase(), comm);
411  EPETRA_CHK_ERR(A->FillComplete(newDomainMap, *rowMap1));
412  }
413  else {
414  EPETRA_CHK_ERR(A->FillComplete());
415  }
416 
417  if (allocatedHere) delete rowMap1;
418 
419  if (handle!=0) fclose(handle);
420  double dt = timer.ElapsedTime();
421  if (verbose && me == 0) cout << "File Read time (secs): " << dt << endl;
422  return(0);
423 }
424 
426 // Sorting values in array list in increasing order. Criteria is int.
427 // Also rearrange values in arrays parlista and partlistb
428 // to match the new order of list.
429 
431  int *list, int *parlista, double *parlistb,
432  int start, int end, int *equal, int *larger)
433 {
434 int i, key, itmp;
435 double dtmp;
436 
437  key = list ? list[(end+start)/2] : 1;
438 
439  *equal = *larger = start;
440  for (i = start; i <= end; i++)
441  if (list[i] < key) {
442  itmp = parlista[i];
443  parlista[i] = parlista[*larger];
444  parlista[(*larger)] = parlista[*equal];
445  parlista[(*equal)] = itmp;
446  dtmp = parlistb[i];
447  parlistb[i] = parlistb[*larger];
448  parlistb[(*larger)] = parlistb[*equal];
449  parlistb[(*equal)] = dtmp;
450  itmp = list[i];
451  list[i] = list[*larger];
452  list[(*larger)++] = list[*equal];
453  list[(*equal)++] = itmp;
454  }
455  else if (list[i] == key) {
456  itmp = parlista[i];
457  parlista[i] = parlista[*larger];
458  parlista[(*larger)] = itmp;
459  dtmp = parlistb[i];
460  parlistb[i] = parlistb[*larger];
461  parlistb[(*larger)] = dtmp;
462  list[i] = list[*larger];
463  list[(*larger)++] = key;
464  }
465 }
466 
468 static void sort_three(int* list, int *parlista, double *parlistb,
469  int start, int end)
470 {
471 int equal, larger;
472 
473  if (start < end) {
474  quickpart_list_inc_int(list, parlista, parlistb, start, end,
475  &equal, &larger);
476  sort_three(list, parlista, parlistb, start, equal-1);
477  sort_three(list, parlista, parlistb, larger, end);
478  }
479 }
480 
482 int MatlabFileToCrsMatrix(const char *filename,
483  const Epetra_Comm & comm,
484  Epetra_CrsMatrix * & A)
485 {
486  const int lineLength = 1025;
487  char line[lineLength];
488  int I, J;
489  double V;
490 
491  FILE * handle = 0;
492 
493  handle = fopen(filename,"r"); // Open file
494  if (handle == 0)
495  EPETRA_CHK_ERR(-1); // file not found
496 
497  int numGlobalRows = 0;
498  int numGlobalCols = 0;
499  while(fgets(line, lineLength, handle)!=0) {
500  if(sscanf(line, "%d %d %lg\n", &I, &J, &V)==0) {if (handle!=0) fclose(handle); EPETRA_CHK_ERR(-1);}
501  if (I>numGlobalRows) numGlobalRows = I;
502  if (J>numGlobalCols) numGlobalCols = J;
503  }
504 
505  if (handle!=0) fclose(handle);
506  Epetra_Map rangeMap(numGlobalRows, 0, comm);
507  Epetra_Map domainMap(numGlobalCols, 0, comm);
508  A = new Epetra_CrsMatrix(Copy, rangeMap, 0);
509 
510  // Now read in each triplet and store to the local portion of the matrix if the row is owned.
511  const Epetra_Map & rowMap1 = A->RowMap();
512 
513  handle = 0;
514 
515  handle = fopen(filename,"r"); // Open file
516  if (handle == 0)
517  EPETRA_CHK_ERR(-1); // file not found
518 
519  while (fgets(line, lineLength, handle)!=0) {
520  if(sscanf(line, "%d %d %lg\n", &I, &J, &V)==0) {if (handle!=0) fclose(handle); EPETRA_CHK_ERR(-1);}
521  I--; J--; // Convert to Zero based
522  if (rowMap1.MyGID(I)) {
523  int ierr = A->InsertGlobalValues(I, 1, &V, &J);
524  if (ierr<0) EPETRA_CHK_ERR(ierr);
525  }
526  }
527 
528  EPETRA_CHK_ERR(A->FillComplete(domainMap, rangeMap));
529 
530  if (handle!=0) fclose(handle);
531  return(0);
532 }
533 
534 int HypreFileToCrsMatrix(const char *filename, const Epetra_Comm &comm, Epetra_CrsMatrix *&Matrix){
535  int MyPID = comm.MyPID();
536  // This double will be in the format we want for the extension besides the leading zero
537  double filePID = (double)MyPID/(double)100000;
538  std::ostringstream stream;
539  // Using setprecision() puts it in the string
540  stream << std::setiosflags(std::ios::fixed) << std::setprecision(5) << filePID;
541  // Then just ignore the first character
542  std::string fileName(filename);
543  fileName += stream.str().substr(1,7);
544  // Open the file
545  std::ifstream file(fileName.c_str());
546  string line;
547  if(file.is_open()){
548  std::getline(file, line);
549  int ilower, iupper;
550  std::istringstream istream(line);
551  // The first line of the file has the beginning and ending rows
552  istream >> ilower;
553  istream >> iupper;
554  // Using those we can create a row map
555  Epetra_Map RowMap(-1, iupper-ilower+1, 0, comm);
556  Matrix = new Epetra_CrsMatrix(Copy, RowMap, 0);
557  int currRow = -1;
558  int counter = 0;
559  std::vector<int> indices;
560  std::vector<double> values;
561  while(!file.eof()){
562  std::getline(file, line);
563  std::istringstream lineStr(line);
564  int row, col;
565  double val;
566  lineStr >> row;
567  lineStr >> col;
568  lineStr >> val;
569  if(currRow == -1) currRow = row; // First line
570  if(row == currRow){
571  // add to the vector
572  counter = counter + 1;
573  indices.push_back(col);
574  values.push_back(val);
575  } else {
576  Matrix->InsertGlobalValues(currRow, counter, &values[0], &indices[0]);
577  indices.clear();
578  values.clear();
579  counter = 0;
580  currRow = row;
581  // make a new vector
582  indices.push_back(col);
583  values.push_back(val);
584  counter = counter + 1;
585  }
586  }
587  Matrix->InsertGlobalValues(currRow, counter, &values[0], &indices[0]);
588  Matrix->Comm().Barrier();
589  Matrix->FillComplete();
590  file.close();
591  return 0;
592  } else {
593  cout << "\nERROR:\nCouldn't open " << fileName << ".\n";
594  return -1;
595  }
596 }
597 
598 } // namespace EpetraExt
599 
int MatrixMarketFileToCrsMatrix(const char *filename, const Epetra_Comm &comm, Epetra_CrsMatrix *&A)
int MatrixMarketFileToCrsMatrixHandle(const char *filename, const Epetra_Comm &comm, Epetra_CrsMatrix *&A, const Epetra_Map *rowMap, const Epetra_Map *colMap, const Epetra_Map *rangeMap, const Epetra_Map *domainMap, const bool transpose, const bool verbose)
int MatlabFileToCrsMatrix(const char *filename, const Epetra_Comm &comm, Epetra_CrsMatrix *&A)
Constructs an Epetra_CrsMatrix object from a Matlab format file, distributes rows evenly across proce...
int HypreFileToCrsMatrix(const char *filename, const Epetra_Comm &comm, Epetra_CrsMatrix *&Matrix)
Constructs an Epetra_CrsMatrix object from a Hypre Matrix Print command, the row map is specified...
static void quickpart_list_inc_int(int *list, int *parlista, double *parlistb, int start, int end, int *equal, int *larger)
static void sort_three(int *list, int *parlista, double *parlistb, int start, int end)