Skip to content
Snippets Groups Projects
Commit 064a168b authored by paun51's avatar paun51 Committed by FKHals
Browse files

Use JSON format for communication MPI -> node-agent

including pre-sending the length of the json string which is required
for the TCP server to be able to process the message.
parent 857af6a4
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include "opal/util/bit_ops.h" #include "opal/util/bit_ops.h"
#include "opal/util/info_subscriber.h" #include "opal/util/info_subscriber.h"
...@@ -54,7 +55,7 @@ ...@@ -54,7 +55,7 @@
#include "ompi/memchecker.h" #include "ompi/memchecker.h"
#define FD_STDIN 0 #define FD_STDIN 0
#define BUFFLEN 64 #define BUFFLEN 128
/* /*
** Table for Fortran <-> C communicator handle conversion ** Table for Fortran <-> C communicator handle conversion
...@@ -138,21 +139,30 @@ static int getProcessAgentRank(uint32_t jobid, uint32_t vpid, size_t size) { ...@@ -138,21 +139,30 @@ static int getProcessAgentRank(uint32_t jobid, uint32_t vpid, size_t size) {
pid_t pid = getpid(); pid_t pid = getpid();
char info_to_send[BUFFLEN]; char info_to_send[BUFFLEN];
memset(info_to_send, 0, BUFFLEN);
snprintf(info_to_send, BUFFLEN, snprintf(info_to_send, BUFFLEN,
"%d,%u,%u,%zu", "{\"msg_type\": 128, \"msg_data\": \"%d,%u,%u,%zu\"}",
pid, vpid, jobid, size); pid, vpid, jobid, size);
if (send(socket_fd, info_to_send, BUFFLEN, 0) < 0) {
// TODO: endianness
uint32_t msg_length = strlen(info_to_send) + 1;
if (send(socket_fd, &msg_length, sizeof(msg_length), 0) < 0) {
errorExit("send");
}
if (send(socket_fd, info_to_send, msg_length, 0) < 0) {
errorExit("send"); errorExit("send");
} }
char rank_to_recv[BUFFLEN]; char rank_to_recv[BUFFLEN];
recv(socket_fd, rank_to_recv, BUFFLEN, 0); recv(socket_fd, rank_to_recv, BUFFLEN, 0);
int received_rank = (int)strtol(rank_to_recv, NULL, 0); rank_to_recv[BUFFLEN-1] = '\0';
printf("Received from server: %d\n", received_rank); printf("Received from server: %s\n", rank_to_recv);
// int received_rank = (int)strtol(rank_to_recv, NULL, 0);
// printf("Received from server: %d\n", received_rank);
close(socket_fd); close(socket_fd);
return received_rank; return vpid; //received_rank;
} }
/* /*
...@@ -187,17 +197,18 @@ int ompi_comm_init(void) ...@@ -187,17 +197,18 @@ int ompi_comm_init(void)
group->grp_proc_count = size; group->grp_proc_count = size;
// transfer the infos about the current processes to the agent // transfer the infos about the current processes to the agent
for (size_t i = 0 ; i < size ; ++i) { // for (size_t i = 0 ; i < size ; ++i) {
opal_process_name_t name = {.vpid = i, .jobid = OMPI_PROC_MY_NAME->jobid}; // opal_process_name_t name = {.vpid = i, .jobid = OMPI_PROC_MY_NAME->jobid};
// call without return just to gain knowledge about the processes // // call without return just to gain knowledge about the processes
getProcessAgentRank(name.jobid, name.vpid, size); // getProcessAgentRank(name.jobid, name.vpid, size);
} // }
getProcessAgentRank(OMPI_PROC_MY_NAME->jobid, OMPI_PROC_MY_NAME->vpid, size);
for (size_t i = 0 ; i < size ; ++i) { for (size_t i = 0 ; i < size ; ++i) {
opal_process_name_t name = {.vpid = i, .jobid = OMPI_PROC_MY_NAME->jobid}; opal_process_name_t name = {.vpid = i, .jobid = OMPI_PROC_MY_NAME->jobid};
/* get desired rank from agent (must be within size!)*/ // /* get desired rank from agent (must be within size!)*/
name.vpid = getProcessAgentRank(name.jobid, name.vpid, size); // name.vpid = getProcessAgentRank(name.jobid, name.vpid, size);
printf("INIT Loop Rank: %u\n", name.vpid); // printf("INIT Loop Rank: %u\n", name.vpid);
/* look for existing ompi_proc_t that matches this name */ /* look for existing ompi_proc_t that matches this name */
group->grp_proc_pointers[i] = (ompi_proc_t *) ompi_proc_lookup (name); group->grp_proc_pointers[i] = (ompi_proc_t *) ompi_proc_lookup (name);
if (NULL == group->grp_proc_pointers[i]) { if (NULL == group->grp_proc_pointers[i]) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment