Skip to content
Snippets Groups Projects
Select Git revision
  • 1a3b94b1a2f2ce836cecca4349eb22eb5509e3e3
  • master default
  • onesided-mpi-rdma
  • origin-master
  • rdma-only-subparts-update-keep-update
  • swift-rdma
  • rdma-only-subparts-update
  • rdma-only-subparts-update-flamingo-cellids
  • rdma-only-subparts-update-flamingo
  • rdma-only-subparts-update-keep
  • rdma-only-subparts
  • queue-timers
  • rdma-only-subcopies
  • rdma-only-subsends
  • rdma-only
  • rdma-only-multiple-sends
  • subsends
  • queue-timers-clean
  • onesided-mpi-single-recv-window
  • onesided-mpi-recv-window
  • onesided-mpi-recv-cache
  • v0.9.0
  • v0.8.5
  • v0.8.4
  • v0.8.3
  • v0.8.2
  • v0.8.1
  • v0.8.0
  • v0.7.0
  • v0.6.0
  • v0.5.0
  • v0.4.0
  • v0.3.0
  • v0.2.0
  • v0.1.0-pre
  • v0.1
  • v0.0
37 results

queue.c

  • Forked from SWIFT / SWIFTsim
    Source project has a limited visibility.
    queue.c 9.68 KiB
    /*******************************************************************************
     * This file is part of SWIFT.
     * Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Lesser General Public License as published
     * by the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU Lesser General Public License
     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     *
     ******************************************************************************/
    
    /* Config parameters. */
    #include "../config.h"
    
    /* Some standard headers. */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    /* MPI headers. */
    #ifdef WITH_MPI
    #include <mpi.h>
    #endif
    
    /* This object's header. */
    #include "queue.h"
    
    /* Local headers. */
    #include "atomic.h"
    #include "error.h"
    #include "memswap.h"
    
    /**
     * @brief Push the task at the given index up the heap until it is either at the
     * top or smaller than its parent.
     *
     * @param q The task #queue.
     * @param ind The index of the task to be sifted-down in the queue.
     *
     * @return The new index of the entry.
     */
    int queue_bubble_up(struct queue *q, int ind) {
      /* Set some pointers we will use often. */
      struct queue_entry *entries = q->entries;
      const float w = entries[ind].weight;
    
      /* While we are not yet at the top of the heap... */
      while (ind > 0) {
        /* Check if the parent is larger and bail if not.. */
        const int parent = (ind - 1) / 2;
        if (w < entries[parent].weight) break;
    
        /* Parent is not larger, so swap. */
        memswap(&entries[ind], &entries[parent], sizeof(struct queue_entry));
        ind = parent;
      }
    
      return ind;
    }
    
    /**
     * @brief Push the task at the given index down the heap until both its children