UIntVector& UIntVector::operator=(const std::initializer_list<unsigned int>& list) { if(list.size() > max_size) { increase_memory(list.size(), false); } count = list.size(); size_t i; std::initializer_list<unsigned int>::iterator item; for(i = 0, item = list.begin(); item != list.end(); ++i, ++item) { data[i] = *item; } return *this; }
int next_index_for_stopping_condition() { int i; if (number_of_stopping_conditions_set == MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET) { if( increase_memory() ) { return -1; } } // Initialize the particle index storage for this stopping condition for (i = 0; i < MAX_NUMBER_OF_PARTICLES_PER_INDEX; i++) { index_of_particle_in_stopping_condition[number_of_stopping_conditions_set * MAX_NUMBER_OF_PARTICLES_PER_INDEX + i] = -1; } return number_of_stopping_conditions_set++; // Post increment - returns original value }
UIntVector& UIntVector::operator=(const UIntVector& other) { if(&other == this) { return *this; } if(other.count > max_size) { increase_memory(other.count, false); } count = other.size(); for(size_t i = 0; i < other.count; ++i) { data[i] = other[i]; } return *this; }
UIntVector& UIntVector::insert(size_t index, const unsigned int& element) { if(index > count) { std::stringstream msg; msg << "Attempted to insert at index " << index << ", expected <= " << count; throw std::out_of_range(msg.str()); } if(max_size < count + 1) { increase_memory(count + 1); } for(size_t i = count; i > index; i--) { data[i] = data[i-1]; } data[index] = element; ++count; return *this; }
int mpi_collect_stopping_conditions() { if(!enabled_conditions) {return 0;} int i; int local_number_of_stopping_conditions_set; int counts[sc_mpi_size]; int displs[sc_mpi_size]; memset(counts, 0, sizeof(counts)); memset(displs, 0, sizeof(displs)); long set = 0; MPI_Allreduce(&set_conditions, &set, 1, MPI_INTEGER, MPI_BOR, world); set_conditions = set; MPI_Gather(&number_of_stopping_conditions_set, 1, MPI_INTEGER, counts, 1, MPI_INT, 0, world); if(sc_mpi_rank == 0) { local_number_of_stopping_conditions_set = 0; for(i = 0; i < sc_mpi_size; i++) { local_number_of_stopping_conditions_set += counts[i]; } if(local_number_of_stopping_conditions_set > MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET) { int n = ((local_number_of_stopping_conditions_set - MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET) / DELTA_MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET) + 1; int tmp = DELTA_MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET; DELTA_MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET = n * DELTA_MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET; increase_memory(); DELTA_MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET = tmp; } local_type_of_stopping_condition_set = (int *) calloc (MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET , sizeof(int));; local_index_of_particle_in_stopping_condition = (int *) calloc (MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET , MAX_NUMBER_OF_PARTICLES_PER_INDEX * sizeof(int)); } if(sc_mpi_rank == 0) { int x = 0; for(i = 0; i < sc_mpi_size; i++) { displs[i] = x; x += counts[i]; } } MPI_Gatherv( type_of_stopping_condition_set, number_of_stopping_conditions_set, MPI_INTEGER, local_type_of_stopping_condition_set, counts, displs, MPI_INTEGER, 0, world ); if(sc_mpi_rank == 0) { int x = 0; for(i = 0; i < sc_mpi_size; i++) { displs[i] = x; counts[i] *= MAX_NUMBER_OF_PARTICLES_PER_INDEX; x += counts[i]; } } MPI_Gatherv( index_of_particle_in_stopping_condition, number_of_stopping_conditions_set*MAX_NUMBER_OF_PARTICLES_PER_INDEX, MPI_INTEGER, local_index_of_particle_in_stopping_condition, counts, displs, MPI_INTEGER, 0, world ); if(sc_mpi_rank == 0) { number_of_stopping_conditions_set = local_number_of_stopping_conditions_set; if(number_of_stopping_conditions_set > 0) { memcpy(index_of_particle_in_stopping_condition, local_index_of_particle_in_stopping_condition, MAX_NUMBER_OF_PARTICLES_PER_INDEX * MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET * sizeof(int)); memcpy(type_of_stopping_condition_set, local_type_of_stopping_condition_set, MAX_NUMBER_OF_SIMULTANIOUS_CONDITIONS_SET * sizeof(int)); } free(local_type_of_stopping_condition_set); free(local_index_of_particle_in_stopping_condition); local_type_of_stopping_condition_set = 0; local_index_of_particle_in_stopping_condition = 0; } }