void CMultiMix::AddMixer(CMixereView *Mixer) { m_Mixer.Add(Mixer); Mixer->UpdateVolume(); ApplyOptions(Mixer); m_CrossfaderBar.AddSource(Mixer); }
void OptionsMenuScene::Update() { InputLayer* ilayer = InputLayer::Instance(); if (ilayer->KeyPressed(DIK_R) && ilayer->KeyDown(DIK_LCONTROL)) { ResetCanvas(); } if (m_canvas.GetStateEnabled("EXIT_MENU")) { m_screenFade.SetFadeTime(0.25f); m_screenFade.FadeOut(); } if (m_screenFade.IsFadeOutEnding()) { if (m_canvas.GetStateEnabled("SAVE_SETTINGS")) { ApplyOptions(); } MainMenuScene* mainMenu = SceneManager::Instance()->LoadScene<MainMenuScene>(); mainMenu->m_promptKey = false; m_isPendingUnload = true; } m_canvas.Update(); m_screenFade.Update(); }
EditorSettings::EditorSettings() { settings = new KeyedArchive(); settings->Load("~doc:/ResourceEditorOptions.archive"); ApplyOptions(); }
DLLEXPORT BOOL APIENTRY Initialize(PTCAPI_OPTIONS options) { if (!InitOSVersionInfo()) { //TODO: Doc -> See GetLastError() //TODO: Doc -> Warnings may be saturated by subsequent errors //TODO: Save warnings here and pass at the end in case of no error return FALSE; } if (IsTrueCryptInstallerRunning()) { set_error_debug_out(TCAPI_E_TC_INSTALLER_RUNNING); return FALSE; } if (!options || !ApplyOptions(options)) { //TODO: Doc -> See GetLastError() return FALSE; } if (!EncryptionThreadPoolStart (ReadEncryptionThreadPoolFreeCpuCountLimit())) { set_error_debug_out(TCAPI_E_CANT_START_ENCPOOL); return FALSE; } bTcApiInitialized = TRUE; return bTcApiInitialized; }
void CMultiMix::ShowOptionsDlg() { if (m_OptionsDlg.DoModal() == IDOK) { for (int i = 0; i < GetMixerCount(); i++) ApplyOptions(m_Mixer[i]); EnableToolTips(m_OptionsDlg.ShowToolTips()); } }
void ScreenCapSetting::on_pushButton_applyOptions_clicked() { QString bits(ui.comboBox_bits->currentText().split(" ")[0]); QString scal(ui.comboBox_scaling->currentText().split(" ")[0]); QString refresh(ui.comboBox_refresh->currentText().split(" ")[0]); emit ApplyOptions(bits, scal, refresh); close(); }
void CMainFrame::OnEditOptions() { COptionsInfo PrevOpts(m_Options); COptionsDlg dlg(IDS_OPTIONS, m_Options, this, m_OptionsPage); if (dlg.DoModal() == IDOK) { m_OptionsPage = dlg.GetCurPage(); // save selected page index ApplyOptions(PrevOpts); // apply edited options } else // canceled m_Options = PrevOpts; // restore previous options }
void FeedFilter::Match(FeedItemInfo* pFeedItemInfo) { int index = 0; for (RuleList::iterator it = m_Rules.begin(); it != m_Rules.end(); it++) { Rule* pRule = *it; index++; if (pRule->IsValid()) { bool bMatch = pRule->Match(pFeedItemInfo); switch (pRule->GetCommand()) { case frAccept: case frOptions: if (bMatch) { pFeedItemInfo->SetMatchStatus(FeedItemInfo::msAccepted); pFeedItemInfo->SetMatchRule(index); ApplyOptions(pRule, pFeedItemInfo); if (pRule->GetCommand() == frAccept) { return; } } break; case frReject: if (bMatch) { pFeedItemInfo->SetMatchStatus(FeedItemInfo::msRejected); pFeedItemInfo->SetMatchRule(index); return; } break; case frRequire: if (!bMatch) { pFeedItemInfo->SetMatchStatus(FeedItemInfo::msRejected); pFeedItemInfo->SetMatchRule(index); return; } break; case frComment: break; } } } pFeedItemInfo->SetMatchStatus(FeedItemInfo::msIgnored); pFeedItemInfo->SetMatchRule(0); }
struct sparsematrix ExecuteMondriaan(struct sparsematrix* matrix, int SplitStrategy, struct opts* Options, long* comm_value){ if (SplitStrategy == 5) Options->SplitStrategy = OneDimCol; else if (SplitStrategy == 8) Options->SplitStrategy = MediumGrain; else if (SplitStrategy == -1){} else{ printf("Wrong Split Strategy!\n"); exit(1); } if (!ApplyOptions(Options)){ printf("Invalid options!\n"); exit(1); } /*printf("%s\n",matrix->MMTypeCode);*/ /* if (!DoMondriaan(MondriaanMatrix, MondriaanU, MondriaanV, &Stats, NumProcessors, Imbalance, Permutation, Symm, SplitStrategy, MaxIterations)) */ PstartInit(matrix,2); if(!DistributeMatrixMondriaan(matrix, 2, 0.03, Options, NULL)){ printf("uh oh\n"); exit(1); } /* Variables used for calculating the communication volume. */ long ComVolumeRow, ComVolumeCol, Dummy; /* Calculate the communication volume. */ CalcCom(matrix, NULL, ROW, &ComVolumeRow, &Dummy, &Dummy, &Dummy, &Dummy); CalcCom(matrix, NULL, COL, &ComVolumeCol, &Dummy, &Dummy, &Dummy, &Dummy); /* printf("comm: %ld, %ld\n", ComVolumeRow,ComVolumeCol);*/ *comm_value = ComVolumeRow+ComVolumeCol; struct sparsematrix new_matrix = partition_to_matrix(matrix); /* struct sparsematrix output = *matrix; print_matrix(output); long* newI = vecallocl(matrix->NrNzElts); long* newJ = vecallocl(matrix->NrNzElts); double* newValues = vecallocd(matrix->NrNzElts); memcpy(newI,new_matrix.i,matrix->NrNzElts*SZLONG); memcpy(newJ,new_matrix.j,matrix->NrNzElts*SZLONG); memcpy(newValues,new_matrix.ReValue,matrix->NrNzElts*SZDBL); MMDeleteSparseMatrix(&new_matrix); vecfreel(output.i); vecfreel(output.j); vecfreed(output.ReValue); output.i = newI; output.j = newJ, output.ReValue = newValues; */ return new_matrix; }
void Entry(void) { HANDLE hMutex; int result=1; Options options; g_controlMsg=RegisterWindowMessageA(CONTROL_MESSAGE_NAME); ZeroFill(&options,sizeof options); ProcessCommandLine(&options); #ifdef _DEBUG options.showWindow=TRUE; #endif hMutex=OpenMutexA(MUTEX_ALL_ACCESS,FALSE,MUTEX_NAME); if(hMutex) { // Already running. ApplyOptions(&options); } else { if(options.nextLayout||options.prevLayout) { // Don't do anything. } else { hMutex=CreateMutexA(0,FALSE,MUTEX_NAME); if(!RunHelpers()) result=1; else { result=Main(&options); ReleaseMutex(hMutex); hMutex=NULL; } PostMessage(HWND_BROADCAST,g_controlMsg,CONTROL_QUIT,0); } } LocalFree(options.pLayoutToSet); options.pLayoutToSet=NULL; ExitProcess(result); }
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_StatusBar.Create(this) || !m_StatusBar.SetIndicators(indicators, _countof(indicators))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } EnableDocking(CBRS_ALIGN_ANY); m_pFloatingFrameClass = RUNTIME_CLASS(CSCBMiniDockFrameWnd); // custom dock frame if (!CreateToolbars()) { TRACE0("Failed to create tool bar\n"); return -1; // fail to create } ShowButton(m_TransportBar, ID_TRANSPORT_PAUSE, FALSE); // avoids gap after bar if (!CreateDialogBars()) { TRACE0("Failed to create dialog bar\n"); return -1; // fail to create } if (!CreateSizingBars()) { TRACE0("Failed to create sizing control bar\n"); return -1; // fail to create } if (VerifyBarState(REG_SETTINGS)) { for (int iBar = 0; iBar < SIZING_BARS; iBar++) { CSizingControlBarG *pBar = STATIC_DOWNCAST(CSizingControlBarG, GetBarAtOffset(m_SizingBarInfo[iBar].Offset)); pBar->LoadState(REG_SETTINGS); } LoadBarState(REG_SETTINGS); } SetTimer(TIMER_ID, 1000 / TIMER_FREQUENCY, NULL); // start timer DragAcceptFiles(); SetCursorWavePos(_T("")); ApplyOptions(COptionsInfo::m_Defaults); if (m_Options.m_CheckForUpdates) // if automatically checking for updates AfxBeginThread(CheckForUpdatesThreadFunc, this); // launch thread to check AfxBeginThread(IteratePluginsThread, this); return 0; }
long newMondriaan(struct sparsematrix* matrix, int SplitStrategy, struct sparsematrix* output) { struct opts Options; /* The Mondriaan options */ struct sparsematrix A; /* The Matrix;-) */ long q; int symmetric; FILE *File = NULL; /* Get the parameters from the command line and initialise Options */ SetDefaultOptions(&Options); if (!SetOptionsFromFile(&Options, "Mondriaan.defaults")) { fprintf(stderr, "main(): warning, cannot set options from 'Mondriaan.defaults', using default options and creating standard 'Mondriaan.defaults'!\n"); File = fopen("Mondriaan.defaults", "w"); if (File != NULL) { ExportDefaultOptions(File); SetDefaultOptions(&Options); fclose(File); } else { fprintf(stderr, "main(): Unable to create 'Mondriaan.defaults'!\n"); } } /* Options.matrix = matrix;*/ Options.P = 2; Options.eps = 0.03; if(SplitStrategy == 8) Options.SplitStrategy = MediumGrain; if(SplitStrategy == 5) Options.SplitStrategy = OneDimCol; if (!ApplyOptions(&Options)) { fprintf(stderr, "main(): could not apply given options!\n"); exit(-1); } A = *matrix; /* Remove duplicate nonzeros by adding them */ if (!SparseMatrixRemoveDuplicates(&A)) { fprintf(stderr, "main(): Unable to remove duplicates!\n"); exit(-1); } /* Check if matrix A is already distributed */ if (A.MMTypeCode[0] == 'D') { /* Matrix will be partitioned again */ fprintf(stderr, "Warning: Matrix '%s' already distributed !\n", Options.matrix); fprintf(stderr, " (Ignoring current partitions)\n"); A.NrProcs = 0; if (A.Pstart != NULL) free(A.Pstart); A.Pstart = NULL; } /* Register whether the input matrix was symmetric, since the symmetry type code will be changed by the conversion to full, to the code 'G' for a general matrix */ if (A.m == A.n && (A.MMTypeCode[3]=='S' || A.MMTypeCode[3]=='K' || A.MMTypeCode[3]=='H')) { symmetric = TRUE; } else { symmetric = FALSE; if (Options.SplitStrategy == SFineGrain) { fprintf(stderr, "Error: Symmetric finegrain can only be used on symmetric input matrices!\n"); exit(-1); } } if (symmetric) { if (Options.SymmetricMatrix_UseSingleEntry == SingleEntNo) SparseMatrixSymmetric2Full(&A); else if (Options.SplitStrategy == SFineGrain) SparseMatrixSymmetricRandom2Lower(&A); else if (Options.SymmetricMatrix_SingleEntryType == ETypeRandom) SparseMatrixSymmetricLower2Random(&A); } if (Options.SplitStrategy == SFineGrain && Options.SymmetricMatrix_SingleEntryType == ETypeRandom) printf("Warning: Symmetric finegrain requires lower-triangular format of symmetric matrix;\n Random single entry type option is overridden.\n"); /* If the matrix is square, add the dummies if requested. This may lead to an enhanced vector distribution in the case of an equal distribution of the input and output vectors. */ if (A.m == A.n && Options.SquareMatrix_DistributeVectorsEqual == EqVecYes && Options.SquareMatrix_DistributeVectorsEqual_AddDummies == DumYes) AddDummiesToSparseMatrix(&A); /* Set the number of processors */ A.NrProcs = Options.P; /* Initialise Pstart with all nonzeros in processor 0 */ A.Pstart = (long *) malloc((A.NrProcs+1) * sizeof(long)); if (A.Pstart == NULL) { fprintf(stderr, "main(): Not enough memory for Pstart!\n"); exit(-1); } A.Pstart[0] = 0; for (q = 1; q <= A.NrProcs; q++) A.Pstart[q] = A.NrNzElts; /**** Distribute the matrix (and time it) ****/ if (!DistributeMatrixMondriaan(&A, A.NrProcs, Options.eps, &Options, 0)) { fprintf(stderr, "main(): Unable to distribute matrix!\n"); exit(-1); } long ComVolumeRow, ComVolumeCol, Dummy; CalcCom(&A, NULL, ROW, &ComVolumeRow, &Dummy, &Dummy, &Dummy, &Dummy); CalcCom(&A, NULL, COL, &ComVolumeCol, &Dummy, &Dummy, &Dummy, &Dummy); long comm_value = ComVolumeRow+ComVolumeCol; MMInsertProcessorIndices(&A); *output = copyMatrix(&A); MMDeleteSparseMatrix(&A); return comm_value; } /* end main */
void GenerateCode ( istream& input, ostream& output, const JString& stringPath, const JString& formName, const JString& tagName, const JString& userTopEnclVarName, JPtrArray<JString>* objTypes, JPtrArray<JString>* objNames ) { JIndex i; // width input >> ws; JString line = JReadUntilws(input); assert( line == kFormWidthMarker ); JSize formWidth; input >> formWidth; // height input >> ws; line = JReadUntilws(input); assert( line == kFormHeightMarker ); JSize formHeight; input >> formHeight; // object count (marker contains whitespace) input >> ws; line = JReadUntil(input, ':') + ":"; assert( line == kFormObjCountMarker ); JSize itemCount; input >> itemCount; // create window const JString topEnclFrameName = tagName + "_Frame"; const JString topEnclApName = tagName + "_Aperture"; JString topEnclVarName; if (tagName == kDefaultDelimTag) { topEnclVarName = kDefTopEnclVarName; output << " JXWindow* window = new JXWindow(this, "; output << formWidth << ',' << formHeight; output << ", \"\");" << endl; output << " assert( window != NULL );" << endl; output << endl; } else { assert( !userTopEnclVarName.IsEmpty() ); topEnclVarName = userTopEnclVarName; output << " const JRect "; topEnclFrameName.Print(output); output << " = "; topEnclVarName.Print(output); output << "->GetFrame();" << endl; output << " const JRect "; topEnclApName.Print(output); output << " = "; topEnclVarName.Print(output); output << "->GetAperture();" << endl; output << " "; topEnclVarName.Print(output); output << "->AdjustSize(" << formWidth << " - "; topEnclApName.Print(output); output << ".width(), " << formHeight << " - "; topEnclApName.Print(output); output << ".height());" << endl; output << endl; } // We need to calculate the enclosure for each object. Since objects // are drawn in the order added, an object must come after its enclosure // in the list in order to be visible. JArray<JRect> rectList(10); JArray<JBoolean> isInstanceVar(10); // This array is used to send the options to ApplyOptions. // It does not own the pointers that it contains. JPtrArray<JString> optionValues(JPtrArrayT::kForgetAll, kOptionCount); for (i=1; i<=kOptionCount; i++) { optionValues.Append(NULL); } // generate code for each object JStringManager stringMgr; JIndex objCount = 1; for (i=1; i<=itemCount; i++) { // check for start-of-object input >> ws; line = JReadLine(input); assert( line == kBeginObjLine ); // object class JString flClass = JReadLine(input); RemoveIdentifier(kObjClassMarker, &flClass); // object type JString flType = JReadLine(input); RemoveIdentifier(kObjTypeMarker, &flType); // object frame input >> ws; line = JReadUntilws(input); assert( line == kObjRectMarker ); JCoordinate x,y,w,h; input >> x >> y >> w >> h >> ws; const JRect frame(y, x, y+h, x+w); rectList.AppendElement(frame); // box type JString boxType = JReadLine(input); RemoveIdentifier(kObjBoxTypeMarker, &boxType); // colors input >> ws; line = JReadUntilws(input); assert( line == kObjColorsMarker ); JString col1 = JReadUntilws(input); optionValues.SetElement(kCol1Index, &col1, JPtrArrayT::kForget); JString col2 = JReadUntilws(input); optionValues.SetElement(kCol2Index, &col2, JPtrArrayT::kForget); // label info JString lAlign = JReadLine(input); RemoveIdentifier(kObjLAlignMarker, &lAlign); JString lStyle = JReadLine(input); RemoveIdentifier(kObjLStyleMarker, &lStyle); JString lSize = JReadLine(input); RemoveIdentifier(kObjLSizeMarker, &lSize); JString lColor = JReadLine(input); RemoveIdentifier(kObjLColorMarker, &lColor); JString label = JReadLine(input); RemoveIdentifier(kObjLabelMarker, &label); // shortcuts JString shortcuts = JReadLine(input); RemoveIdentifier(kObjShortcutMarker, &shortcuts); optionValues.SetElement(kShortcutsIndex, &shortcuts, JPtrArrayT::kForget); // resizing (ignored) JIgnoreLine(input); // gravity input >> ws; line = JReadUntilws(input); assert( line == kObjGravityMarker ); const JString nwGravity = JReadUntilws(input); const JString seGravity = JReadUntilws(input); // variable name JBoolean isLocal = kJFalse; JString* varName = new JString(JReadLine(input)); assert( varName != NULL ); RemoveIdentifier(kObjNameMarker, varName); if (varName->IsEmpty()) { isInstanceVar.AppendElement(kJFalse); GetTempVarName(tagName, varName, *objNames); isLocal = kJTrue; } else if (varName->GetFirstCharacter() == '(' && varName->GetLastCharacter() == ')') { isInstanceVar.AppendElement(kJFalse); isLocal = kJTrue; *varName = varName->GetSubstring(2, varName->GetLength()-1); } else if (varName->GetFirstCharacter() == '<' && varName->GetLastCharacter() == '>') { isInstanceVar.AppendElement(kJFalse); *varName = varName->GetSubstring(2, varName->GetLength()-1); } else { isInstanceVar.AppendElement(kJTrue); } objNames->Append(varName); // callback (ignored) JIgnoreLine(input); // callback argument JString cbArg = JReadLine(input); RemoveIdentifier(kObjCBArgMarker, &cbArg); JString cbArgExtra; do { cbArgExtra = JReadLine(input); cbArgExtra.TrimWhitespace(); } while (!cbArgExtra.IsEmpty()); // don't bother to generate code for initial box // if it is FL_BOX, FLAT_BOX, FL_COL1 if (i==1 && flClass == "FL_BOX" && flType == "FLAT_BOX" && col1 == "FL_COL1") { rectList.RemoveElement(objCount); isInstanceVar.RemoveElement(objCount); objNames->DeleteElement(objCount); continue; } // check for errors -- safe since we have read in entire object JString hSizing, vSizing; if (!ParseGravity(nwGravity, &hSizing, &vSizing)) { cerr << "Illegal sizing specification "; cerr << nwGravity << ',' << seGravity; cerr << " for '" << *varName << '\'' << endl; rectList.RemoveElement(objCount); isInstanceVar.RemoveElement(objCount); objNames->DeleteElement(objCount); continue; } if (*varName == topEnclVarName) { cerr << "Cannot use reserved name '" << topEnclVarName << '\'' << endl; rectList.RemoveElement(objCount); isInstanceVar.RemoveElement(objCount); objNames->DeleteElement(objCount); continue; } // get the object's enclosure JIndex enclIndex; JString enclName; JRect localFrame = frame; if (GetEnclosure(rectList, objCount, &enclIndex)) { enclName = *(objNames->NthElement(enclIndex)); const JRect enclFrame = rectList.GetElement(enclIndex); localFrame.Shift(-enclFrame.topLeft()); } else { enclName = topEnclVarName; } // get the class name and additional arguments JString* className = new JString; assert( className != NULL ); objTypes->Append(className); JString argList; if (!GetConstructor(flClass, flType, &label, className, &argList)) { cerr << "Unsupported class: " << flClass << ", " << flType << endl; rectList.RemoveElement(objCount); isInstanceVar.RemoveElement(objCount); objNames->DeleteElement(objCount); objTypes->DeleteElement(objCount); continue; } // generate the actual code const JBoolean needCreate = NeedsCreateFunction(*className); output << " "; if (isLocal) { className->Print(output); output << "* "; } varName->Print(output); output << " =" << endl; output << " "; if (!needCreate) { output << "new "; } className->Print(output); if (needCreate) { output << "::Create"; } output << '('; if (!argList.IsEmpty()) { argList.Print(output); if (argList.GetLastCharacter() != ',') { output << ','; } output << ' '; } if (!cbArg.IsEmpty()) { cbArg.Print(output); if (cbArg.GetLastCharacter() != ',') { output << ','; } output << ' '; } if ((*className == "JXStaticText" && cbArg.IsEmpty()) || NeedsStringArg(*className)) { JString id = *varName; id += "::"; id += formName; id += "::"; id += tagName; // last since it is almost always the same output << "JGetString(\""; id.Print(output); output << "\"), "; stringMgr.SetElement(id, label, JPtrArrayT::kDelete); } enclName.Print(output); output << ',' << endl; output << " JXWidget::"; hSizing.Print(output); output << ", JXWidget::"; vSizing.Print(output); output << ", " << localFrame.left << ',' << localFrame.top << ", "; output << localFrame.width() << ',' << localFrame.height() << ");" << endl; output << " assert( "; varName->Print(output); output << " != NULL );" << endl; ApplyOptions(output, *className, formName, tagName, *varName, optionValues, lSize, lStyle, lColor, &stringMgr); if (*className == "JXStaticText" && cbArg.IsEmpty() && !lAlign.Contains("FL_ALIGN_TOP") && localFrame.height() <= 20) { output << " "; varName->Print(output); output << "->SetToLabel();" << endl; } output << endl; // now we know the object is valid objCount++; } // write string database JString dbFileName = stringPath + formName; if (tagName != kDefaultDelimTag) { dbFileName += kCustomTagMarker + tagName; } dbFileName += "_layout"; if (stringMgr.GetElementCount() > 0) { JEditVCS(dbFileName); ofstream dbOutput(dbFileName); stringMgr.WriteFile(dbOutput); } else { JRemoveVCS(dbFileName); JRemoveFile(dbFileName); } // reset enclosure size if (tagName != kDefaultDelimTag) { output << " "; topEnclVarName.Print(output); output << "->SetSize("; topEnclFrameName.Print(output); output << ".width(), "; topEnclFrameName.Print(output); output << ".height());" << endl; output << endl; } // throw away temporary variables objCount--; assert( objCount == isInstanceVar.GetElementCount() ); assert( objCount == objTypes->GetElementCount() ); assert( objCount == objNames->GetElementCount() ); for (i=objCount; i>=1; i--) { if (!isInstanceVar.GetElement(i)) { objTypes->DeleteElement(i); objNames->DeleteElement(i); } } }
int main(int argc, char **argv) { /* This function is the main function, called mondriaan. It partitions a sparse matrix, a dense input vector, and a dense output vector for the purpose of parallel sparse matrix-vector multiplication u = A*v. The function tries to minimise the total communication volume by suitably partitioning the matrix, while keeping the computation load imbalance withing a user-specified fraction epsilon. For the resulting communication volume, it tries to balance the communication work among the processors by suitably partitioning the vectors. The partitioning of the input and output vectors can either be done independently, or by imposing distr(u) = distr(v). The sparse matrix is read from file using the Matrix Market (MM) format. Its partitioning is written to file using a variant of the MM format, where all nonzeros belonging to the same processor are listed together. If the input file is called pi.mtx and 4 processors are required, the following output files are produced: pi.mtx-P4 containing the matrix distribution pi.mtx-v4 input vector distribution pi.mtx-u4 output vector distribution pi.mtx-C4 Cartesian submatrices corresponding to the matrix distribution Furthermore, useful information on the partitioning process and the result, such as the load imbalance and communication volume obtained, is written to standard output. The sparse matrix partitioner can also be used for partitioning hypergraphs. To do this, Mondriaan must be used in 1D column mode. Matrix columns then represent hypergraph vertices; they can be given integer weights. Matrix rows then represent hyperedges; they cannot be given weights. The following additional operations are carried out by the main program: - timing the matrix and vector partitionings - removing duplicate nonzeros - (optionally) checking whether the matrix is structurally symmetric - (optionally) expanding a symmetric matrix stored in lower triangular format to a fully stored matrix - (optionally) adding diagonal dummy nonzeros to a square matrix to make the diagonal completely nonzero (thereby facilitating the vector distribution with distr(u) = distr(v)). All partitioning options and parameters can be set using the file mondriaan.defaults (provided the main function is compiled with the name mondriaan.) If no such file exists, it is created with sensible defaults. If the input matrix has already been partitioned, it will be partitioned again, from scratch. */ struct opts Options; /* The Mondriaan options */ struct sparsematrix A; /* The Matrix;-) */ long MinNrNzElts, MaxNrNzElts; /* minimum, maximum number of nonzero elements per processor */ double AvgNrNzElts; /* average number of nonzero matrix elements per processor */ long MinWeight, MaxWeight, TotWeight; /* minimum, maximum, total column weight */ double AvgWeight; /* average column weight */ long weight, i, j; unsigned long int ui; long int *temp; long ComU, ComV; /* communication cost for vectors u, v */ long q, nzq; /* processor number and its corresponding number of nonzeros */ int weighted, symmetric; /* boolean registering whether the input matrix was weighted, symmetric */ long int *u_proc, *v_proc; /* vector distribution for u, v */ char output[MAX_WORD_LENGTH]; /* filename of the output */ char EMMcomment[2000]; /* Comments in EMM one-file output */ long int **row_perms = NULL, **col_perms = NULL; /* Will store local to global index info */ /* Below is used for Extended Matrix-Market one-file output */ long int *inv_count, **row_local2proc, **row_local2index, **col_local2proc, **col_local2index; FILE *File = NULL; char stdinName[] = "stdin"; /* Timing variables */ clock_t starttime, endtime; double cputime; #ifdef UNIX struct timeval starttime1, endtime1; #endif /* Get the parameters from the command line and initialise Options */ SetDefaultOptions(&Options); if (!SetOptionsFromFile(&Options, "Mondriaan.defaults")) { fprintf(stderr, "main(): warning, cannot set options from 'Mondriaan.defaults', using default options and creating standard 'Mondriaan.defaults'!\n"); File = fopen("Mondriaan.defaults", "w"); if (File != NULL) { ExportDefaultOptions(File); SetDefaultOptions(&Options); fclose(File); } else { fprintf(stderr, "main(): Unable to create 'Mondriaan.defaults'!\n"); } } if (!GetParameters(&Options, argc, argv)) { fprintf(stderr, "main(): invalid command line parameters!\n"); exit(-1); } if (!ApplyOptions(&Options)) { fprintf(stderr, "main(): could not apply given options!\n"); exit(-1); } /* Read matrix file from disk or standard input. */ if (!strcmp(Options.matrix, "-") || !strcmp(Options.matrix, "stdin")) { if (!MMReadSparseMatrix(stdin, &A)) { fprintf(stderr, "main(): Could not read matrix from standard input!\n"); exit(-1); } Options.matrix = stdinName; } else { File = fopen(Options.matrix, "r"); if (!File) { fprintf(stderr, "main(): Unable to open '%s' for reading!\n", Options.matrix); exit(-1); } if (!MMReadSparseMatrix(File, &A)) { fprintf(stderr, "main(): Could not read matrix!\n"); exit(-1); } fclose(File); } #ifdef INFO printf("\nUsing Mondriaan version %s.\n\n", MONDRIAANVERSION); printf("\n**************************************************************\n"); printf("Problem statistics:\n"); printf(" Matrix: : %s\n",Options.matrix); printf(" %s %s %s %s %s\n", A.Banner,A.Object,A.Format,A.Field,A.Symmetry); printf(" m = Nr rows : %ld\n", A.m); printf(" n = Nr columns : %ld\n", A.n); printf(" nz = Nr nonzeros : %ld\n", A.NrNzElts); /* Check if matrix A is structurally symmetric */ if (SparseMatrixStructurallySymmetric(&A)) printf(" Matrix is structurally symmetric\n\n"); else printf(" Matrix is structurally unsymmetric\n\n"); #endif /* Remove duplicate nonzeros by adding them */ if (!SparseMatrixRemoveDuplicates(&A)) { fprintf(stderr, "main(): Unable to remove duplicates!\n"); exit(-1); } /* Check if matrix A is already distributed */ if (A.MMTypeCode[0] == 'D') { /* Matrix will be partitioned again */ fprintf(stderr, "Warning: Matrix '%s' already distributed !\n", Options.matrix); fprintf(stderr, " (Ignoring current partitions)\n"); A.NrProcs = 0; if (A.Pstart != NULL) free(A.Pstart); A.Pstart = NULL; } /* Check if matrix is weighted (thus representing a hypergraph). In that case, it must have n column weights (representing vertex weights), 0 row weights and the split strategy must be onedimcol */ if (A.MMTypeCode[0] == 'W' && A.NrColWeights != A.n) { fprintf(stderr, "main(): Weighted matrix with NrColWeights != n!\n"); exit(-1); } if (A.MMTypeCode[0] == 'W' && A.NrRowWeights != 0) { fprintf(stderr, "Warning: Matrix '%s' has row weights!\n", Options.matrix); fprintf(stderr, " Row-weighted column partitioning not yet implemented\n"); fprintf(stderr, " (Ignoring row weights)\n"); A.NrRowWeights = 0; if (A.RowWeights != NULL) free(A.RowWeights); A.RowWeights = NULL; } if (A.MMTypeCode[0] == 'W' && Options.SplitStrategy != OneDimCol) { fprintf(stderr, "Warning: Matrix '%s' is a weighted matrix!\n", Options.matrix); fprintf(stderr, " must be partitioned by onedimcol strategy\n"); fprintf(stderr, " (Ignoring requested split strategy)\n"); Options.SplitStrategy = OneDimCol; } /* Register whether the input matrix was weighted, since the object type code will be changed by the partitioning procedure to the code 'D' for a distributed matrix */ if (A.MMTypeCode[0] == 'W') weighted = TRUE; else weighted = FALSE; /* Register whether the input matrix was symmetric, since the symmetry type code will be changed by the conversion to full, to the code 'G' for a general matrix */ if (A.m == A.n && (A.MMTypeCode[3]=='S' || A.MMTypeCode[3]=='K' || A.MMTypeCode[3]=='H')) { symmetric = TRUE; } else { symmetric = FALSE; if (Options.SplitStrategy == SFineGrain) { fprintf(stderr, "Error: Symmetric finegrain can only be used on symmetric input matrices!\n"); exit(-1); } } if (symmetric) { if (Options.SymmetricMatrix_UseSingleEntry == SingleEntNo) SparseMatrixSymmetric2Full(&A); else if (Options.SplitStrategy == SFineGrain) SparseMatrixSymmetricRandom2Lower(&A); else if (Options.SymmetricMatrix_SingleEntryType == ETypeRandom) SparseMatrixSymmetricLower2Random(&A); } if (Options.SplitStrategy == SFineGrain && Options.SymmetricMatrix_SingleEntryType == ETypeRandom) printf("Warning: Symmetric finegrain requires lower-triangular format of symmetric matrix;\n Random single entry type option is overridden.\n"); /* If the matrix is square, add the dummies if requested. This may lead to an enhanced vector distribution in the case of an equal distribution of the input and output vectors. */ if (A.m == A.n && Options.SquareMatrix_DistributeVectorsEqual == EqVecYes && Options.SquareMatrix_DistributeVectorsEqual_AddDummies == DumYes) AddDummiesToSparseMatrix(&A); /* Set the number of processors */ A.NrProcs = Options.P; #ifdef INFO printf(" P = Nr processors : %d\n", A.NrProcs); printf(" Nr dummies added : %ld\n", A.NrDummies); printf(" allowed imbalance : %g %c\n", 100*Options.eps, '%'); printf("\n****** Mondriaan matrix distribution ******\n\n"); #endif /* Initialise Pstart with all nonzeros in processor 0 */ A.Pstart = (long *) malloc((A.NrProcs+1) * sizeof(long)); if (A.Pstart == NULL) { fprintf(stderr, "main(): Not enough memory for Pstart!\n"); exit(-1); } A.Pstart[0] = 0; for (q = 1; q <= A.NrProcs; q++) A.Pstart[q] = A.NrNzElts; /**** Distribute the matrix (and time it) ****/ starttime = clock(); #ifdef UNIX gettimeofday(&starttime1, NULL); #endif if (!DistributeMatrixMondriaan(&A, A.NrProcs, Options.eps, &Options, 0)) { fprintf(stderr, "main(): Unable to distribute matrix!\n"); exit(-1); } endtime = clock(); #ifdef UNIX gettimeofday(&endtime1, NULL); #endif cputime = ((double) (endtime - starttime)) / CLOCKS_PER_SEC; #ifdef TIME printf(" matrix distribution CPU-time : %f seconds\n", cputime); #ifdef UNIX printf(" matrix distribution elapsed time: %f seconds\n", (endtime1.tv_sec - starttime1.tv_sec) + (endtime1.tv_usec - starttime1.tv_usec) / 1000000.0); #endif fflush(stdout); #endif /* Remove the dummies */ if (A.m == A.n && Options.SquareMatrix_DistributeVectorsEqual == EqVecYes && Options.SquareMatrix_DistributeVectorsEqual_AddDummies == DumYes) RemoveDummiesFromSparseMatrix(&A); /* Print information about the number of matrix elements */ AvgNrNzElts = (double) A.NrNzElts / A.NrProcs; MinNrNzElts = LONG_MAX; MaxNrNzElts = LONG_MIN; for (q = 0; q < A.NrProcs; q++) { nzq = A.Pstart[q+1] - A.Pstart[q]; if (nzq < MinNrNzElts) MinNrNzElts = nzq; if (nzq > MaxNrNzElts) MaxNrNzElts = nzq; } #ifdef INFO printf(" Nr nonzero matrix elements:\n"); printf(" tot : %ld \n", A.NrNzElts); printf(" avg = tot/P : %g \n", AvgNrNzElts); printf(" max : %ld \n", MaxNrNzElts); printf(" min : %ld \n", MinNrNzElts); printf(" imbalance : %g %c\n", 100 * (MaxNrNzElts/AvgNrNzElts - 1.0), '%'); #endif if (weighted){ A.MMTypeCode[0] = 'W'; /* temporarily, needed for computing weights */ TotWeight = ComputeWeight(&A, 0, A.NrNzElts-1, NULL, &Options); AvgWeight = (double) TotWeight / A.NrProcs; MinWeight = LONG_MAX; MaxWeight = LONG_MIN; for (q = 0; q < A.NrProcs; q++) { weight = ComputeWeight(&A, A.Pstart[q], A.Pstart[q+1]-1, NULL, &Options); if (weight < MinWeight) MinWeight = weight; if (weight > MaxWeight) MaxWeight = weight; } A.MMTypeCode[0] = 'D'; /* back to distributed matrix */ #ifdef INFO printf(" Vertex (column) weight:\n"); printf(" tot : %ld \n", TotWeight); printf(" avg = tot/P : %g \n", AvgWeight); printf(" max : %ld \n", MaxWeight); printf(" min : %ld \n", MinWeight); printf(" imbalance : %g %c\n", 100 * (MaxWeight/AvgWeight - 1.0), '%'); #endif } /* Convert randomly represented symmetric matrix to standard lower triangular form */ if (symmetric && Options.SymmetricMatrix_UseSingleEntry == SingleEntYes && Options.SymmetricMatrix_SingleEntryType == ETypeRandom) SparseMatrixSymmetricRandom2Lower(&A); /* Writing (distributed) matrix info */ if( Options.OutputMode == MultipleFiles ) { /* Write the distributed matrix to file */ sprintf(output, "%s-P%d", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); else { MMWriteSparseMatrix(&A, File, NULL, &Options); fclose(File); } /* Commit to permutation */ if (A.row_perm_inv != NULL && A.col_perm_inv != NULL) { for( i=0; i<A.NrNzElts; i++ ) { A.i[ i ] = A.row_perm_inv[ A.i[ i ] ]; A.j[ i ] = A.col_perm_inv[ A.j[ i ] ]; } } /* Write permuted matrix */ sprintf(output, "%s-reor-P%d", Options.matrix, A.NrProcs); File = fopen(output, "w"); A.MMTypeCode[0] = 'M'; if (!File) fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); else { MMWriteSparseMatrix(&A, File, NULL, &Options); fclose(File); } A.MMTypeCode[0] = 'D'; /* Write out block information */ if (A.rowBoundaries) { if (remembrance_get( A.rowBoundaries )==NULL) { fprintf(stderr, "main(): Error during read-out of row boundaries\n"); exit( -1 ); } sprintf(output, "%s-rowblocks%d", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); else { remembrance_write(A.rowBoundaries, File); fclose(File); } } if (Options.SplitStrategy != SFineGrain) if (A.colBoundaries) { if (remembrance_get( A.colBoundaries )==NULL) { fprintf(stderr, "main(): Error during read-out of column boundaries\n"); exit( -1 ); } sprintf(output, "%s-colblocks%d", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); else { remembrance_write(A.colBoundaries, File); fclose(File); } } /* Undo commit to permutation */ if (A.row_perm_inv != NULL && A.col_perm_inv != NULL) { for( i=0; i<A.NrNzElts; i++ ) { A.i[ i ] = A.row_perm[ A.i[ i ] ]; A.j[ i ] = A.col_perm[ A.j[ i ] ]; } } /* Write out local matrix format */ row_perms = malloc( (A.NrProcs+1) * sizeof( long int * ) ); col_perms = malloc( (A.NrProcs+1) * sizeof( long int * ) ); if( !row_perms || !col_perms || !SparseMatrixOriginal2Local(&A, row_perms, col_perms) ) { fprintf(stderr, "main(): Unable to transform to local view!"); exit(-1); } sprintf(output, "%s-local%d", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); else { MMWriteSparseMatrix(&A, File, NULL, &Options); fclose(File); } /* Transform matrix back */ for( i=0; i<A.NrProcs; i++ ) for(j=A.Pstart[i]; j<A.Pstart[i+1]; j++ ) { A.i[j] = row_perms[i][ A.i[j] ]; A.j[j] = col_perms[i][ A.j[j] ]; } A.ViewType = ViewTypeOriginal; /* Write out matrix the entries of which are processor indices. */ if (!MMInsertProcessorIndices(&A)) { fprintf(stderr, "main(): Unable to write processor indices!\n"); exit(-1); } A.MMTypeCode[0] = 'M'; sprintf(output, "%s-I%d", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); else { MMWriteSparseMatrix(&A, File, NULL, &Options); fclose(File); } A.MMTypeCode[0] = 'D'; /* Write out permutations. */ if (A.col_perm != NULL) { sprintf(output, "%s-col%d", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); else { WriteVector(A.col_perm, 0, NULL, A.n, 0, File, &Options); fclose(File); } } if (A.row_perm != NULL) { sprintf(output, "%s-row%d", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); else { WriteVector(A.row_perm, 0, NULL, A.m, 0, File, &Options); fclose(File); } } /* Free local to global index */ for( i=0; i<A.NrProcs+1; i++ ) { free( row_perms[i] ); free( col_perms[i] ); } free( row_perms ); free( col_perms ); } else if (Options.OutputMode == OneFile) { /* Extended MatrixMarket output */ if (Options.OutputFormat != OutputEMM) { fprintf(stderr, "main(): Single-file output requires EMM format!\n"); fprintf(stderr, " overriding output format to EMM.\n"); Options.OutputFormat = OutputEMM; } sprintf(EMMcomment, "%% File generated by running Mondriaan on A=%s with p=%d and \\epsilon=%f\n", Options.matrix, A.NrProcs, Options.eps); sprintf(EMMcomment, "%s%% Main matrix corresponds to the distributed version of A\n", EMMcomment); if (A.row_perm_inv != NULL && A.col_perm_inv != NULL) { switch( Options.OrderPermutation ) { case OrderPrefix: sprintf(EMMcomment, "%s%% This is followed by the (not-distributed) reverse Bordered Block Diagonal permuted matrix 'PAQ',\n", EMMcomment); break; case OrderPostfix: sprintf(EMMcomment, "%s%% This is followed by the (not-distributed) Bordered Block Diagonal permuted matrix 'PAQ',\n", EMMcomment); break; default: sprintf(EMMcomment, "%s%% This is followed by the (not-distributed) Separated Block Diagonal permuted matrix 'PAQ',\n", EMMcomment); } sprintf(EMMcomment, "%s%% followed by the row-block boundary vector 'Row-boundaries',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by the row-block hierarchy vector 'Row-hierarchy',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by the column-block boundary vector 'Column-boundaries',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by the column-block hierarchy vector 'Column-hierarchy',\n", EMMcomment); } sprintf(EMMcomment, "%s%% followed by a local view of the distributed form of A 'Local-A',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by a mapping of local row indices to global row indices 'LocalRow2Global',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by a mapping of local column indices to global column indices 'LocalCol2Global',\n", EMMcomment); if (A.row_perm != NULL) sprintf(EMMcomment, "%s%% followed by the row permutation vector corresponding to P in PAQ 'Row-permutation',\n", EMMcomment); if (A.col_perm != NULL) sprintf(EMMcomment, "%s%% followed by the column permutation vector corresponding to Q in PAQ 'Column-permutation',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by the input vector distribution 'Input-vector',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by the output vector distribution 'Output-vector',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by the local lengths of the output vectors 'OutputVectorLengths',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by the matrix row index to output vector processor ID mapping 'LocalRow2Processor',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by the matrix row index to output vector index mapping 'LocalRow2Index',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by the matrix column index to input vector processor ID mapping 'LocalCol2Processor',\n", EMMcomment); sprintf(EMMcomment, "%s%% followed by the matrix column index to input vector index mapping 'LocalCol2Index'.\n", EMMcomment); A.comment = EMMcomment; sprintf(output, "%s-P%d.emm", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) { fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); exit( -1 ); } MMWriteSparseMatrix(&A, File, NULL, &Options); /* Commit to permutation */ if (A.row_perm_inv != NULL && A.col_perm_inv != NULL) { for( i=0; i<A.NrNzElts; i++ ) { A.i[ i ] = A.row_perm_inv[ A.i[ i ] ]; A.j[ i ] = A.col_perm_inv[ A.j[ i ] ]; } } /* Write permuted matrix */ A.MMTypeCode[0] = 'M'; MMWriteSparseMatrix(&A, File, "PAQ", &Options); A.MMTypeCode[0] = 'D'; /* Write out block information */ if (A.rowBoundaries) { if (remembrance_get( A.rowBoundaries )==NULL) { fprintf(stderr, "main(): Error during read-out of row boundaries\n"); exit( -1 ); } temp = malloc(A.rowBoundaries->size * sizeof( long int )); for(ui=0; ui<A.rowBoundaries->size; ui++) temp[ ui ] = A.rowBoundaries->vector[ ui ].index; WriteVector(temp, 0, "Row-boundaries", A.rowBoundaries->size, 0, File, &Options); for(ui=0; ui<A.rowBoundaries->size-1; ui++ ) temp[ ui ] = A.rowBoundaries->vector[ ui ].parent == ULONG_MAX ? 0 : A.rowBoundaries->vector[ ui ].parent + 1; WriteVector(temp, 1, "Row-hierarchy", A.rowBoundaries->size-1, 0, File, &Options); free(temp); } if (Options.SplitStrategy != SFineGrain) { if (A.colBoundaries) { if (remembrance_get( A.colBoundaries )==NULL) { fprintf(stderr, "main(): Error during read-out of column boundaries\n"); exit( -1 ); } temp = malloc( A.colBoundaries->size * sizeof( long int ) ); for(ui=0; ui<A.colBoundaries->size; ui++) temp[ ui ] = A.colBoundaries->vector[ ui ].index; WriteVector(temp, 0, "Col-boundaries", A.colBoundaries->size, 0, File, &Options); for(ui=0; ui<A.colBoundaries->size-1; ui++ ) temp[ ui ] = A.colBoundaries->vector[ ui ].parent == ULONG_MAX ? 0 : A.colBoundaries->vector[ ui ].parent + 1; WriteVector(temp, 1, "Col-hierarchy", A.colBoundaries->size-1, 0, File, &Options); free(temp); } } /* Write out local matrix format */ row_perms = malloc( (A.NrProcs+1) * sizeof( long int * ) ); col_perms = malloc( (A.NrProcs+1) * sizeof( long int * ) ); if( !row_perms || !col_perms || !SparseMatrixOriginal2Local(&A, row_perms, col_perms) ) { fprintf(stderr, "main(): Unable to transform to local view!"); exit(-1); } MMWriteSparseMatrix(&A, File, "Local-A", &Options); /* Transform matrix back from Local to global view */ for( i=0; i<A.NrProcs; i++ ) for(j=A.Pstart[i]; j<A.Pstart[i+1]; j++ ) { A.i[j] = row_perms[i][ A.i[j] ]; A.j[j] = col_perms[i][ A.j[j] ]; } A.ViewType = ViewTypeOriginal; /* Permutate row_perms and col_perms so that they point * to global indices (corresponding to A) instead of * permuted indices (corresponding to PAQ). for( i=0; i<A.NrProcs; i++ ) { for( j=0; j<row_perms[A.NrProcs][i]; j++ ) row_perms[i][j] = row_perms[i][j]; for( j=0; j<col_perms[A.NrProcs][i]; j++ ) col_perms[i][j] = col_perms[i][j]; } */ WriteVectorCollection(row_perms, "LocalRow2Global", A.NrProcs, row_perms[A.NrProcs], File); WriteVectorCollection(col_perms, "LocalCol2Global", A.NrProcs, col_perms[A.NrProcs], File); /* Write out matrix the entries of which are processor indices */ /*if (!MMInsertProcessorIndices(&A)) { fprintf(stderr, "main(): Unable to write processor indices!\n"); exit(-1); } A.MMTypeCode[0] = 'M'; tempchar = A.MMTypeCode[2]; A.MMTypeCode[2] = 'I'; MMWriteSparseMatrix(&A, File, "Global-A", &Options); A.MMTypeCode[0] = 'D'; A.MMTypeCode[2] = tempchar;*/ /* Write out permutations */ if (A.row_perm != NULL) { WriteVector(A.row_perm, 0, "Row-permutation", A.m, 0, File, &Options); } if (A.col_perm != NULL) { WriteVector(A.col_perm, 0, "Column-permutation", A.n, 0, File, &Options); } } else if (Options.OutputMode == DIMACS) { /* For DIMACS we only need the vector distribution. */ } else { fprintf(stderr, "main(): Unknown output mode!\n" ); exit( -1 ); } /* Convert symmetrically partitioned, symmetric matrix to full form for vector distribution */ if (symmetric && Options.SymmetricMatrix_UseSingleEntry == SingleEntYes) { /* Some of the above transformations can make A arbitrary symmetric instead of lower-traingular */ SparseMatrixSymmetricRandom2Lower(&A); SparseMatrixSymmetric2Full(&A); /* now A.MMTypeCode[3]='G' */ /* Print information about the number of matrix elements */ AvgNrNzElts = (double) A.NrNzElts / A.NrProcs; MinNrNzElts = LONG_MAX; MaxNrNzElts = LONG_MIN; for (q = 0; q < A.NrProcs; q++) { nzq = A.Pstart[q+1] - A.Pstart[q]; if (nzq < MinNrNzElts) MinNrNzElts = nzq; if (nzq > MaxNrNzElts) MaxNrNzElts = nzq; } #ifdef INFO printf(" After conversion of distributed symmetric matrix to" " distributed full matrix\n"); printf(" Nr matrix elements:\n"); printf(" tot : %ld \n", A.NrNzElts); printf(" avg = tot/P : %g \n", AvgNrNzElts); printf(" max : %ld \n", MaxNrNzElts); printf(" min : %ld \n", MinNrNzElts); printf(" imbalance : %g %c\n", 100 * (MaxNrNzElts / AvgNrNzElts - 1.0), '%'); /* vertex weight information is not printed, since it is not meaningful here */ #endif } #ifdef INFO printf("\n****** Mondriaan vector distribution ******\n"); #endif /* Allocate memory for processor numbers for the vector components, for u = A*v with A an m by n matrix */ u_proc = (long int *) malloc(A.m * sizeof(long int)); v_proc = (long int *) malloc(A.n * sizeof(long int)); if (u_proc == NULL || v_proc == NULL) { fprintf(stderr, "main(): Not enough memory for vectors u_proc and v_proc!\n"); exit(-1); } /**** Distribute the vector (and time it) ****/ starttime = clock(); #ifdef UNIX gettimeofday(&starttime1, NULL); #endif if (A.m == A.n && Options.SquareMatrix_DistributeVectorsEqual == EqVecYes) { /* Distribute the vectors equally */ if (symmetric && Options.SymmetricMatrix_UseSingleEntry == SingleEntYes) { /* Distribute v independently, and then use the same distribution for u */ ComV = DistributeVec(&A, v_proc, ROW, &Options); if (ComV < 0) { fprintf(stderr, "main(): Unable to distribute vectors!\n"); exit(-1); } for (i = 0; i < A.m; i++) u_proc[i] = v_proc[i]; ComU = ComV; #ifdef INFO printf("\nCommunication results for u are the same as for v\n"); printf("but with sends and receives reversed\n\n"); #endif } else { /* Distribute u and v together */ ComU = DistributeVecOrigEq(&A, u_proc, v_proc, &Options); if (ComU < 0) { fprintf(stderr, "main(): Unable to distribute vectors!\n"); exit(-1); } ComV = 0; } } else { /* Distribute the vectors independently */ ComV = DistributeVec(&A, v_proc, ROW, &Options); if (ComV < 0) { fprintf(stderr, "main(): Unable to distribute input vector!\n"); exit(-1); } ComU = DistributeVec(&A, u_proc, COL, &Options); if (ComU < 0) { fprintf(stderr, "main(): Unable to distribute output vector!\n"); exit(-1); } } endtime = clock(); #ifdef UNIX gettimeofday(&endtime1, NULL); #endif cputime = ((double) (endtime - starttime)) / CLOCKS_PER_SEC; #ifdef TIME printf(" vector distribution CPU-time : %f seconds\n", cputime); #ifdef UNIX printf(" vector distribution elapsed time : %f seconds\n", (endtime1.tv_sec - starttime1.tv_sec) + (endtime1.tv_usec - starttime1.tv_usec) / 1000000.0); #endif fflush(stdout); #endif #ifdef INFO printf("\nCommunication cost for u = A v: %ld (%g) \n", ComU + ComV, ((double) ComU / A.m + (double) ComV / A.n) /2); fflush(stdout); #endif /* Write vector info */ if (Options.OutputMode == MultipleFiles) { /* Write the vector distribution to file */ sprintf(output, "%s-u%d", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); else { WriteVectorDistribution(u_proc, NULL, A.m, A.NrProcs, File, &Options); fclose(File); } sprintf(output, "%s-v%d", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); else { WriteVectorDistribution(v_proc, NULL, A.n, A.NrProcs, File, &Options); fclose(File); } } else if (Options.OutputMode == OneFile) { /* Write the vector distribution to file */ WriteVectorDistribution(v_proc, "Input-vector", A.n, A.NrProcs, File, &Options); WriteVectorDistribution(u_proc, "Output-vector", A.m, A.NrProcs, File, &Options); /* LocalRow2Processor */ inv_count = NULL; row_local2proc = row_local2index = col_local2proc = col_local2index = NULL; if(!SparseMatrixLocal2Vector(&A, row_perms, u_proc, &inv_count, &row_local2proc, &row_local2index, 0)) { fprintf(stderr, "Error during derivation of local index arrays for SpMV multiplication (row direction)\n"); exit(-1); } WriteVector(inv_count, 0, "OutputVectorLengths", A.NrProcs, 0, File, &Options); WriteVectorCollection(row_local2proc, "LocalRow2Processor", A.NrProcs, row_perms[A.NrProcs], File); WriteVectorCollection(row_local2index, "LocalRow2Index", A.NrProcs, row_perms[A.NrProcs], File); for( i=0; i<A.NrProcs; i++ ) { free( row_local2proc[i] ); free( row_local2index[i] ); } free( row_local2proc ); free( row_local2index ); /* LocalCol2Processor */ free(inv_count); if(!SparseMatrixLocal2Vector(&A, col_perms, v_proc, &inv_count, &col_local2proc, &col_local2index, 1)) { fprintf(stderr, "Error during derivation of local index arrays for SpMV multiplication (column direction)\n"); exit(-1); } WriteVector(inv_count, 0, "InputVectorLengths", A.NrProcs, 0, File, &Options); WriteVectorCollection(col_local2proc, "LocalCol2Processor", A.NrProcs, col_perms[A.NrProcs], File); WriteVectorCollection(col_local2index, "LocalCol2Index", A.NrProcs, col_perms[A.NrProcs], File); for( i=0; i<A.NrProcs; i++ ) { free( col_local2proc[i] ); free( col_local2index[i] ); } free( col_local2proc ); free( col_local2index ); free(inv_count); /* Also free local to global index */ for( i=0; i<A.NrProcs+1; i++ ) { free( row_perms[i] ); free( col_perms[i] ); } free( row_perms ); free( col_perms ); fclose(File); } else if (Options.OutputMode == DIMACS) { if (A.m != A.n || Options.SquareMatrix_DistributeVectorsEqual != EqVecYes) { fprintf(stderr, "main(): Unequal vector distributions in DIMACS mode!\n"); } /* Only write the vector distribution to disk. */ sprintf(output, "%s%d.part", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) { fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); } else { for (i = 0; i < A.m; i++) fprintf(File, "%ld\n", u_proc[i]); fclose(File); } } if (Options.OutputMode == MultipleFiles) { /* Write the index sets of the Cartesian submatrices to file */ sprintf(output, "%s-C%d", Options.matrix, A.NrProcs); File = fopen(output, "w"); if (!File) fprintf(stderr, "main(): Unable to open '%s' for writing!\n", output); else { MMWriteCartesianSubmatrices(&A, File); fclose(File); } } /* Free memory */ MMDeleteSparseMatrix(&A); free(v_proc); free(u_proc); /* Exit :) */ exit(0); } /* end main */
int main(int argc, char **argv) { struct opts Options; int i; time_t CurrentTime; clock_t TotalClock = clock(); /* Apply Mondriaan options. */ SetDefaultOptions(&Options); if (!SetOptionsFromFile(&Options, "Mondriaan.defaults")) { fprintf(stderr, "main(): warning, cannot set options from 'Mondriaan.defaults', using default options!\n"); } if (!ParseCommandLineOptions(&Options, argc, argv)) { fprintf(stderr, "main(): invalid command line parameters!\n"); exit(EXIT_FAILURE); } if (!ApplyOptions(&Options)) { fprintf(stderr, "main(): could not apply given options!\n"); exit(EXIT_FAILURE); } if (NumMatrices <= 0 || Matrices == NULL) { fprintf(stderr, "main(): Invalid number of supplied matrices or samples!\n"); exit(EXIT_FAILURE); } /* Start profiling ... */ fprintf(stderr, "Profiling Mondriaan for %d matrices, %d samples, %s processors, and %f imbalance.\n", NumMatrices, NumSamples, argv[1], Options.eps); for (i = 0; i < NumMatrices*NumNumProcs; ++i) { int j; fprintf(stderr, "[% 4d/%d] (% 4ld) %s ", i + 1, NumMatrices*NumNumProcs, Matrices[i].P, Matrices[i].File); fflush(stderr); if (!SetupAttributes(&Matrices[i])) { fprintf(stderr, "main(): Cannot setup attributes!\n"); exit(EXIT_FAILURE); } Options.P = Matrices[i].P; /* Take the requested number of samples. */ for (j = 0; j < NumSamples; ++j) { struct sparsematrix A; long int *UAssign, *VAssign, Symmetric; FILE *File; long l; int k; clock_t Clock; double Duration; long MaxNz, MinNz; long MaxComU, MaxComV, ComVolU, ComVolV; fprintf(stderr, "."); fflush(stderr); /* Read matrix from disk. */ File = fopen(Matrices[i].File, "r"); if (!File) { fprintf(stderr, "main(): Could not open '%s' for reading!\n", Matrices[i].File); exit(EXIT_FAILURE); } if (!MMReadSparseMatrix(File, &A)) { fprintf(stderr, "main(): Could not read matrix!\n"); exit(EXIT_FAILURE); } fclose(File); /* Remove double zeroes. */ if (!SparseMatrixRemoveDuplicates(&A)) exit(EXIT_FAILURE); /* Check symmetry. */ if (A.m == A.n && (A.MMTypeCode[3] == 'S' || A.MMTypeCode[3] == 'K' || A.MMTypeCode[3] == 'H')) Symmetric = TRUE; else Symmetric = FALSE; if (Symmetric) { if (Options.SymmetricMatrix_UseSingleEntry == SingleEntNo) SparseMatrixSymmetric2Full(&A); else if (Options.SymmetricMatrix_SingleEntryType == ETypeRandom) SparseMatrixSymmetricLower2Random(&A); } /* Add dummies if requested. */ if (A.m == A.n && Options.SquareMatrix_DistributeVectorsEqual == EqVecYes && Options.SquareMatrix_DistributeVectorsEqual_AddDummies == DumYes) AddDummiesToSparseMatrix(&A); /* Initialise processor array. */ A.NrProcs = Options.P; A.Pstart = (long *)malloc((A.NrProcs + 1)*sizeof(long)); if (A.Pstart == NULL) { fprintf(stderr, "main(): Cannot allocate processor array!\n"); exit(EXIT_FAILURE); } A.Pstart[0] = 0; for (k = 1; k <= A.NrProcs; ++k) { A.Pstart[k] = A.NrNzElts; } /* Distribute the processors among the matrix entries. */ SetRandomSeed(Options.Seed = 137*j + 12345); /* ==== Start Mondriaan */ Clock = clock(); if (!DistributeMatrixMondriaan(&A, Options.P, Options.eps, &Options, NULL)) { fprintf(stderr, "main(): Unable to distribute matrix!\n"); exit(EXIT_FAILURE); } /* Remove dummies. */ if (A.m == A.n && Options.SquareMatrix_DistributeVectorsEqual == EqVecYes && Options.SquareMatrix_DistributeVectorsEqual_AddDummies == DumYes) RemoveDummiesFromSparseMatrix(&A); /* Convert randomly represented matrix to lower triangular form. */ if (Symmetric && Options.SymmetricMatrix_UseSingleEntry == SingleEntYes && Options.SymmetricMatrix_SingleEntryType == ETypeRandom) SparseMatrixSymmetricRandom2Lower(&A); /* Distribute vectors. */ UAssign = (long int *)malloc(A.m*sizeof(long int)); VAssign = (long int *)malloc(A.n*sizeof(long int)); if (UAssign == NULL || VAssign == NULL) { fprintf(stderr, "main(): Cannot allocate vertex assign arrays!\n"); exit(EXIT_FAILURE); } /* Convert symmetrically partitioned matrix to full form. */ if (Symmetric && Options.SymmetricMatrix_UseSingleEntry == SingleEntYes) SparseMatrixSymmetric2Full(&A); if (A.m == A.n && Options.SquareMatrix_DistributeVectorsEqual == EqVecYes) { if (Symmetric && Options.SymmetricMatrix_UseSingleEntry == SingleEntYes) { MaxComV = DistributeVec(&A, VAssign, ROW, &Options); if (MaxComV < 0) { fprintf(stderr, "main(): Unable to distribute vector!\n"); exit(EXIT_FAILURE); } for (k = 0; k < A.m; k++) { UAssign[k] = VAssign[k]; } MaxComU = MaxComV; } else { MaxComU = DistributeVecOrigEq(&A, UAssign, VAssign, &Options); if (MaxComU < 0) { fprintf(stderr, "main(): Unable to distribute vector!\n"); exit(EXIT_FAILURE); } MaxComV = 0; } } else { MaxComV = DistributeVec(&A, VAssign, ROW, &Options); MaxComU = DistributeVec(&A, UAssign, COL, &Options); if (MaxComV < 0 || MaxComU < 0) { fprintf(stderr, "main(): Unable to distribute vector!\n"); exit(EXIT_FAILURE); } } /* ==== Stop Mondriaan */ /* Calculate duration. */ Duration = (double)(clock() - Clock)/(double)CLOCKS_PER_SEC; /* Determine minimum and maximum number of assigned nonzeroes. */ MaxNz = MinNz = A.Pstart[1] - A.Pstart[0]; for (k = 1; k < A.NrProcs; ++k) { l = A.Pstart[k + 1] - A.Pstart[k]; if (l > MaxNz) MaxNz = l; if (l < MinNz) MinNz = l; } /* Calculate communication volume. */ if (!CalcCom(&A, VAssign, ROW, &ComVolV, &l, &l, &l, &l) || !CalcCom(&A, UAssign, COL, &ComVolU, &l, &l, &l, &l)) { fprintf(stderr, "main(): Unable to calculate communication volume!\n"); exit(EXIT_FAILURE); } /* Store attributes. */ Matrices[i].NumNz = A.NrNzElts; Matrices[i].Rows = A.m; Matrices[i].Cols = A.n; Matrices[i].Attributes[0].Data[j] = Duration; Matrices[i].Attributes[1].Data[j] = (double)(Options.P*MaxNz - A.NrNzElts)/(double)A.NrNzElts; Matrices[i].Attributes[2].Data[j] = (double)(MaxComV + MaxComU); Matrices[i].Attributes[3].Data[j] = (double)(ComVolV + ComVolU); /* Free memory. */ MMDeleteSparseMatrix(&A); free(UAssign); free(VAssign); } /* Average attributes. */ if (!AverageAndFreeAttributes(&Matrices[i])) { fprintf(stderr, "main(): Cannot setup attributes!\n"); exit(EXIT_FAILURE); } fprintf(stderr, "\n"); } /* Write accumulated data to stdout. */ fprintf(stderr, "Finished profiling, writing data ...\n"); printf("%% Profiled Mondriaan for %d matrices, %d samples, and %f imbalance.\n", NumMatrices, NumSamples, Options.eps); printf("\\documentclass[a4paper, 10pt]{article}\n\n"); printf("\\usepackage{lscape}\n"); printf("\\usepackage{longtable}\n\n"); printf("\\author{\\texttt{Profile.c}}\n"); CurrentTime = time(NULL); printf("\\date{%s}\n", asctime(localtime(&CurrentTime))); printf("\\title{Profiling Mondriaan %s with %d %s}\n\n", MONDRIAANVERSION, NumMatrices, NumMatrices > 1 ? "matrices" : "matrix"); printf("\\begin{document}\n\n"); printf("\\maketitle\n\n"); printf("\\section{Results}\n\n"); printf("Used Mondriaan version %s to distribute %d matrices (listed in table \\ref{MondriaanMatrices}) over %d processors with maximum imbalance %f, taking the average of %d samples. The used options can be found in table \\ref{MondriaanSettings} en the numerical results in table \\ref{MondriaanResults}.\n", MONDRIAANVERSION, NumMatrices, Options.P, Options.eps, NumSamples); printf("This took %.1f minutes in total.\n\n", (double)(clock() - TotalClock)/(60.0*(double)CLOCKS_PER_SEC)); /* Export options. */ printf("\\begin{table}\n"); printf("\\caption{Mondriaan configuration.}\n"); printf("\\label{MondriaanSettings}\n"); printf("\\begin{center}\n"); if (!ExportOptionsToLaTeX(stdout, &Options)) { fprintf(stderr, "main(): Unable to create option table!\n"); exit(EXIT_FAILURE); } printf("\\end{center}\n"); printf("\\end{table}\n\n"); /* Export list of test matrices. */ printf("\\begin{table}\n"); printf("\\caption{%d tested matrices.}\n", NumMatrices); printf("\\label{MondriaanMatrices}\n"); printf("\\begin{center}\n"); printf("\\begin{tabular}{l|lll}\nFile & $\\mathit{nz}$ & $m$ & $n$ \\\\\n\\hline\n"); for (i = 0; i < NumMatrices*NumNumProcs; i += NumNumProcs) { printf("\\verb|%s| & %ld & %ld & %ld \\\\\n", Matrices[i].File, Matrices[i].NumNz, Matrices[i].Rows, Matrices[i].Cols); } printf("\\hline\n"); printf("\\end{tabular}\n"); printf("\\end{center}\n"); printf("\\end{table}\n\n"); /* Export test data. */ printf("\\begin{landscape}\n"); printf("\\begin{longtable}{lrrrrr}"); printf("\\caption[Profile results]{Profile results for %d matrices.}\n", NumMatrices); printf("\\label{MondriaanResults} \\\\\n\n"); printf("\\multicolumn{1}{c}{File} & \\multicolumn{1}{c}{$p$} & \\multicolumn{1}{c}{Time (s)} & \\multicolumn{1}{c}{$\\varepsilon$} & \\multicolumn{1}{c}{Max. com.} & \\multicolumn{1}{c}{Com. vol.} \\\\ \\hline\n"); printf("\\endfirsthead\n\n"); printf("\\multicolumn{6}{c}{\\tablename\\ \\thetable{} -- continued from previous page.} \\\\\n"); printf("\\multicolumn{1}{c}{File} & \\multicolumn{1}{c}{$p$} & \\multicolumn{1}{c}{Time (s)} & \\multicolumn{1}{c}{$\\varepsilon$} & \\multicolumn{1}{c}{Max. com.} & \\multicolumn{1}{c}{Com. vol.} \\\\ \\hline\n"); printf("\\endhead\n\n"); printf("\\multicolumn{6}{c}{Continued on next page.} \\\\\n"); printf("\\endfoot\n\n"); printf("\\hline\n\\endlastfoot\n\n"); for (i = 0; i < NumMatrices*NumNumProcs; i += NumNumProcs) { int j; for (j = 0; j < NumNumProcs; ++j) { char Tmp[256]; const struct sMatrixData *Mat = &Matrices[i + j]; if (j == 0) printf("\\verb|%s| & %ld", Mat->File, Mat->P); else printf(" & %ld", Mat->P); /* int k; for (k = 0; k < NUM_ATTRIBUTES; ++k) { char Tmp[256]; DoubleToLaTeX(Tmp, Mat->Attributes[k].Average, 3); printf(" & $%s \\pm ", Tmp); DoubleToLaTeX(Tmp, sqrt(Mat->Attributes[k].Variance), 1); printf("%s$", Tmp); } */ DoubleToLaTeX(Tmp, Mat->Attributes[0].Average, 3); printf(" & $%s \\pm ", Tmp); DoubleToLaTeX(Tmp, sqrt(Mat->Attributes[0].Variance), 1); printf("%s$", Tmp); DoubleToLaTeX(Tmp, Mat->Attributes[1].Average, 3); printf(" & $%s$", Tmp); printf(" & $%ld \\pm %ld$", (long)Mat->Attributes[2].Average, (long)sqrt(Mat->Attributes[2].Variance)); printf(" & $%ld \\pm %ld$", (long)Mat->Attributes[3].Average, (long)sqrt(Mat->Attributes[3].Variance)); printf(" \\\\\n"); } printf("\\hline\n"); } printf("\n\\end{longtable}\n"); printf("\\end{landscape}\n\n"); printf("\\end{document}\n\n"); /* Append raw data. */ printf("Raw data:\n"); for (i = 0; i < NumMatrices*NumNumProcs; ++i) { int j; printf("%s\t%ld\t%ld\t%ld\t%ld\t", Matrices[i].File, Matrices[i].NumNz, Matrices[i].Rows, Matrices[i].Cols, Matrices[i].P); for (j = 0; j < NUM_ATTRIBUTES - 1; ++j) printf("%e\t%e\t", Matrices[i].Attributes[j].Average, sqrt(Matrices[i].Attributes[j].Variance)); printf("%e\t%e\n", Matrices[i].Attributes[j].Average, sqrt(Matrices[i].Attributes[j].Variance)); } printf("\n"); free(Matrices); fprintf(stderr, "Done!\n"); exit(EXIT_SUCCESS); }
void CMainFrame::SetOptions(const COptionsInfo& Options) { COptionsInfo PrevOpts(m_Options); m_Options = Options; ApplyOptions(PrevOpts); }