#define GRID_SIZE 3
#define NODE_MATRIX_SIZE 300
#define GRID_NUM_NODES GRID_SIZE * GRID_SIZE
#define MATRIX_SIZE NODE_MATRIX_SIZE * GRID_SIZE
#define MAILBOX_NAME_SIZE 10
#define NEIGHBOURS_COUNT GRID_SIZE - 1
typedef struct s_node_job{
int row;
int col;
int nodes_in_row[NEIGHBOURS_COUNT];
int nodes_in_col[NEIGHBOURS_COUNT];
} s_node_job_t;
typedef s_node_job_t *node_job_t;
typedef struct s_result {
int row;
int col;
} s_result_t;
typedef s_result_t *result_t;
static void broadcast_jobs(node_job_t *
jobs);
static node_job_t wait_job(int selfid);
static void receive_results(result_t *results);
static void task_cleanup(void *arg);
{
char my_mbox[MAILBOX_NAME_SIZE];
node_job_t myjob;
node_job_t
jobs[GRID_NUM_NODES];
xbt_assert(argc != 1,
"Wrong number of arguments for this node");
int myid =
xbt_str_parse_int(argv[1],
"Invalid ID received as first node parameter: %s");
snprintf(my_mbox, MAILBOX_NAME_SIZE - 1, "%d", myid);
if (myid == 0){
create_jobs(A, B, jobs);
myjob = jobs[0];
broadcast_jobs(jobs + 1);
} else {
myjob = wait_job(myid);
}
XBT_VERB(
"Start Multiplication's Main-loop");
for (int k=0; k < GRID_SIZE; k++){
if(k == myjob->col){
XBT_VERB(
"Broadcast sA(%d,%d) to row %d", myjob->row, k, myjob->row);
broadcast_matrix(myjob->A, NEIGHBOURS_COUNT, myjob->nodes_in_row);
}
if(k == myjob->row){
XBT_VERB(
"Broadcast sB(%d,%d) to col %d", k, myjob->col, myjob->col);
broadcast_matrix(myjob->B, NEIGHBOURS_COUNT, myjob->nodes_in_col);
}
if(myjob->row == k && myjob->col == k){
}else if(myjob->row == k){
get_sub_matrix(&sA, myid);
}else if(myjob->col == k){
get_sub_matrix(&sB, myid);
}else{
get_sub_matrix(&sA, myid);
get_sub_matrix(&sB, myid);
}
}
if(myid == 0){
int node;
result_t results[GRID_NUM_NODES] = {0};
receive_results(results);
for (node = 1; node < GRID_NUM_NODES; node++){
NODE_MATRIX_SIZE * results[node]->row, NODE_MATRIX_SIZE * results[node]->col,
0, 0, NULL);
}
}else{
XBT_VERB(
"Multiplication done. Send the sub-result.");
result->row = myjob->row;
result->col = myjob->col;
}
return 0;
}
static void broadcast_jobs(node_job_t *jobs)
{
char node_mbox[MAILBOX_NAME_SIZE];
for (int node = 1; node < GRID_NUM_NODES; node++){
snprintf(node_mbox, MAILBOX_NAME_SIZE - 1, "%d", node);
}
for (int node = 1; node < GRID_NUM_NODES; node++)
}
static node_job_t wait_job(int selfid)
{
char self_mbox[MAILBOX_NAME_SIZE];
snprintf(self_mbox, MAILBOX_NAME_SIZE - 1, "%d", selfid);
xbt_assert(err ==
MSG_OK,
"Error while receiving from %s (%d)", self_mbox, (
int)err);
XBT_VERB(
"Got Job (%d,%d)", job->row, job->col);
return job;
}
{
char node_mbox[MAILBOX_NAME_SIZE];
for(int node=0; node < num_nodes; node++){
snprintf(node_mbox, MAILBOX_NAME_SIZE - 1, "%d", nodes[node]);
XBT_DEBUG(
"sub-matrix sent to %s", node_mbox);
}
}
{
char node_mbox[MAILBOX_NAME_SIZE];
snprintf(node_mbox, MAILBOX_NAME_SIZE - 1, "%d", selfid);
xbt_assert(err ==
MSG_OK,
"Error while receiving from %s (%d)", node_mbox, (
int)err);
}
static void task_cleanup(void *arg){
}
int main(
int argc,
char *argv[])
{
const char *platform = "../../platforms/cluster.xml";
if (argc > 1)
platform = argv[1];
for(int i = 0 ; i< 9; i++) {
char *hostname =
bprintf(
"node-%d.acme.org", i);
argvF[2] = NULL;
}
}
{
int row = 0;
int col = 0;
for (int node = 0; node < GRID_NUM_NODES; node++){
jobs[node]->row = row;
jobs[node]->col = col;
int k=0;
for (int j = 0; j < GRID_SIZE; j++) {
if (node != (GRID_SIZE * row) + j) {
jobs[node]->nodes_in_row[k] = (GRID_SIZE * row) + j;
k++;
}
}
k=0;
for (int j = 0; j < GRID_SIZE; j++) {
if (node != (GRID_SIZE * j) + col) {
jobs[node]->nodes_in_col[k] = (GRID_SIZE * j) + col;
k++;
}
}
jobs[node]->A =
xbt_matrix_new_sub(A, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE * row, NODE_MATRIX_SIZE * col, NULL);
jobs[node]->B =
xbt_matrix_new_sub(B, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE, NODE_MATRIX_SIZE * row, NODE_MATRIX_SIZE * col, NULL);
col++;
if (col >= GRID_SIZE){
col = 0;
row++;
}
}
}
static void receive_results(result_t *results) {
for (int node = 1; node < GRID_NUM_NODES; node++)
for (int node = 1; node < GRID_NUM_NODES; node++)
for (int node = 1; node < GRID_NUM_NODES; node++){
}
}