00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <sys/types.h>
00037 #include <sys/socket.h>
00038 #include <orbisquartus.h>
00039 #include <mini_mpi.h>
00040 #include <daemon.h>
00041 #include <config.h>
00042 #include <virtual_time.h>
00043
00044
00045 int OrbisQuartus::_init()
00046 {
00047 pthread_mutex_init(&sim_mutex, NULL);
00048 }
00049
00050
00051
00052 int OrbisQuartus::_get_config(int argc, char *argv[])
00053 {
00054 int i, ctl_sock, numbytes, recvd_bytes, flag = 0;
00055 int assign_len, cfg_len;
00056 char len_str[INTEGER_STRING];
00057 char *assignmt, *assgn, *sptr, *config;
00058
00059 MPI_Initialized(&flag);
00060 if (flag == 0) {
00061 MPI_Init(&argc, &argv);
00062 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
00063 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
00064 }
00065 MPI_Comm_socket(MPI_COMM_WORLD, &ctl_sock);
00066
00067
00068 if ((numbytes = recv(ctl_sock, len_str, INTEGER_STRING, 0)) < 0)
00069 return numbytes;
00070 num_mynodes = atoi(len_str);
00071 assign_len = (2 * num_mynodes) - 1;
00072
00073 assignmt = (char*) malloc(sizeof(char) * (assign_len + 1));
00074 if ((numbytes = recv(ctl_sock, assignmt, assign_len, 0)) < 0)
00075 return numbytes;
00076
00077 mynodes = (unsigned long*) malloc(sizeof(unsigned long) * num_mynodes);
00078 assgn = assignmt;
00079 for (i = 0; i < num_mynodes &&
00080 (sptr = index(assgn, ',')) != NULL; i++) {
00081 sptr = '\0';
00082 sscanf(assgn, "%lu", &mynodes[i]);
00083 assgn = sptr + 1;
00084 }
00085 sscanf(assgn, "%lu", &mynodes[i]);
00086 free(assignmt);
00087
00088
00089 if ((numbytes = recv(ctl_sock, len_str, INTEGER_STRING, 0)) < 0)
00090 return numbytes;
00091 cfg_len = atoi(len_str);
00092
00093 numbytes = 0;
00094 config = (char*) malloc(sizeof(char) * (cfg_len + 1));
00095 while (numbytes < cfg_len) {
00096 recvd_bytes = recv(ctl_sock, config, cfg_len, 0);
00097 numbytes += recvd_bytes;
00098 }
00099 cfg.xml_to_cfg(config);
00100 free(config);
00101
00102 return 0;
00103 }
00104
00105
00106 void OrbisQuartus::stop(void)
00107 {
00108 daemon_quit();
00109 pthread_join(sim_thread, NULL);
00110 pthread_join(vt_thread, NULL);
00111 pthread_join(ctl_thread, NULL);
00112 MPI_Finalize();
00113 }