Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce scope for loop variables.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 2 Oct 2020 20:04:16 +0000 (22:04 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 2 Oct 2020 20:04:33 +0000 (22:04 +0200)
20 files changed:
examples/c/dht-kademlia/node.c
examples/c/dht-kademlia/routing_table.c
examples/s4u/dht-kademlia/node.cpp
src/kernel/lmm/maxmin.cpp
src/mc/compare.cpp
src/mc/inspect/mc_dwarf.cpp
src/smpi/bindings/smpi_f77.cpp
src/smpi/bindings/smpi_f77_request.cpp
src/smpi/bindings/smpi_f77_type.cpp
src/smpi/mpi/smpi_win.cpp
src/xbt/dynar.cpp
src/xbt/log.cpp
src/xbt/mallocator.c
src/xbt/mmalloc/mmalloc.c
src/xbt/mmalloc/mrealloc.c
teshsuite/smpi/io-all-at/io-all-at.c
teshsuite/smpi/io-all/io-all.c
teshsuite/smpi/io-ordered/io-ordered.c
teshsuite/smpi/io-simple-at/io-simple-at.c
teshsuite/smpi/io-simple/io-simple.c

index 79d228b..da155cc 100644 (file)
@@ -170,7 +170,6 @@ void routing_table_update(const_node_t node, unsigned int id)
  */
 answer_t find_closest(const_node_t node, unsigned int destination_id)
 {
-  int i;
   answer_t answer = answer_init(destination_id);
   /* We find the corresponding bucket for the id */
   const_bucket_t bucket = routing_table_find_bucket(node->table, destination_id);
@@ -182,7 +181,7 @@ answer_t find_closest(const_node_t node, unsigned int destination_id)
   /* However, if we don't have enough elements in our bucket, we NEED to include at least "BUCKET_SIZE" elements
    * (if, of course, we know at least "BUCKET_SIZE" elements. So we're going to look unsigned into the other buckets.
    */
-  for (i = 1; answer->size < BUCKET_SIZE && ((bucket_id - i > 0) || (bucket_id + i < IDENTIFIER_SIZE)); i++) {
+  for (int i = 1; answer->size < BUCKET_SIZE && ((bucket_id - i > 0) || (bucket_id + i < IDENTIFIER_SIZE)); i++) {
     /* We check the previous buckets */
     if (bucket_id - i >= 0) {
       const_bucket_t bucket_p = &node->table->buckets[bucket_id - i];
index b8204f8..9751cf7 100644 (file)
@@ -25,9 +25,8 @@ routing_table_t routing_table_init(unsigned int node_id)
 /** @brief Frees the routing table */
 void routing_table_free(routing_table_t table)
 {
-  unsigned int i;
   // Free the buckets.
-  for (i = 0; i <= IDENTIFIER_SIZE; i++) {
+  for (unsigned int i = 0; i <= IDENTIFIER_SIZE; i++) {
     xbt_dynar_free(&table->buckets[i].nodes);
   }
   xbt_free(table->buckets);
@@ -37,13 +36,13 @@ void routing_table_free(routing_table_t table)
 /**@brief prints the routing table, to debug stuff. */
 void routing_table_print(const_routing_table_t table)
 {
-  unsigned int j;
-  unsigned int value;
   XBT_INFO("Routing table of %08x:", table->id);
 
   for (unsigned int i = 0; i <= IDENTIFIER_SIZE; i++) {
     if (!xbt_dynar_is_empty(table->buckets[i].nodes)) {
       XBT_INFO("Bucket number %u: ", i);
+      unsigned int j;
+      unsigned int value;
       xbt_dynar_foreach (table->buckets[i].nodes, j, value) {
         XBT_INFO("Element %u: %08x", j, value);
       }
index 265cdc0..f98c9ef 100644 (file)
@@ -23,7 +23,6 @@ static void destroy(void* message)
 bool Node::join(unsigned int known_id)
 {
   const Answer* node_list;
-  unsigned int i;
   bool got_answer = false;
 
   /* Add the guy we know to our routing table and ourselves. */
@@ -59,7 +58,7 @@ bool Node::join(unsigned int known_id)
   /* Second step: Send a FIND_NODE to a a random node in buckets */
   unsigned int bucket_id = table.findBucket(known_id)->getId();
   xbt_assert(bucket_id <= IDENTIFIER_SIZE);
-  for (i = 0; ((bucket_id > i) || (bucket_id + i) <= IDENTIFIER_SIZE) && i < JOIN_BUCKETS_QUERIES; i++) {
+  for (unsigned int i = 0; ((bucket_id > i) || (bucket_id + i) <= IDENTIFIER_SIZE) && i < JOIN_BUCKETS_QUERIES; i++) {
     if (bucket_id > i) {
       unsigned int id_in_bucket = get_id_in_prefix(id_, bucket_id - i);
       findNode(id_in_bucket, false);
index 3dd1bb6..eff10f6 100644 (file)
@@ -645,8 +645,7 @@ template <class CnstList> void System::lmm_solve(CnstList& cnst_list)
     min_usage = -1;
     min_bound = -1;
     saturated_constraints.clear();
-    int pos;
-    for (pos = 0; pos < cnst_light_num; pos++) {
+    for (int pos = 0; pos < cnst_light_num; pos++) {
       xbt_assert(not cnst_light_tab[pos].cnst->active_element_set_.empty(),
                  "Cannot saturate more a constraint that has"
                  " no active element! You may want to change the maxmin precision (--cfg=maxmin/precision:<new_value>)"
index 70c2982..f13a96a 100644 (file)
@@ -1015,7 +1015,6 @@ static bool areas_differ_with_type(simgrid::mc::StateComparator& state, const vo
   const simgrid::mc::Type* subtype;
   const simgrid::mc::Type* subsubtype;
   int elm_size;
-  int i;
 
   xbt_assert(type != nullptr);
   switch (type->type) {
@@ -1060,7 +1059,7 @@ static bool areas_differ_with_type(simgrid::mc::StateComparator& state, const vo
         default:
           return false;
       }
-      for (i = 0; i < type->element_count; i++) {
+      for (int i = 0; i < type->element_count; i++) {
         size_t off = i * elm_size;
         if (areas_differ_with_type(state, (const char*)real_area1 + off, snapshot1, region1,
                                    (const char*)real_area2 + off, snapshot2, region2, type->subtype, pointer_level))
index f6f8601..c1620ec 100644 (file)
@@ -396,8 +396,7 @@ static uint64_t MC_dwarf_array_element_count(Dwarf_Die* die, Dwarf_Die* unit)
 
   int result = 1;
   Dwarf_Die child;
-  int res;
-  for (res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child)) {
+  for (int res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child)) {
     int child_tag = dwarf_tag(&child);
     if (child_tag == DW_TAG_subrange_type || child_tag == DW_TAG_enumeration_type)
       result *= MC_dwarf_subrange_element_count(&child, unit);
@@ -487,10 +486,9 @@ static void MC_dwarf_fill_member_location(const simgrid::mc::Type* type, simgrid
 static void MC_dwarf_add_members(const simgrid::mc::ObjectInformation* /*info*/, Dwarf_Die* die,
                                  const Dwarf_Die* /*unit*/, simgrid::mc::Type* type)
 {
-  int res;
   Dwarf_Die child;
   xbt_assert(type->members.empty());
-  for (res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child)) {
+  for (int res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child)) {
     int tag = dwarf_tag(&child);
     if (tag == DW_TAG_member || tag == DW_TAG_inheritance) {
       // Skip declarations:
@@ -853,8 +851,7 @@ static void MC_dwarf_handle_children(simgrid::mc::ObjectInformation* info, Dwarf
 {
   // For each child DIE:
   Dwarf_Die child;
-  int res;
-  for (res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child))
+  for (int res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child))
     MC_dwarf_handle_die(info, &child, unit, frame, ns);
 }
 
index 4d108c2..23b5270 100644 (file)
@@ -405,8 +405,7 @@ void mpi_info_get_(int* info, char* key, int* valuelen, char* value, int* flag,
   xbt_free(tkey);
   if(*flag!=0){
     int replace=0;
-    int i=0;
-    for (i=0; i<*valuelen; i++){
+    for (int i = 0; i < *valuelen; i++) {
       if(value[i]=='\0')
         replace=1;
       if(replace)
@@ -902,8 +901,7 @@ void mpi_info_get_nkeys_ ( int* info, int *nkeys, int* ierr){
 
 void mpi_info_get_nthkey_ ( int* info, int* n, char *key, int* ierr, unsigned int keylen){
   *ierr = MPI_Info_get_nthkey( simgrid::smpi::Info::f2c(*info), *n, key);
-  unsigned int i = 0;
-  for (i=strlen(key); i<keylen; i++)
+  for (unsigned int i = strlen(key); i < keylen; i++)
     key[i]=' ';
 }
 
index 939a3f6..0a1cf7d 100644 (file)
@@ -152,10 +152,9 @@ void mpi_start_(int* request, int* ierr) {
 
 void mpi_startall_(int* count, int* requests, int* ierr) {
   MPI_Request* reqs;
-  int i;
 
   reqs = xbt_new(MPI_Request, *count);
-  for(i = 0; i < *count; i++) {
+  for (int i = 0; i < *count; i++) {
     reqs[i] = simgrid::smpi::Request::f2c(requests[i]);
   }
   *ierr = MPI_Startall(*count, reqs);
@@ -174,10 +173,9 @@ void mpi_wait_(int* request, MPI_Status* status, int* ierr) {
 
 void mpi_waitany_(int* count, int* requests, int* index, MPI_Status* status, int* ierr) {
   MPI_Request* reqs;
-  int i;
 
   reqs = xbt_new(MPI_Request, *count);
-  for(i = 0; i < *count; i++) {
+  for (int i = 0; i < *count; i++) {
     reqs[i] = simgrid::smpi::Request::f2c(requests[i]);
   }
   *ierr = MPI_Waitany(*count, reqs, index, status);
@@ -258,10 +256,9 @@ void mpi_testall_ (int* count, int * requests,  int *flag, MPI_Status * statuses
 void mpi_testany_ (int* count, int* requests, int *index, int *flag, MPI_Status* status, int* ierr)
 {
   MPI_Request* reqs;
-  int i;
 
   reqs = xbt_new(MPI_Request, *count);
-  for(i = 0; i < *count; i++) {
+  for (int i = 0; i < *count; i++) {
     reqs[i] = simgrid::smpi::Request::f2c(requests[i]);
   }
   *ierr = MPI_Testany(*count, reqs, index, flag, FORT_STATUS_IGNORE(status));
index ceedaab..9bd6938 100644 (file)
@@ -186,10 +186,9 @@ void mpi_type_create_indexed_block_ (int* count, int* blocklength, int* indices,
 
 void mpi_type_struct_ (int* count, int* blocklens, int* indices, int* old_types, int*  newtype, int* ierr) {
   MPI_Datatype tmp;
-  int i=0;
   MPI_Datatype* types = static_cast<MPI_Datatype*>(xbt_malloc(*count*sizeof(MPI_Datatype)));
   MPI_Aint* indices_aint=new MPI_Aint[*count];
-  for(i=0; i< *count; i++){
+  for (int i = 0; i < *count; i++) {
     indices_aint[i]=indices[i];
     types[i] = simgrid::smpi::Datatype::f2c(old_types[i]);
   }
@@ -203,9 +202,8 @@ void mpi_type_struct_ (int* count, int* blocklens, int* indices, int* old_types,
 
 void mpi_type_create_struct_(int* count, int* blocklens, MPI_Aint* indices, int*  old_types, int*  newtype, int* ierr){
   MPI_Datatype tmp;
-  int i=0;
   MPI_Datatype* types = static_cast<MPI_Datatype*>(xbt_malloc(*count*sizeof(MPI_Datatype)));
-  for(i=0; i< *count; i++){
+  for (int i = 0; i < *count; i++) {
     types[i] = simgrid::smpi::Datatype::f2c(old_types[i]);
   }
   *ierr = MPI_Type_create_struct(*count, blocklens, indices, types, &tmp);
index f62ab4e..456905c 100644 (file)
@@ -617,12 +617,11 @@ int Win::lock(int lock_type, int rank, int /*assert*/)
 }
 
 int Win::lock_all(int assert){
-  int i=0;
   int retval = MPI_SUCCESS;
-  for (i=0; i<comm_->size();i++){
-      int ret = this->lock(MPI_LOCK_SHARED, i, assert);
-      if(ret != MPI_SUCCESS)
-        retval = ret;
+  for (int i = 0; i < comm_->size(); i++) {
+    int ret = this->lock(MPI_LOCK_SHARED, i, assert);
+    if (ret != MPI_SUCCESS)
+      retval = ret;
   }
   return retval;
 }
@@ -644,9 +643,8 @@ int Win::unlock(int rank){
 }
 
 int Win::unlock_all(){
-  int i=0;
   int retval = MPI_SUCCESS;
-  for (i=0; i<comm_->size();i++){
+  for (int i = 0; i < comm_->size(); i++) {
     int ret = this->unlock(i);
     if (ret != MPI_SUCCESS)
       retval = ret;
index 6778ca1..ae898ab 100644 (file)
@@ -300,9 +300,7 @@ void xbt_dynar_remove_at(xbt_dynar_t dynar, int idx, void* object)
  */
 signed int xbt_dynar_search_or_negative(const_xbt_dynar_t dynar, const void* elem)
 {
-  unsigned long it;
-
-  for (it = 0; it < dynar->used; it++)
+  for (unsigned long it = 0; it < dynar->used; it++)
     if (not memcmp(_xbt_dynar_elm(dynar, it), elem, dynar->elmsize)) {
       return it;
     }
@@ -317,9 +315,7 @@ signed int xbt_dynar_search_or_negative(const_xbt_dynar_t dynar, const void* ele
  */
 int xbt_dynar_member(const_xbt_dynar_t dynar, const void* elem)
 {
-  unsigned long it;
-
-  for (it = 0; it < dynar->used; it++)
+  for (unsigned long it = 0; it < dynar->used; it++)
     if (not memcmp(_xbt_dynar_elm(dynar, it), elem, dynar->elmsize)) {
       return 1;
     }
@@ -394,11 +390,10 @@ void xbt_dynar_map(const_xbt_dynar_t dynar, void_f_pvoid_t op)
   char *const data = (char *) dynar->data;
   const unsigned long elmsize = dynar->elmsize;
   const unsigned long used = dynar->used;
-  unsigned long i;
 
   _sanity_check_dynar(dynar);
 
-  for (i = 0; i < used; i++) {
+  for (unsigned long i = 0; i < used; i++) {
     char* elm = data + i * elmsize;
     op(elm);
   }
index 7f4da38..5b16eff 100644 (file)
@@ -437,18 +437,15 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string)
 
 static xbt_log_category_t _xbt_log_cat_searchsub(xbt_log_category_t cat, const char* name)
 {
-  xbt_log_category_t child;
-  xbt_log_category_t res;
-
   XBT_DEBUG("Search '%s' into '%s' (firstChild='%s'; nextSibling='%s')", name,
          cat->name, (cat->firstChild ? cat->firstChild->name : "none"),
          (cat->nextSibling ? cat->nextSibling->name : "none"));
   if (strcmp(cat->name, name) == 0)
     return cat;
 
-  for (child = cat->firstChild; child != nullptr; child = child->nextSibling) {
+  for (xbt_log_category_t child = cat->firstChild; child != nullptr; child = child->nextSibling) {
     XBT_DEBUG("Dig into %s", child->name);
-    res = _xbt_log_cat_searchsub(child, name);
+    xbt_log_category_t res = _xbt_log_cat_searchsub(child, name);
     if (res)
       return res;
   }
index 8fff0ce..d4685d6 100644 (file)
@@ -125,11 +125,10 @@ xbt_mallocator_t xbt_mallocator_new(int size, pvoid_f_void_t new_f, void_f_pvoid
  */
 void xbt_mallocator_free(xbt_mallocator_t m)
 {
-  int i;
   xbt_assert(m != NULL, "Invalid parameter");
 
   XBT_VERB("Frees mallocator %p (size:%d/%d)", m, m->current_size, m->max_size);
-  for (i = 0; i < m->current_size; i++) {
+  for (int i = 0; i < m->current_size; i++) {
     m->free_f(m->objects[i]);
   }
   xbt_free(m->objects);
@@ -159,9 +158,8 @@ void *xbt_mallocator_get(xbt_mallocator_t m)
     if (m->current_size <= 0) {
       /* No object is ready yet. Create a bunch of them to try to group the
        * mallocs on the same memory pages (to help the cache lines) */
-      int i;
       int amount = MIN(m->max_size / 2, 1000);
-      for (i = 0; i < amount; i++)
+      for (int i = 0; i < amount; i++)
         m->objects[i] = m->new_f();
       m->current_size = amount;
     }
index d3c26bb..7b98cdc 100644 (file)
@@ -70,9 +70,6 @@ static void initialize_heapinfo_heapinfo(const s_xbt_mheap_t* mdp)
  * properly, we need to make the align function publicly visible, too  */
 static void initialize(xbt_mheap_t mdp)
 {
-  int i;
-  malloc_info mi; /* to compute the offset of the swag hook */
-
   // Update mdp meta-data:
   mdp->heapsize = HEAP / BLOCKSIZE;
   mdp->heapinfo = (malloc_info *)
@@ -89,9 +86,9 @@ static void initialize(xbt_mheap_t mdp)
 
   initialize_heapinfo_heapinfo(mdp);
 
-  for (i=0;i<BLOCKLOG;i++) {
-      xbt_swag_init(&(mdp->fraghead[i]),
-                    xbt_swag_offset(mi, freehook));
+  for (int i = 0; i < BLOCKLOG; i++) {
+    malloc_info mi; /* to compute the offset of the swag hook */
+    xbt_swag_init(&(mdp->fraghead[i]), xbt_swag_offset(mi, freehook));
   }
 }
 
@@ -109,8 +106,6 @@ static void *register_morecore(struct mdesc *mdp, size_t size)
 
   /* Check if we need to grow the info table (in a multiplicative manner)  */
   if ((size_t) BLOCK((char *) result + size) > mdp->heapsize) {
-    int it;
-
     size_t newsize = mdp->heapsize;
     while ((size_t) BLOCK((char *) result + size) > newsize)
       newsize *= 2;
@@ -140,7 +135,7 @@ static void *register_morecore(struct mdesc *mdp, size_t size)
 
     /* mark the space previously occupied by the block info as free by first marking it
      * as occupied in the regular way, and then freing it */
-    for (it=0; it<BLOCKIFY(mdp->heapsize * sizeof(malloc_info)); it++){
+    for (int it = 0; it < BLOCKIFY(mdp->heapsize * sizeof(malloc_info)); it++) {
       newinfo[BLOCK(oldinfo)+it].type = MMALLOC_TYPE_UNFRAGMENTED;
       newinfo[BLOCK(oldinfo)+it].busy_block.ignore = 0;
     }
index 4ce18de..ad6ea5d 100644 (file)
@@ -79,9 +79,8 @@ void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size)
     /* Full blocks -> Full blocks; see if we can hold it in place. */
     blocks = BLOCKIFY(size);
     if (blocks < mdp->heapinfo[block].busy_block.size) {
-      size_t it;
       /* The new size is smaller; return excess memory to the free list. */
-      for (it= block+blocks; it< mdp->heapinfo[block].busy_block.size ; it++){
+      for (size_t it = block + blocks; it < mdp->heapinfo[block].busy_block.size; it++) {
         mdp->heapinfo[it].type = MMALLOC_TYPE_UNFRAGMENTED; // FIXME that should be useless, type should already be 0 here
         mdp->heapinfo[it].busy_block.ignore = 0;
         mdp->heapinfo[it].busy_block.size = 0;
index 3c2963b..b977265 100644 (file)
@@ -11,7 +11,6 @@ int main( int argc, char *argv[] )
     int errs = 0;
     int size;
     int rank;
-    int i;
     int* buf;
     int count;
     MPI_File fh;
@@ -61,7 +60,8 @@ int main( int argc, char *argv[] )
 
     MPI_Barrier( comm );
 
-    for (i=0; i<size; i++) buf[i] = -1;
+    for (int i = 0; i < size; i++)
+      buf[i] = -1;
     MPI_File_read_at_all( fh, sizeof(int)*rank, buf, 10, MPI_INT, &status );
     // if (buf[0] != rank) {
         // errs++;
index 72468b1..a05c21f 100644 (file)
@@ -11,7 +11,6 @@ int main( int argc, char *argv[] )
     int errs = 0;
     int size;
     int rank;
-    int i;
     int* buf;
     int count;
     MPI_File fh;
@@ -63,7 +62,8 @@ int main( int argc, char *argv[] )
     MPI_Barrier( comm );
 
     MPI_File_seek( fh, sizeof(int)*rank, MPI_SEEK_SET );
-    for (i=0; i<size; i++) buf[i] = -1;
+    for (int i = 0; i < size; i++)
+      buf[i] = -1;
     MPI_File_read_all( fh, buf, 10, MPI_INT, &status );
     // if (buf[0] != rank) {
         // errs++;
index c34409a..6423f5b 100644 (file)
@@ -11,7 +11,6 @@ int main( int argc, char *argv[] )
     int errs = 0;
     int size;
     int rank;
-    int i;
     int* buf;
     int count;
     MPI_File fh;
@@ -36,7 +35,8 @@ int main( int argc, char *argv[] )
     }
     MPI_Barrier( comm );
     MPI_File_seek_shared( fh, 0, MPI_SEEK_SET );
-    for (i=0; i<size; i++) buf[i] = -1;
+    for (int i = 0; i < size; i++)
+      buf[i] = -1;
     MPI_File_read_ordered( fh, buf, 10, MPI_INT, &status );
 
     MPI_Barrier(comm);
index 9ad28f1..fecb251 100644 (file)
@@ -11,7 +11,6 @@ int main( int argc, char *argv[] )
     int errs = 0;
     int size;
     int rank;
-    int i;
     int* buf;
     int count;
     MPI_File fh;
@@ -54,7 +53,8 @@ int main( int argc, char *argv[] )
 
     MPI_Barrier( comm );
 
-    for (i=0; i<size; i++) buf[i] = -1;
+    for (int i = 0; i < size; i++)
+      buf[i] = -1;
     MPI_File_read_at( fh, sizeof(int)*rank, buf, 1, MPI_INT, &status );
     // if (buf[0] != rank) {
         // errs++;
index f4563c3..4a3858e 100644 (file)
@@ -11,7 +11,6 @@ int main( int argc, char *argv[] )
     int errs = 0;
     int size;
     int rank;
-    int i;
     int* buf;
     int count;
     MPI_File fh;
@@ -56,7 +55,8 @@ int main( int argc, char *argv[] )
     MPI_Barrier( comm );
 
     MPI_File_seek( fh, sizeof(int)*rank, MPI_SEEK_SET );
-    for (i=0; i<size; i++) buf[i] = -1;
+    for (int i = 0; i < size; i++)
+      buf[i] = -1;
     MPI_File_read( fh, buf, 1, MPI_INT, &status );
     // if (buf[0] != rank) {
         // errs++;