... and fix associated warnings.
/** Indicates if the remote peer has a piece not stored by the local peer nor requested by the local peer */
int is_interested_and_free(const_peer_t peer, const_connection_t remote_peer)
{
- for (int i = 0; i < FILE_PIECES; i++)
+ for (unsigned int i = 0; i < FILE_PIECES; i++)
if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) && peer_is_not_downloading_piece(peer, i))
return 1;
return 0;
/** @brief Updates the list of who has a piece from a bitfield */
void update_pieces_count_from_bitfield(const_peer_t peer, unsigned int bitfield)
{
- for (int i = 0; i < FILE_PIECES; i++)
+ for (unsigned int i = 0; i < FILE_PIECES; i++)
if (bitfield & (1U << i))
peer->pieces_count[i]++;
}
-int count_pieces(unsigned int bitfield)
+unsigned int count_pieces(unsigned int bitfield)
{
- int count = 0;
+ unsigned int count = 0;
unsigned int n = bitfield;
while (n) {
count += n & 1U;
break;
case MESSAGE_HAVE:
XBT_DEBUG("\t for piece %d", message->piece);
- xbt_assert((message->piece >= 0 && message->piece < FILE_PIECES), "Wrong HAVE message received");
+ xbt_assert((message->piece >= 0 && (unsigned)message->piece < FILE_PIECES), "Wrong HAVE message received");
remote_peer->bitfield = remote_peer->bitfield | (1U << message->piece);
peer->pieces_count[message->piece]++;
// If the piece is in our pieces, we tell the peer that we are interested.
break;
case MESSAGE_REQUEST:
xbt_assert(remote_peer->interested);
- xbt_assert((message->piece >= 0 && message->piece < FILE_PIECES), "Wrong request received");
+ xbt_assert((message->piece >= 0 && (unsigned)message->piece < FILE_PIECES), "Wrong request received");
if (remote_peer->choked_upload == 0) {
XBT_DEBUG("\t for piece %d (%d,%d)", message->piece, message->block_index,
message->block_index + message->block_length);
message->block_index + message->block_length);
xbt_assert(!remote_peer->choked_download);
xbt_assert(remote_peer->choked_download != 1, "Can't received a piece if I'm choked !");
- xbt_assert((message->piece >= 0 && message->piece < FILE_PIECES), "Wrong piece received");
+ xbt_assert((message->piece >= 0 && (unsigned)message->piece < FILE_PIECES), "Wrong piece received");
// TODO: Execute a computation.
if (peer_has_not_piece(peer, message->piece)) {
update_bitfield_blocks(peer, message->piece, message->block_index, message->block_length);
(is_interested(peer, remote_peer) != 0)) {
int nb_interesting_pieces = 0;
// compute the number of interesting pieces
- for (int i = 0; i < FILE_PIECES; i++) {
+ for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i)) {
nb_interesting_pieces++;
}
// get a random interesting piece
int random_piece_index = rand() % nb_interesting_pieces;
int current_index = 0;
- for (int i = 0; i < FILE_PIECES; i++) {
+ for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i)) {
if (random_piece_index == current_index) {
piece = i;
if (count_pieces(peer->bitfield) < 4 && (is_interested_and_free(peer, remote_peer) != 0)) {
int nb_interesting_pieces = 0;
// compute the number of interesting pieces
- for (int i = 0; i < FILE_PIECES; i++) {
+ for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) &&
peer_is_not_downloading_piece(peer, i)) {
nb_interesting_pieces++;
// get a random interesting piece
int random_piece_index = rand() % nb_interesting_pieces;
int current_index = 0;
- for (int i = 0; i < FILE_PIECES; i++) {
+ for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) &&
peer_is_not_downloading_piece(peer, i)) {
if (random_piece_index == current_index) {
int nb_min_pieces = 0;
int current_index = 0;
// compute the smallest number of copies of available pieces
- for (int i = 0; i < FILE_PIECES; i++) {
+ for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (peer->pieces_count[i] < min && peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) &&
peer_is_not_downloading_piece(peer, i))
min = peer->pieces_count[i];
}
xbt_assert(min != SHRT_MAX || (is_interested_and_free(peer, remote_peer) == 0));
// compute the number of rarest pieces
- for (int i = 0; i < FILE_PIECES; i++) {
+ for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (peer->pieces_count[i] == min && peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) &&
peer_is_not_downloading_piece(peer, i))
nb_min_pieces++;
if (nb_min_pieces > 0) {
random_rarest_index = rand() % nb_min_pieces;
}
- for (int i = 0; i < FILE_PIECES; i++) {
+ for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (peer->pieces_count[i] == min && peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) &&
peer_is_not_downloading_piece(peer, i)) {
if (random_rarest_index == current_index) {
if (connection->am_interested != 0) {
int interested = 0;
// Check if the peer still has a piece we want.
- for (int i = 0; i < FILE_PIECES; i++) {
+ for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (peer_has_not_piece(peer, i) && connection_has_piece(connection, i)) {
interested = 1;
break;
void update_bitfield_blocks(peer_t peer, int index, int block_index, int block_length)
{
- xbt_assert((index >= 0 && index <= FILE_PIECES), "Wrong piece.");
- xbt_assert((block_index >= 0 && block_index <= PIECES_BLOCKS), "Wrong block : %d.", block_index);
+ xbt_assert((index >= 0 && (unsigned)index <= FILE_PIECES), "Wrong piece.");
+ xbt_assert((block_index >= 0 && (unsigned)block_index <= PIECES_BLOCKS), "Wrong block : %d.", block_index);
for (int i = block_index; i < (block_index + block_length); i++) {
peer->bitfield_blocks |= (1ULL << (unsigned int)(index * PIECES_BLOCKS + i));
}
/** Returns if a peer has completed the download of a piece */
int piece_complete(const_peer_t peer, int index)
{
- for (int i = 0; i < PIECES_BLOCKS; i++) {
+ for (unsigned int i = 0; i < PIECES_BLOCKS; i++) {
if (!(peer->bitfield_blocks & 1ULL << (index * PIECES_BLOCKS + i))) {
return 0;
}
/** Returns the first block that a peer doesn't have in a piece. If the peer has all blocks of the piece, returns -1. */
int get_first_missing_block_from(const_peer_t peer, int piece)
{
- for (int i = 0; i < PIECES_BLOCKS; i++) {
+ for (unsigned int i = 0; i < PIECES_BLOCKS; i++) {
if (!(peer->bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i))) {
return i;
}
/** Returns a piece that is partially downloaded and stored by the remote peer if any -1 otherwise. */
int partially_downloaded_piece(const_peer_t peer, const_connection_t remote_peer)
{
- for (int i = 0; i < FILE_PIECES; i++) {
+ for (unsigned int i = 0; i < FILE_PIECES; i++) {
if (peer_has_not_piece(peer, i) && connection_has_piece(remote_peer, i) && peer_is_not_downloading_piece(peer, i) &&
get_first_missing_block_from(peer, i) > 0)
return i;
int is_interested_and_free(const_peer_t peer, const_connection_t remote_peer);
void update_pieces_count_from_bitfield(const_peer_t peer, unsigned int bitfield);
-int count_pieces(unsigned int bitfield);
+unsigned int count_pieces(unsigned int bitfield);
int nb_interested_peers(const_peer_t peer);
void leech(peer_t peer);
xbt_assert(argc == 0, "The relay_runner function does not accept any parameter from the XML deployment file");
const char* name = sg_actor_self_get_name();
- int rank = (int)xbt_str_parse_int(name, "Any actor of this example must have a numerical name");
+ unsigned rank = (unsigned)xbt_str_parse_int(name, "Any actor of this example must have a numerical name");
sg_mailbox_t my_mailbox = sg_mailbox_by_name(name);
/* The last actor sends the token back to rank 0, the others send to their right neighbor (rank+1) */
char neighbor_mailbox_name[256];
- snprintf(neighbor_mailbox_name, 255, "%d", rank + 1 == sg_host_count() ? 0 : rank + 1);
+ snprintf(neighbor_mailbox_name, 255, "%u", rank + 1 == sg_host_count() ? 0 : rank + 1);
sg_mailbox_t neighbor_mailbox = sg_mailbox_by_name(neighbor_mailbox_name);
char* res;
if (rank == 0) {
/* The root actor (rank 0) first sends the token then waits to receive it back */
- XBT_INFO("Host \"%d\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox_name);
+ XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox_name);
sg_mailbox_put(neighbor_mailbox, xbt_strdup("Token"), 1000000);
res = (char*)sg_mailbox_get(my_mailbox);
- XBT_INFO("Host \"%d\" received \"%s\"", rank, res);
+ XBT_INFO("Host \"%u\" received \"%s\"", rank, res);
} else {
/* The others actors receive from their left neighbor (rank-1) and send to their right neighbor (rank+1) */
res = (char*)sg_mailbox_get(my_mailbox);
- XBT_INFO("Host \"%d\" received \"%s\"", rank, res);
- XBT_INFO("Host \"%d\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox_name);
+ XBT_INFO("Host \"%u\" received \"%s\"", rank, res);
+ XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox_name);
sg_mailbox_put(neighbor_mailbox, xbt_strdup("Token"), 1000000);
}
free(res);
// check if the id is already in the bucket.
unsigned int id_pos = bucket_find_id(bucket, id);
- if (id_pos == -1) {
+ if (id_pos == (unsigned int)-1) {
/* We check if the bucket is full or not. If it is, we evict an old element */
if (xbt_dynar_length(bucket->nodes) >= BUCKET_SIZE)
xbt_dynar_pop(bucket->nodes, NULL);
}
node->namespace_set[NAMESPACE_SIZE / 2 + j] = message->sender_id;
node->ready += message->steps + 1;
- /* no break */
+ /* fallthrough */
case JOIN_REPLY:
XBT_DEBUG("Joining Reply");
char** options = &argv[1];
while (!strncmp(options[0], "-", 1)) {
- int length = strlen("-nb_bits=");
+ size_t length = strlen("-nb_bits=");
if (!strncmp(options[0], "-nb_bits=", length) && strlen(options[0]) > length) {
nb_bits = (int)xbt_str_parse_int(options[0] + length, "Invalid nb_bits parameter");
XBT_DEBUG("Set nb_bits to %d", nb_bits);
size_t host_count = sg_host_count();
sg_host_t* hosts = sg_host_list();
- for (long i = 0; i < host_count; i++) {
+ for (size_t i = 0; i < host_count; i++) {
XBT_INFO("*** %s properties ****", sg_host_get_name(hosts[i]));
xbt_dict_t props = sg_host_get_properties(hosts[i]);
xbt_dict_cursor_t cursor = NULL;
size_t host_count = sg_host_count();
sg_host_t* hosts = sg_host_list();
- for (long i = 0; i < host_count; i++) {
+ for (size_t i = 0; i < host_count; i++) {
unsigned int disk_count;
sg_disk_t* disks;
sg_host_get_disks(hosts[i], &disk_count, &disks);
simgrid_run();
- for (long i = 0; i < host_count; i++) {
+ for (size_t i = 0; i < host_count; i++) {
unsigned int disk_count;
sg_disk_t* disks;
sg_host_get_disks(hosts[i], &disk_count, &disks);
}
int AttachNode(DGraph* dg, DGNode* nd) {
- int i=0,j,len=0;
+ int i = 0, j;
+ unsigned len = 0;
DGNode **nds =NULL, *tmpnd=NULL;
DGArc **ar=NULL;
{
size_t frag_nb;
size_t i;
- int it;
+ size_t it;
if (ptr == NULL)
return;
for (it=0; it<mdp->heapinfo[block].busy_block.size; it++) {
if (mdp->heapinfo[block+it].type < 0) {
fprintf(stderr,
- "Internal Error: Asked to free a block already marked as free (block=%zu it=%d type=%d). "
+ "Internal Error: Asked to free a block already marked as free (block=%zu it=%zu type=%d). "
"Please report this bug.\n",
block, it, mdp->heapinfo[block].type);
abort();
for (it=0; it<mdp->heapinfo[block].free_block.size; it++) {
if (mdp->heapinfo[block+it].type <0) {
fprintf(stderr,
- "Internal error: Asked to free a block already marked as free (block=%zu it=%d/%zu type=%d). "
+ "Internal error: Asked to free a block already marked as free (block=%zu it=%zu/%zu type=%d). "
"Please report this bug.\n",
block, it, mdp->heapinfo[block].free_block.size, mdp->heapinfo[block].type);
abort();
/* Update the swag of busy blocks containing free fragments by applying the offset to all swag_hooks. Yeah. My hand is right in the fan and I still type */
size_t offset=((char*)newinfo)-((char*)oldinfo);
- for (int i = 1 /*first element of heapinfo describes the mdesc area*/; i < mdp->heaplimit; i++) {
+ for (size_t i = 1 /*first element of heapinfo describes the mdesc area*/; i < mdp->heaplimit; i++) {
update_hook(&newinfo[i].freehook.next, offset);
update_hook(&newinfo[i].freehook.prev, offset);
}
/* 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 (int it = 0; it < BLOCKIFY(mdp->heapsize * sizeof(malloc_info)); it++) {
+ for (size_t 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;
}
static void mmalloc_mark_used(xbt_mheap_t mdp, size_t block, size_t nblocks, size_t requested_size)
{
- for (int it = 0; it < nblocks; it++) {
+ for (size_t it = 0; it < nblocks; it++) {
mdp->heapinfo[block + it].type = MMALLOC_TYPE_UNFRAGMENTED;
mdp->heapinfo[block + it].busy_block.busy_size = 0;
mdp->heapinfo[block + it].busy_block.ignore = 0;
/* Address to block number and vice versa. */
-#define BLOCK(A) (((char*) (A) - (char*) mdp -> heapbase) / BLOCKSIZE + 1)
+#define BLOCK(A) ((size_t)(((char*)(A) - (char*)mdp->heapbase) / BLOCKSIZE + 1))
#define ADDRESS(B) ((void*) (((ADDR2UINT(B)) - 1) * BLOCKSIZE + (char*) mdp -> heapbase))
// Return true iff "enough" elements are equal to (i+value)%256 between buf[start] and buf[stop-1].
static int check_enough(const uint8_t* buf, size_t start, size_t stop, uint8_t value)
{
- int page_size = 0x1000;
+ const unsigned int page_size = 0x1000;
size_t size = stop-start;
if(size <= 2*page_size) // we are not sure to have a whole page that is shared
return 1;
set(CMAKE_C_COMPILER "${CMAKE_BINARY_DIR}/smpi_script/bin/smpicc")
set(CMAKE_Fortran_COMPILER "${CMAKE_BINARY_DIR}/smpi_script/bin/smpiff")
endif()
+ # There are too many warnings with these programs
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-sign-compare")
include_directories(BEFORE "${CMAKE_HOME_DIRECTORY}/include/smpi")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../include/")
#define BAD_ANSWER 100000
-int assoc(int *, int *, int *, MPI_Datatype *);
-
/*
The operation is inoutvec[i] = invec[i] op inoutvec[i]
(see 4.9.4). The order is important.
Note that the computation is in process rank (in the communicator)
order, independent of the root.
*/
-int assoc(int *invec, int *inoutvec, int *len, MPI_Datatype * dtype)
+static void assoc(int *invec, int *inoutvec, int *len, MPI_Datatype *dtype)
{
int i;
for (i = 0; i < *len; i++) {
else
inoutvec[i] = invec[i];
}
- return (1);
}
int main(int argc, char **argv)
#include <stdio.h>
#include <stdlib.h>
-int add(double *, double *, int *, MPI_Datatype *);
/*
* User-defined operation on a long value (tests proper handling of
* possible pipelining in the implementation of reductions with user-defined
* operations).
*/
-int add(double *invec, double *inoutvec, int *len, MPI_Datatype * dtype)
+static void add(double *invec, double *inoutvec, int *len, MPI_Datatype *dtype)
{
int i, n = *len;
for (i = 0; i < n; i++) {
inoutvec[i] = invec[i] + inoutvec[i];
}
- return 0;
}
int main(int argc, char **argv)
MPI_Type_vector(n, 1, stride, MPI_DOUBLE, &vec);
MPI_Type_commit(&vec);
MPI_Type_extent(vec, &vextent);
- if (vextent != ((n - 1) * (MPI_Aint) stride + 1) * sizeof(double)) {
+ if (vextent != (MPI_Aint)(((n - 1) * stride + 1) * sizeof(double))) {
err++;
printf("Vector extent is %ld, should be %ld\n",
(long) vextent, (long) (((n - 1) * stride + 1) * sizeof(double)));
MPI_Type_vector(n, 1, stride, MPI_DOUBLE, &vec);
MPI_Type_commit(&vec);
MPI_Type_extent(vec, &vextent);
- if (vextent != ((n - 1) * (MPI_Aint) stride + 1) * sizeof(double)) {
+ if (vextent != (MPI_Aint)(((n - 1) * stride + 1) * sizeof(double))) {
errs++;
printf("Vector extent is %ld, should be %ld\n",
(long) vextent, (long) (((n - 1) * stride + 1) * sizeof(double)));
errs++;
printf("Incorrect value for key %s\n", keys[i]);
}
- if (strlen(value) != vallen) {
+ if ((int)strlen(value) != vallen) {
errs++;
printf("value_len returned %d but actual len is %d\n", vallen, (int) strlen(value));
}
data = malloc(data_size);
verify = malloc(data_size * BLK_COUNT + HEADER + PAD);
- for (i = 0; i < data_size / sizeof(int); i++)
+ for (i = 0; i < (int)(data_size / sizeof(int)); i++)
data[i] = i;
MPI_Type_create_hindexed_block(BLK_COUNT, data_size, disp, MPI_BYTE, &file_type);
set(warnCXXFLAGS "")
if(enable_compile_warnings)
- set(warnCFLAGS "-fno-common -Wall -Wunused -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing")
+ set(warnCFLAGS "-fno-common -Wall -Wextra -Wunused -Wmissing-declarations -Wpointer-arith -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing")
if(CMAKE_COMPILER_IS_GNUCC)
set(warnCFLAGS "${warnCFLAGS} -Wclobbered -Wformat-signedness -Wno-error=clobbered -Wno-unused-local-typedefs -Wno-error=attributes -Wno-error=maybe-uninitialized")
endif()