Skip to content

Commit

Permalink
added a lot of code on the client side
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier committed Mar 25, 2024
1 parent 4e435a7 commit 0e5da51
Show file tree
Hide file tree
Showing 22 changed files with 2,050 additions and 156 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) 2020 The University of Chicago
# (C) 2024 The University of Chicago
# See COPYRIGHT in top-level directory.
cmake_minimum_required (VERSION 3.8)
project (flock C CXX)
Expand Down
2 changes: 1 addition & 1 deletion examples/client.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/server.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand Down
2 changes: 1 addition & 1 deletion include/flock/flock-backend.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand Down
2 changes: 1 addition & 1 deletion include/flock/flock-client.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand Down
2 changes: 1 addition & 1 deletion include/flock/flock-common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand Down
44 changes: 29 additions & 15 deletions include/flock/flock-group.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand Down Expand Up @@ -57,7 +57,7 @@ flock_return_t flock_group_handle_create(
* "transport": "<protocol>",
* "credentials": 42,
* "members": [
* { "address": "<some-address>", "provider_id": 1234 },
* { "rank": 12, "address": "<some-address>", "provider_id": 1234 },
* ...
* ],
* "metadata": {
Expand Down Expand Up @@ -170,12 +170,12 @@ flock_return_t flock_group_live_member_count(
*
* @param void* User-provided context
* @param size_t Member rank
* @param hg_addr_t Address of the member
* @param const char* Address of the member
* @param uint16_t Provider ID of the member
*
* @return true to continue iterating, false to break
*/
typedef bool (*flock_member_access_fn)(void*, size_t, hg_addr_t, uint16_t);
typedef bool (*flock_member_access_fn)(void*, size_t, const char*, uint16_t);

/**
* @brief Iterate over the members of the group. The iteration
Expand Down Expand Up @@ -213,6 +213,25 @@ flock_return_t flock_group_member_get_address(
size_t rank,
hg_addr_t* address);

/**
* @brief Get the address of a member at a given rank, as a string.
*
* @important The caller is responsible for calling free on the address.
*
* If no member exist at that rank, the address will be set to NULL
* and the function will return FLOCK_ERR_NO_MEMBER.
*
* @param[in] handle Group handle
* @param[in] rank Rank of the process
* @param[out] address Address of the process
*
* @return FLOCK_SUCCESS or error code defined in flock-common.h
*/
flock_return_t flock_group_member_get_address_string(
flock_group_handle_t handle,
size_t rank,
char** address);

/**
* @brief Get the provider ID of a member at a given rank.
*
Expand Down Expand Up @@ -241,7 +260,7 @@ flock_return_t flock_group_member_get_provider_id(
*/
flock_return_t flock_group_member_get_rank(
flock_group_handle_t handle,
hg_addr_t address,
const char* address,
uint16_t provider_id,
size_t* rank);

Expand All @@ -250,13 +269,11 @@ flock_return_t flock_group_member_get_rank(
*
* @param void* User-provided context
* @param const char* Metadata key
* @param size_t Size of the metadata key
* @param const char* Metadata value
* @param size_t Size of the metadata value
*
* @return true to continue iterating, false to break
*/
typedef bool (*flock_metadata_access_fn)(void*, const char*, size_t, const char*, size_t);
typedef bool (*flock_metadata_access_fn)(void*, const char*, const char*);

/**
* @brief Iterate over the metadata associated with the group.
Expand All @@ -276,9 +293,11 @@ flock_return_t flock_group_metadata_iterate(
* @brief Get the value associated with a given key and pass
* the key/value pair to the provided access function.
*
* If no value is found associated with the specified key,
* the callback will be called with NULL as the value.
*
* @param handle Group handle
* @param key Metadata key
* @param key_size Size of the key
* @param access_fn Function to call on the metadata
* @param context Context to pass to the callback
*
Expand All @@ -287,7 +306,6 @@ flock_return_t flock_group_metadata_iterate(
flock_return_t flock_group_metadata_access(
flock_group_handle_t handle,
const char* key,
size_t key_size,
flock_metadata_access_fn access_fn,
void* context);

Expand All @@ -299,18 +317,14 @@ flock_return_t flock_group_metadata_access(
*
* @param handle Group handle
* @param key Key to add
* @param key_size Size of the key
* @param value Value to add
* @param value_size Size of the value
*
* @return FLOCK_SUCCESS or error code defined in flock-common.h
*/
flock_return_t flock_group_metadata_set(
flock_group_handle_t handle,
const char* key,
size_t key_size,
const char* value,
size_t value_size);
const char* value);

/**
* @brief Update the internal view of the group.
Expand Down
2 changes: 1 addition & 1 deletion include/flock/flock-server.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ set (server-src-files
provider.c)

set (client-src-files
client.c)
client.c
group-handle.c)

set (dummy-src-files
dummy/dummy-backend.c)
Expand Down
2 changes: 1 addition & 1 deletion src/bedrock-module.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand Down
107 changes: 24 additions & 83 deletions src/client.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand All @@ -13,15 +13,18 @@ flock_return_t flock_client_init(margo_instance_id mid, ABT_pool pool, flock_cli
if(!c) return FLOCK_ERR_ALLOCATION;

c->mid = mid;
if(pool == ABT_POOL_NULL)
margo_get_handler_pool(mid, &pool);
c->pool = pool;

hg_bool_t flag;
hg_id_t id;
margo_registered_name(mid, "flock_sum", &id, &flag);
margo_registered_name(mid, "flock_update", &id, &flag);

if(flag == HG_TRUE) {
margo_registered_name(mid, "flock_sum", &c->sum_id, &flag);
margo_registered_name(mid, "flock_update", &c->update_id, &flag);
} else {
c->sum_id = MARGO_REGISTER(mid, "flock_sum", sum_in_t, sum_out_t, NULL);
c->update_id = MARGO_REGISTER(mid, "flock_update", void, update_out_t, NULL);
}

*client = c;
Expand All @@ -39,90 +42,20 @@ flock_return_t flock_client_finalize(flock_client_t client)
return FLOCK_SUCCESS;
}

flock_return_t flock_group_handle_create(
flock_client_t client,
hg_addr_t addr,
uint16_t provider_id,
uint32_t mode,
flock_group_handle_t* handle)
{
if(client == FLOCK_CLIENT_NULL)
return FLOCK_ERR_INVALID_ARGS;

hg_return_t ret;

if(mode & FLOCK_MODE_INIT_UPDATE) {
char buffer[sizeof("flock")];
size_t bufsize = sizeof("flock");
ret = margo_provider_get_identity(client->mid, addr, provider_id, buffer, &bufsize);
if(ret != HG_SUCCESS || strcmp("flock", buffer) != 0)
return FLOCK_ERR_INVALID_PROVIDER;
}

flock_group_handle_t rh =
(flock_group_handle_t)calloc(1, sizeof(*rh));

if(!rh) return FLOCK_ERR_ALLOCATION;

ret = margo_addr_dup(client->mid, addr, &(rh->addr));
if(ret != HG_SUCCESS) {
free(rh);
return FLOCK_ERR_FROM_MERCURY;
}

rh->client = client;
rh->provider_id = provider_id;
rh->refcount = 1;

client->num_group_handles += 1;

*handle = rh;
return FLOCK_SUCCESS;
}

flock_return_t flock_group_handle_ref_incr(
flock_group_handle_t handle)
{
if(handle == FLOCK_GROUP_HANDLE_NULL)
return FLOCK_ERR_INVALID_ARGS;
handle->refcount += 1;
return FLOCK_SUCCESS;
}

flock_return_t flock_group_handle_release(flock_group_handle_t handle)
{
if(handle == FLOCK_GROUP_HANDLE_NULL)
return FLOCK_ERR_INVALID_ARGS;
handle->refcount -= 1;
if(handle->refcount == 0) {
margo_addr_free(handle->client->mid, handle->addr);
handle->client->num_group_handles -= 1;
free(handle);
}
return FLOCK_SUCCESS;
}

#if 0
flock_return_t flock_compute_sum(
flock_return_t flock_group_update(
flock_group_handle_t handle,
int32_t x,
int32_t y,
int32_t* result)
flock_request_t* req)
{
hg_handle_t h;
sum_in_t in;
sum_out_t out;
update_out_t out;
hg_return_t hret;
flock_return_t ret;

in.x = x;
in.y = y;

hret = margo_create(handle->client->mid, handle->addr, handle->client->sum_id, &h);
hret = margo_create(handle->client->mid, handle->addr, handle->client->update_id, &h);
if(hret != HG_SUCCESS)
return FLOCK_ERR_FROM_MERCURY;

hret = margo_provider_forward(handle->provider_id, h, &in);
hret = margo_provider_forward(handle->provider_id, h, NULL);
if(hret != HG_SUCCESS) {
ret = FLOCK_ERR_FROM_MERCURY;
goto finish;
Expand All @@ -134,14 +67,22 @@ flock_return_t flock_compute_sum(
goto finish;
}

ret = out.ret;
if(ret == FLOCK_SUCCESS)
*result = out.result;
LOCK_GROUP_VIEW(&handle->view);
handle->view.capacity = out.view.capacity;
handle->view.size = out.view.size;
handle->view.members = out.view.members;
handle->view.metadata = out.view.metadata;
UNLOCK_GROUP_VIEW(&handle->view);

// Prevent margo_free_output from freeing the content we just moved
out.view.size = 0;
out.view.capacity = 0;
out.view.members = NULL;
out.view.metadata = NULL;

margo_free_output(h, &out);

finish:
margo_destroy(h);
return ret;
}
#endif
19 changes: 13 additions & 6 deletions src/client.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand All @@ -12,15 +12,22 @@

typedef struct flock_client {
margo_instance_id mid;
hg_id_t sum_id;
ABT_pool pool;
hg_id_t update_id;
uint64_t num_group_handles;
} flock_client;

typedef struct flock_group_handle {
flock_client_t client;
hg_addr_t addr;
uint16_t provider_id;
uint64_t refcount;
flock_client_t client;
uint64_t refcount;
// Bellow are the address and provider ID of the member
// that will be contacted in priority for updates
hg_addr_t addr;
uint16_t provider_id;
// Group view
group_view_t view;
// Credentials
int64_t credentials;
} flock_group_handle;

#endif
4 changes: 2 additions & 2 deletions src/config.h.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* (C) 2020 The University of Chicago
*
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#ifndef _CONFIG_H
Expand Down
2 changes: 1 addition & 1 deletion src/dummy/dummy-backend.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/dummy/dummy-backend.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) 2020 The University of Chicago
* (C) 2024 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
Expand Down
Loading

0 comments on commit 0e5da51

Please sign in to comment.