void Hypergraph::getPartitionsByKDTree(int &nPartitions, vector<int> &partitionSizes, vector<int> &partitions) { int minPartition = 5; int maxPartition = 15; int nClusters = *max_element(_clusters.begin(), _clusters.end())+1; int partitionIdx = 0; int partitionCnt = 0; _clusters.resize(_nVertices+_edges.size()); for (int i=_nVertices; i<_nVertices+_edges.size(); ++i) { _clusters[i] = i-_nVertices; } _partitions.resize(_clusters.size()); for (int i=0; i<nClusters; ++i) { int clusterSize = count(_clusters.begin(), _clusters.end(), i); int partitionSize = 0; int nSubPartitions = (clusterSize*1.0f/maxPartition+clusterSize*1.0f/minPartition)/2; int depth = max(floor(log(1.0f*nSubPartitions)/log(2.0f)),0); nSubPartitions = pow(2.0f, depth); vector<fvec> ptBuf (clusterSize); vector<float> divisions (pow(2.0f, depth+1)-1); int bufIdx = 0; for (int j=0; j<_clusters.size(); ++j) { if (_clusters[j] == i) { ptBuf[bufIdx++] = _layout[j]; } } kdPartition(0, depth, ptBuf.begin(), ptBuf.end(), divisions, 0); for (int j=0; j<_clusters.size(); ++j) { if (_clusters[j] == i) { int subPartitionIdx = kdCoord(_layout[j], depth, divisions); _partitions[j] = partitionIdx+subPartitionIdx; } } partitionIdx += nSubPartitions; } nPartitions = partitionIdx; partitionSizes.resize(nPartitions); for (int i=0; i<nPartitions; ++i) { partitionSizes[i] = count(_partitions.begin(), _partitions.end(), i); } _clusters.resize(_nVertices); }
void diy::RegularPartners:: fill_steps() { if (contiguous_) { std::vector<int> cur_steps(divisions().size(), 1); for (size_t r = 0; r < rounds(); ++r) { steps_.push_back(cur_steps[kvs_[r].dim]); cur_steps[kvs_[r].dim] *= kvs_[r].size; } } else { std::vector<int> cur_steps(divisions().begin(), divisions().end()); for (size_t r = 0; r < rounds(); ++r) { cur_steps[kvs_[r].dim] /= kvs_[r].size; steps_.push_back(cur_steps[kvs_[r].dim]); } } }
// **************************************************************************** // Method: avtImgCommunicator:: // // Purpose: // // Programmer: Manasa Prasad // Creation: August 2013 // // Modifications: // // **************************************************************************** void avtImgCommunicator::patchAllocationLogic(){ // 1. do not send the numpatchespreproc vector! // 2. do away with numcompositedPatches test and replace with totalRecvPatches std::vector<std::vector<iotaMeta> > all_patches_sorted_avgZ_proc0(num_procs); std::vector<int> procToSend; std::vector<int> numAvgZEachBlock (num_procs); numBlocksPerProc = new int[num_procs](); boundsPerBlockVec.resize(num_procs); int num_avgZ_proc0 = all_avgZ_proc0.size(); // calculate the range of avg_zs int num_avgZ_perBlock = (num_avgZ_proc0 / num_procs); int rem_avgZ = num_avgZ_proc0 % num_procs; //printf("num_avg_z: %d num_procs: %d num_avgZ_perBlock: %d rem_avgZ: %d \n\n", num_avgZ_proc0, num_procs, num_avgZ_perBlock, rem_avgZ); //procToSend.resize (num_procs); //all_patches_sorted_avgZ_proc0.resize(num_procs); for(int i = 0; i < num_procs; i++){ numAvgZEachBlock[i] = num_avgZ_perBlock + (rem_avgZ-- > 0 ? 1 : 0); } // Sorting the patches std::sort(allRecvIotaMeta, allRecvIotaMeta + totalPatches, &sortImgByDepthIota); // Populate the all_patches_sorted_avgZ_proc0 vector with data from allPatchesMeta int current_avgZ_Block = 0; float prevAvgZ = totalPatches > 0 ? allRecvIotaMeta[0].avg_z : 0; int num_avgZ_thisBlock = 1; for (int i = 0; i < totalPatches; ++i){ float currentAvgZ = allRecvIotaMeta[i].avg_z; if (currentAvgZ != prevAvgZ && num_avgZ_thisBlock == numAvgZEachBlock[current_avgZ_Block]){ num_avgZ_thisBlock = 1; current_avgZ_Block++; prevAvgZ = currentAvgZ; } else if (currentAvgZ != prevAvgZ){ prevAvgZ = currentAvgZ; num_avgZ_thisBlock++; } all_patches_sorted_avgZ_proc0[current_avgZ_Block].push_back(allRecvIotaMeta[i]); } //sort the avg_z vector by size std::sort (all_patches_sorted_avgZ_proc0.begin(), all_patches_sorted_avgZ_proc0.end(), sortByVecSize); std::vector<std::vector<iotaMeta> > patchesToCompositeLocallyVector(num_procs); // Calculate which block of avg_z to send to which processor // ith block is sent to the processor in procToSend[i] //printf("num_avg_z: %d num_procs: %d\n\n", num_avgZ_proc0, num_procs); for (int i = 0; i < num_procs; ++i){ procToSend.push_back(calculatePatchDivision(all_patches_sorted_avgZ_proc0[i], procToSend)); std::vector<std::vector<int> > divisions(num_procs); determinePatchesToCompositeLocally(all_patches_sorted_avgZ_proc0[i], patchesToCompositeLocallyVector, procToSend[i], divisions); determinePatchAdjacency(all_patches_sorted_avgZ_proc0[i], patchesToCompositeLocallyVector, divisions); int size = all_patches_sorted_avgZ_proc0[i].size(); if(size > 0){ boundsPerBlockVec[procToSend[i]].push_back(all_patches_sorted_avgZ_proc0[i][0].avg_z); boundsPerBlockVec[procToSend[i]].push_back(all_patches_sorted_avgZ_proc0[i][size-1].avg_z); } //printf("division: %d, procToSend: %d \n", i, procToSend[i]); } // Printing for error check for(int i = 0; i < num_procs; ++i){ debug5 << "Block: " << i << " \t size:" << all_patches_sorted_avgZ_proc0[i].size() << endl; // printf("Block %d\n", i ); for(std::vector<iotaMeta>::iterator it = all_patches_sorted_avgZ_proc0[i].begin(); it != all_patches_sorted_avgZ_proc0[i].end(); ++it){ debug5 << it->avg_z << "\t " << it->procId << endl; // printf("\t %.5f \t %d\n", it->avg_z, it->procId); } } std::vector< std::vector<int> > patchesToSendVec (num_procs); std::vector< std::map<int,int> > patchesToRecvMap (num_procs); std::pair< std::map<int,int>::iterator, bool > isPresent; for (int procId = 0; procId < num_procs; procId++) patchesToRecvMap[procId].clear(); // Populate recvMap and sendVec for (size_t i = 0; i < all_patches_sorted_avgZ_proc0.size(); i++){ int destProcId = procToSend[i]; for (size_t j = 0; j < all_patches_sorted_avgZ_proc0[i].size(); j++){ int originProcId = all_patches_sorted_avgZ_proc0[i][j].procId; if(originProcId != destProcId){ // Array of the form [0 1 2 3 ...] // even numbers(0,2..): patchNumber // odd numbers(1,3...): destProcId patchesToSendVec[originProcId].push_back( all_patches_sorted_avgZ_proc0[i][j].patchNumber ); patchesToSendVec[originProcId].push_back( destProcId ); // Array of the form [0 1 2 3 ...] // even numbers(0,2..): procId // odd numbers(1,3...): numPatches isPresent = patchesToRecvMap[destProcId].insert( std::pair<int,int>(originProcId, 1) ); if(isPresent.second == false) ++patchesToRecvMap[destProcId][originProcId]; //printf("Inserted to dest: %d the origin: %d avg_z: %.2f\n", destProcId, originProcId, allPatchesMeta[patchIndex].avg_z ); } } debug5 << "------division: " << i << " procToSend:" << procToSend[i] << endl; } recvDisplacementForProcs = new int[num_procs](); sendDisplacementForProcs = new int[num_procs](); numPatchesToSendArray = new int[num_procs](); numPatchesToRecvArray = new int[num_procs](); blockDisplacementForProcs = new int[num_procs](); numPatchesToSendRecvArray = new int[4*num_procs](); compositeDisplacementForProcs = new int[num_procs](); numPatchesToCompositeLocally = new int[num_procs](); int totalRecvSize = 0; int totalSendSize = 0; int totalBlockSize = 0; int totalCompositeSize = 0; for (int currentProcId = 0; currentProcId < num_procs; currentProcId++){ numPatchesToSendArray[currentProcId] = patchesToSendVec[currentProcId].size(); numPatchesToRecvArray[currentProcId] = 2*patchesToRecvMap[currentProcId].size(); numBlocksPerProc[currentProcId] = boundsPerBlockVec[currentProcId].size(); numPatchesToCompositeLocally[currentProcId] = patchesToCompositeLocallyVector[currentProcId].size(); numPatchesToSendRecvArray[currentProcId*4] = numPatchesToSendArray[currentProcId]; numPatchesToSendRecvArray[currentProcId*4 + 1] = numPatchesToRecvArray[currentProcId]; numPatchesToSendRecvArray[currentProcId*4 + 2] = numBlocksPerProc[currentProcId]; numPatchesToSendRecvArray[currentProcId*4 + 3] = numPatchesToCompositeLocally[currentProcId]; totalRecvSize += numPatchesToRecvArray[currentProcId]; totalSendSize += numPatchesToSendArray[currentProcId]; totalBlockSize+= numBlocksPerProc[currentProcId]; totalCompositeSize += numPatchesToCompositeLocally[currentProcId]; if(currentProcId!=0) { recvDisplacementForProcs[currentProcId] = recvDisplacementForProcs[currentProcId-1] + numPatchesToRecvArray[currentProcId-1]; sendDisplacementForProcs[currentProcId] = sendDisplacementForProcs[currentProcId-1] + numPatchesToSendArray[currentProcId-1]; blockDisplacementForProcs[currentProcId] = blockDisplacementForProcs[currentProcId-1] + numBlocksPerProc[currentProcId-1]; compositeDisplacementForProcs[currentProcId] = compositeDisplacementForProcs[currentProcId-1] + numPatchesToCompositeLocally[currentProcId-1]; } } patchesToRecvArray = new int[totalRecvSize]; patchesToSendArray = new int[totalSendSize]; boundsPerBlockArray = new float[totalBlockSize]; patchesToCompositeLocallyArray = new int[totalCompositeSize]; for (int currentProcId = 0; currentProcId < num_procs; currentProcId++){ //printf("\n\n### dest: %d size: %ld\n ", currentProcId, patchesToRecvMap[currentProcId].size()); int count = 0; for (std::map<int,int>::iterator it = patchesToRecvMap[currentProcId].begin(); it!=patchesToRecvMap[currentProcId].end(); ++it){ patchesToRecvArray[recvDisplacementForProcs[currentProcId] + (count++)] = it->first; patchesToRecvArray[recvDisplacementForProcs[currentProcId] + (count++)] = it->second; //printf("\t numPatches %d origin: %d\n", it->second, it->first); } count = 0; //printf("\n\n### origin: %d size: %ld\n ", currentProcId, patchesToSendVec[currentProcId].size()); for (std::vector<int>::iterator it = patchesToSendVec[currentProcId].begin(); it!=patchesToSendVec[currentProcId].end(); ++it){ patchesToSendArray[sendDisplacementForProcs[currentProcId] + (count++)] = *it; //if(count%2!=0) printf("\t patchNumber %d", *it); //else printf(" dest: %d\n", *it); } count = 0; for (std::vector<float>::iterator it = boundsPerBlockVec[currentProcId].begin(); it!=boundsPerBlockVec[currentProcId].end(); ++it) boundsPerBlockArray[blockDisplacementForProcs[currentProcId] + (count++)] = *it; count = 0; for (std::vector<iotaMeta>::iterator it = patchesToCompositeLocallyVector[currentProcId].begin(); it!=patchesToCompositeLocallyVector[currentProcId].end(); ++it) patchesToCompositeLocallyArray[compositeDisplacementForProcs[currentProcId] + (count++)] = it->patchNumber; } //printf("\n ..................................................\n"); }
int main(){ srand(time(NULL)); int encore=0; int choixmodif=2; int choixaffich=0; int affichH=0; int action=0; int nbCell=0; int iteration=0, iMax=0; int ageMature=0, ageMax=0; float beta=0, delta=0; CELLULE* P[taille][taille]; initMat(P); bordure(P); H* matH=Allouematrice(); printf("Ce programme permet de modéliser l'évolution d'une culture cellulaire.\nIl prend en compte l'âge de maturité des cellules, c'est à dire l'âge à partir duquel les cellules peuvent se diviser.\nLe programme gère également l'espérance de vie des cellules et le nombre initial de cellules en culture.\nLe nombre d'itérations est à relier au temps nécessaire à une cellule pour se diviser.\nLors d'une itération, la cellule peut également se transformer en cellule cancéreuse, mourir.\n\n"); do{ printf("Souhaitez vous utiliser les paramètres par défaut:\nAge de maturité=3\nAge maximum=1001\nNombre de cellules initiales=100\nNombre maximal d'itérations=1000\nbeta=0.5\ndelta=0.8\n\n[1]Oui [2]Non\n"); do{ scanf("%d", &choixmodif); if(choixmodif==1){ ageMature=3; ageMax= 1001; nbCell= 100; iMax= 1000; beta= 0.5; delta= 0.8; }else if(choixmodif==2){ printf("Age de maturité (par défaut 3): "); scanf("%d", &ageMature); printf("Age maximum (par défaut 1001): "); scanf("%d", &ageMax); printf("Nombre de cellules initiales (par défaut 100): "); scanf("%d", &nbCell); printf("Nombre maximal d'itérations (par défaut 1000): "); scanf("%d", &iMax); printf("beta (par défaut 0.5): "); scanf("%f", &beta); printf("delta (par défaut 0.8): "); scanf("%f", &delta); }else printf("Erreur de saisie...\nLes choix sont:\n[1]paramètres par défault\n[2]Modifier les paramètres\n"); }while(choixmodif!=1 && choixmodif!=2); do{ initPosition(nbCell, P, matH, iteration); chgmtType(beta, ageMax, P, matH, iteration); comptVoisines(P); printf("\nVoici la disposition des cellules à l'état initial (avant la première itération)\n"); afficheMat(P, iteration); printf("\n"); do{ printf("Souhaitez-vous afficher l'état de la matrice à chaque itération? [1]Oui [2]Non\n"); scanf("%d", &choixaffich); if(choixaffich!=1 && choixaffich!=2) printf("Erreur de saisie...\n"); }while(choixaffich!=1 && choixaffich!=2); while(iteration<iMax) { iteration++; incrementeAge(ageMax, P, matH, iteration); tuer_f_nbVoisines(P, matH, iteration); tuer_f_Cancer(delta, P, matH, iteration); chgmtType(beta, ageMax, P, matH, iteration); divisions(ageMature, P, matH, iteration); comptVoisines(P); if(choixaffich==1){ afficheMat(P, iteration); printf("\n"); } } sauvegarde(matH); printf("Un fichier contenant l'historique de la matrice vient d'être créé.\nIl se trouve dans le répertertoire du programme principal.\n"); printf("\nVoici l'état de la culture cellulaire à la fin de toutes les itérations.\n"); afficheMat(P, iteration); printf("\n"); do{ printf("Souhaitez-vous afficher l'histoire d'une cellule? [1]Oui [2]Non\n"); scanf("%d", &affichH); if(affichH!=1 && affichH!=2) printf("Erreur de saisie...\n"); }while(affichH!=1 && affichH!=2); if(affichH==1) affichelistHCase(matH); do{ printf("Souhaitez-vous relancer la modélisation en concervant ces paramètres? [1]Oui [2]Non\n"); scanf("%d", &encore); if(encore!=1 && encore!=2) printf("Erreur de saisie...\n"); }while(encore!=1 && encore!=2); }while(encore==1); do{ printf("Souhaitez-vous [1]relancer une modélisation [2]quitter le programme ?\n"); scanf("%d", &action); if(action!=1 && action!=2) printf("Erreur de saisie...\n"); }while(action!=1 && action!=2); }while(action==1); printf("Au revoir.\n"); return 0; }