void XC::Graph::copy(const Graph &other) { const size_t numVertex= other.getNumVertex(); if(numVertex>0) { inic(numVertex); Graph &other_no_const= const_cast<Graph &>(other); VertexIter &otherVertices= other_no_const.getVertices(); Vertex *vertexPtr= nullptr; // loop through other creating vertices if tag not the same in this while((vertexPtr = otherVertices()) != nullptr) { const int vertexTag= vertexPtr->getTag(); const int vertexRef= vertexPtr->getRef(); Vertex newVertex(vertexTag, vertexRef); this->addVertex(newVertex, false); } // loop through other adding all the edges that exist in other VertexIter &otherVertices2 = other_no_const.getVertices(); while((vertexPtr = otherVertices2()) != nullptr) { int vertexTag = vertexPtr->getTag(); const std::set<int> &adjacency= vertexPtr->getAdjacency(); for(std::set<int>::const_iterator i=adjacency.begin(); i!=adjacency.end(); i++) { if(this->addEdge(vertexTag, *i) < 0) { std::cerr << "Graph::" << __FUNCTION__ << "; could not add an edge!\n"; return; } } } } else { inic(32); numEdge= 0; nextFreeTag= START_VERTEX_NUM; } theVertexIter= VertexIter(&myVertices); }
void main(void) { char cadena[MAXTAM]; introduce(cadena); inic(cadena); fin(cadena); inter(cadena); puts(cadena); printf("\nLA CADENA TIENE %d PALABRAS", contar(cadena)); }
int main (int argc, char * const argv[]) { int red[2], green[2], blue[2], ret[2]; int id, leido, opcion, channel = NOSET; int inputfd = STDIN_FILENO, outfd = STDOUT_FILENO; u_char buff[768] = {}; char * inputfile = NULL; char * outputfile = NULL; char * header = NULL; extern char * optarg; extern int optind, opterr, optopt; while ((opcion = getopt(argc, argv, "hc:a:o:") ) >= 0) { switch(opcion) { case 'h': write(STDOUT_FILENO, "Usage: hist [OPTION...]\n -h, show this help and exit\n -a <ppm-file>, use ppm-file file\n -c <rojo/verde/azul>, show only the result for selected colour\n -o <file-name>, create a file named file-name and stores the results\n", 249); return 0; break; case 'o': if ((outfd = open(optarg, O_CREAT | O_RDWR | O_TRUNC, 0640)) == -1) { perror("open"); return -3; } outputfile = malloc(sizeof (char) * strlen(optarg)); strcpy(outputfile, optarg); break; case 'a': if ((inputfd = open(optarg, O_RDONLY)) == -1) { perror("open"); return -3; } inputfd = setpointer(inputfd, optarg); inputfile = malloc(sizeof (char) * strlen(optarg)); strcpy(inputfile, optarg); break; case 'c': if (!strcmp("rojo", optarg)) channel = RED; else if (!strcmp("verde", optarg)) channel = GREEN; else if (!strcmp("azul", optarg)) channel = BLUE; else { write(STDERR_FILENO, "Wrong argument\n", 15); return -3; } break; case '?': write(STDERR_FILENO, "Missing argument\n", 17); return -2; break; } } if (inputfd == STDIN_FILENO) { write(STDERR_FILENO, "No input file\n", 14); return -4; } header = malloc(sizeof (char) * 256); sprintf(header, "File read: %s\n", inputfile); if (outputfile != NULL) sprintf(header, "%sOutput file: %s\n", header, outputfile); if (channel == NOSET) sprintf(header, "%sChannels analized: all\n\n", header); if (channel == RED) sprintf(header, "%sChannel analized: red\n\n", header); if (channel == GREEN) sprintf(header, "%sChannel analized: green\n\n", header); if (channel == BLUE) sprintf(header, "%sChannel analized: blue\n\n", header); write(outfd,header,strlen(header)); id = inic(red, green, blue, ret, channel); switch(id) { case RED: while ((leido = read(red[0], buff, 768)) > 0) { if (analize(RED, ret[1], leido, buff) != 0) return -1; } return 0; break; case GREEN: while ((leido = read(green[0], buff, 768)) > 0) { if (analize(GREEN, ret[1], leido, buff) != 0) return -1; } return 0; break; case BLUE: while ((leido = read(blue[0], buff, 768)) > 0) { if (analize(BLUE, ret[1], leido, buff) != 0) return -1; } return 0; break; } u_char r[257]; char outTxt[50]; int pix[3][256], i, j, status; for(i = 0 ; i < 3 ; i++ ) for(j = 0; j < 256; j++ ) pix[i][j] = 0; while ((leido = read(inputfd, buff, 768)) > 0) { if (leido == -1) { perror("read"); return -9; } if (channel == RED || channel == NOSET) write(red[1], buff, leido); if (channel == GREEN || channel == NOSET) write(green[1], buff, leido); if (channel == BLUE || channel == NOSET) write(blue[1], buff, leido); for(j = 0 ; j < 3 ; j++) { if (channel != NOSET) j += 2; leido = read(ret[0],r,257); for (i=1; i<257; i++) { pix [ r[0] ] [i-1] += (int) r[i]; } } } if (channel == RED || channel == NOSET) close(red[1]); if (channel == GREEN || channel == NOSET) close(green[1]); if (channel == BLUE || channel == NOSET) close(blue[1]); for(i = 0 ; i < 2 ; i++ ) { if (channel != NOSET) i += 2; wait(&status); if (WIFEXITED(status)) { if (WEXITSTATUS(status) != 0) write(STDERR_FILENO, "Child ended with error\n", 23); } else write(STDERR_FILENO, "Child ended signalized\n", 17); } switch (channel) { case NOSET: for (i = 0 ; i < 256 ; i++) { sprintf(outTxt, "red[%3d]=%d\t\tgreen[%3d]=%d\t\tblue[%3d]=%d\n", i, pix[0][i], i, pix[1][i], i, pix[2][i]); write(outfd, outTxt, strlen(outTxt)); } break; case RED: for (i = 0 ; i < 256 ; i++) { sprintf(outTxt, "red[%3d]=%d\n", i, pix[0][i]); write(outfd, outTxt, strlen(outTxt)); } break; case GREEN: for (i = 0 ; i < 256 ; i++) { sprintf(outTxt, "green[%3d]=%d\n", i, pix[1][i]); write(outfd, outTxt, strlen(outTxt)); } break; case BLUE: for (i = 0 ; i < 256 ; i++) { sprintf(outTxt, "blue[%3d]=%d\n", i, pix[2][i]); write(outfd, outTxt, strlen(outTxt)); } break; } return 0; }
/* Based on the graph (the entries in A), set up the pair (rowStartA, colA). * It is the same as the pair (ADJNCY, XADJ). * Then perform the symbolic factorization by calling symFactorization(). */ int XC::SymSparseLinSOE::setSize(Graph &theGraph) { int result = 0; size= checkSize(theGraph); // first iterarte through the vertices of the graph to get nnz Vertex *theVertex; int newNNZ = 0; VertexIter &theVertices = theGraph.getVertices(); while((theVertex = theVertices()) != 0) { const std::set<int> &theAdjacency = theVertex->getAdjacency(); newNNZ += theAdjacency.size(); } nnz = newNNZ; colA= ID(newNNZ); if(colA.isEmpty()) { std::cerr << "WARNING SymSparseLinSOE::setSize :"; std::cerr << " ran out of memory for colA with nnz = "; std::cerr << newNNZ << " \n"; size = 0; nnz = 0; result = -1; } factored = false; if(size > B.Size()) { inic(size); rowStartA= ID(size+1); } // fill in rowStartA and colA if(size != 0) { rowStartA(0) = 0; int startLoc = 0; int lastLoc = 0; for (int a=0; a<size; a++) { theVertex = theGraph.getVertexPtr(a); if(theVertex == 0) { std::cerr << "WARNING:XC::SymSparseLinSOE::setSize :"; std::cerr << " vertex " << a << " not in graph! - size set to 0\n"; size = 0; return -1; } const std::set<int> &theAdjacency = theVertex->getAdjacency(); // now we have to place the entries in the ID into order in colA for(std::set<int>::const_iterator i=theAdjacency.begin(); i!=theAdjacency.end(); i++) { const int row= *i; bool foundPlace = false; for (int j=startLoc; j<lastLoc; j++) if(colA(j) > row) { // move the entries already there one further on // and place col in current location for (int k=lastLoc; k>j; k--) colA(k)= colA(k-1); colA(j) = row; foundPlace = true; j = lastLoc; } if(foundPlace == false) // put in at the end colA(lastLoc) = row; lastLoc++; } rowStartA(a+1)= lastLoc; startLoc = lastLoc; } } // call "C" function to form elimination tree and to do the symbolic factorization. nblks = symFactorization(rowStartA.getDataPtr(), colA.getDataPtr(), size, this->LSPARSE, &xblk, &invp, &rowblks, &begblk, &first, &penv, &diag); return result; }
int main() { int przelacznik,i,rozmiar,nevelement,zdjety,wartosc,el,random,r,il,wybrana; printf("TWORZENIE NOWEGO STOSU" ); przelacznik='1'; do { switch(przelacznik) { case '1': wsk *wskaznik; wskaznik =(wsk*)malloc(10*sizeof(struct stos)); inic (wskaznik); rozmiar=1; printf("podaj wartosc pierwszego elementu stosu"); scanf("%d",&el); push(wskaznik,el); break; case '2': if(rozmiar<10) { printf("podaj wartosc kolejnego elementu\n"); scanf("%d",&nevelement); push(wskaznik,nevelement); rozmiar++; } else {printf("stos jest juz pelen\n");} break; case '3':if(rozmiar==1) { printf("stos pusty\n"); break; } else { zdjety=pop(wskaznik); rozmiar--; printf("wartosc zdjetego elementu to %d\n",zdjety); } break; case '4': wypisz(wskaznik); break; case '5': zwolnij(wskaznik); rozmiar=0; break; } printf("co chcesz zrobic\n 1.stworz stos\n 2.dodaj kolejny element\n 3.usun element\n 4.wypisz stos\n 5.zwolnj stos\n 6. zakoncz dzialanie programu\n"); przelacznik=getch(); system("cls"); } while(przelacznik!='6'); system("PAUSE"); }
int XC::DistributedBandGenLinSOE::setSize(Graph &theGraph) { int result = 0; int oldSize = size; static ID data(3); // if subprocess, collect graph, send it off, // vector back containing size of system, etc. if(processID != 0) { result= sendGraph(theGraph,data); size= data(0); numSubD= data(1); numSuperD= data(2); } // if main domain, collect graphs from all subdomains, // merge into 1, number this one, send to subdomains the // id containing dof tags & start id's. else { // from each distributed soe recv it's graph // and merge them into master graph getSubGraphs(theGraph); calcBand(theGraph); // to each distributed soe send the size data // and merge them into master graph data(0) = size; data(1) = numSubD; data(2) = numSuperD; sendSizeData(data); } const int numCols = theGraph.getNumVertex(); calcLocalMap(size); int newSize; if(processID != 0) newSize = numCols * (2*numSubD + numSuperD + 1); else newSize = size * (2*numSubD + numSuperD + 1); // newSize = size * (2*numSubD + numSuperD + 1); if(newSize != A.Size()) { // we have to get another space for A if(processID == 0) { workArea.resize(newSize); } A.resize(newSize); } A.Zero(); factored = false; if(size > B.Size()) { // we have to get space for the vectors inic(size); myB.resize(size); } setupMyB(oldSize,size); // invoke setSize() on the Solver result= setSolverSize(); return result; }