Skip to content
Snippets Groups Projects
Commit d83cf7d2 authored by FKHals's avatar FKHals
Browse files

Add agent-rank-setting function to comm_init

as a first draft of an implementation to change the process rank by an
external agent.
parent 060f129a
Branches
No related tags found
No related merge requests found
......@@ -33,6 +33,10 @@
#include "ompi_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include "opal/util/bit_ops.h"
#include "opal/util/info_subscriber.h"
......@@ -49,6 +53,10 @@
#include "ompi/dpm/dpm.h"
#include "ompi/memchecker.h"
#define SOCKET_PATH "/home/beach/Dokumente/Uni/Informatik_BA/Bachelorarbeit_MPI/sockets_mpi_test/socket"
#define FD_STDIN 0
#define BUFFLEN 64
/*
** Table for Fortran <-> C communicator handle conversion
** Also used by P2P code to lookup communicator based
......@@ -82,6 +90,46 @@ OBJ_CLASS_INSTANCE(ompi_communicator_t, opal_infosubscriber_t,
shortcut for finalize and abort. */
int ompi_comm_num_dyncomm=0;
static void errorExit(char* msg) {
perror(msg);
exit(1);
}
// TODO: Change int return to size_t!
static int getProcessAgentRank(uint32_t jobid, size_t size) {
struct sockaddr_un strAddr;
socklen_t lenAddr;
int fdSock;
if ((fdSock=socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
errorExit("socket");
}
strAddr.sun_family=AF_LOCAL; /* Unix domain */
strcpy(strAddr.sun_path, SOCKET_PATH);
lenAddr=sizeof(strAddr.sun_family)+strlen(strAddr.sun_path);
if (connect(fdSock, (struct sockaddr*)&strAddr, lenAddr) !=0 ) {
errorExit("connect");
}
pid_t pid = getpid();
char info_to_send[BUFFLEN];
snprintf(info_to_send, BUFFLEN+1, "Spawned - PID: %d, jobID: %u, size: %zu", pid, jobid, size);
if (send(fdSock, info_to_send, BUFFLEN+1, 0) < 0) {
errorExit("send");
}
char rank_to_recv[BUFFLEN];
recv(fdSock, rank_to_recv, BUFFLEN+1, 0);
int received_rank = (int)strtol(rank_to_recv, NULL, 0);
printf("Received from server: %d\n", received_rank);
close(fdSock);
return received_rank;
}
/*
* Initialize comm world/self/null/parent.
*/
......@@ -115,8 +163,12 @@ int ompi_comm_init(void)
for (size_t i = 0 ; i < size ; ++i) {
opal_process_name_t name = {.vpid = i, .jobid = OMPI_PROC_MY_NAME->jobid};
/* get desired rank from agent (must be within size!)*/
// TODO: Change int to size_t
size_t desired_rank = getProcessAgentRank(name.jobid, size);
printf("INIT Loop Rank: %zu\n", desired_rank);
/* 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[desired_rank] = (ompi_proc_t *) ompi_proc_lookup (name);
if (NULL == group->grp_proc_pointers[i]) {
/* set sentinel value */
group->grp_proc_pointers[i] = (ompi_proc_t *) ompi_proc_name_to_sentinel (name);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment