Esempio n. 1
0
/**
 * Bittorrent example launcher
 */
int main(int argc, char *argv[])
{
  xbt_dynar_t host_list;
  msg_host_t host;
  unsigned i;

  MSG_init(&argc, argv);

  /* Check the arguments */
  if (argc < 3) {
    printf("Usage: %s platform_file deployment_file \n", argv[0]);
    return -1;
  }

  const char *platform_file = argv[1];
  const char *deployment_file = argv[2];

  MSG_create_environment(platform_file);

  host_list = MSG_hosts_as_dynar();
  xbt_dynar_foreach(host_list, i, host) {
    char descr[512];
    RngStream stream;
    snprintf(descr, sizeof descr, "RngSream<%s>", MSG_host_get_name(host));
    stream = RngStream_CreateStream(descr);
    MSG_host_set_data(host, stream);
  }
Esempio n. 2
0
JNIEXPORT jobject JNICALL
Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls,
                                         jstring jname) {
  msg_host_t host;                /* native host                                          */
  jobject jhost;                /* global reference to the java host instance returned  */

  /* get the C string from the java string */
  const char *name = (*env)->GetStringUTFChars(env, jname, 0);
  if (name == NULL) {
  	jxbt_throw_null(env,bprintf("No host can have a null name"));
  	return NULL;
  }
  /* get the host by name       (the hosts are created during the grid resolution) */
  host = MSG_get_host_by_name(name);

  if (!host) {                  /* invalid name */
    jxbt_throw_host_not_found(env, name);
    (*env)->ReleaseStringUTFChars(env, jname, name);
    return NULL;
  }
  (*env)->ReleaseStringUTFChars(env, jname, name);

  if (!MSG_host_get_data(host)) {       /* native host not associated yet with java host */

    /* Instantiate a new java host */
    jhost = jhost_new_instance(env);

    if (!jhost) {
      jxbt_throw_jni(env, "java host instantiation failed");
      return NULL;
    }

    /* get a global reference to the newly created host */
    jhost = jhost_ref(env, jhost);

    if (!jhost) {
      jxbt_throw_jni(env, "new global ref allocation failed");
      return NULL;
    }
    /* Sets the java host name */
    (*env)->SetObjectField(env, jhost, jhost_field_Host_name, jname);
    /* bind the java host and the native host */
    jhost_bind(jhost, host, env);

    /* the native host data field is set with the global reference to the
     * java host returned by this function
     */
    MSG_host_set_data(host, (void *) jhost);
  }

  /* return the global reference to the java host instance */
  return (jobject) MSG_host_get_data(host);
}
Esempio n. 3
0
    xbt_dynar_foreach (process_list, cursor, process)
    {
	process_name = MSG_process_get_name (process);
	host = MSG_process_get_host (process);
	if ( strcmp (process_name, "worker") == 0 )
	{
	    config.workers[wid] = host;
	    /* Set the worker ID as its data. */
	    wi = xbt_new (struct w_info_s, 1);
	    wi->wid = wid;
	    MSG_host_set_data (host, (void*)wi);
	    /* Add the worker's cpu power to the grid total. */
	    config.grid_cpu_power += MSG_get_host_speed (host);
	    wid++;
	}
Esempio n. 4
0
/** Bittorrent example launcher */
int main(int argc, char* argv[])
{
  msg_host_t host;
  unsigned i;

  MSG_init(&argc, argv);

  /* Check the arguments */
  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file", argv[0]);

  MSG_create_environment(argv[1]);

  xbt_dynar_t host_list = MSG_hosts_as_dynar();
  xbt_dynar_foreach (host_list, i, host) {
    char descr[512];
    snprintf(descr, sizeof descr, "RngSream<%s>", MSG_host_get_name(host));
    RngStream stream = RngStream_CreateStream(descr);
    MSG_host_set_data(host, stream);
  }
Esempio n. 5
0
JNIEXPORT jobject JNICALL
Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) {
  jobject jhost;

  msg_host_t host = MSG_host_self();

  if (!MSG_host_get_data(host)) {
    /* the native host not yet associated with the java host instance */

    /* instanciate a new java host instance */
    jhost = jhost_new_instance(env);

    if (!jhost) {
      jxbt_throw_jni(env, "java host instantiation failed");
      return NULL;
    }

    /* get a global reference to the newly created host */
    jhost = jhost_ref(env, jhost);

    if (!jhost) {
      jxbt_throw_jni(env, "global ref allocation failed");
      return NULL;
    }
    /* Sets the host name */
    const char *name = MSG_host_get_name(host);
    jobject jname = (*env)->NewStringUTF(env,name);
    (*env)->SetObjectField(env, jhost, jhost_field_Host_name, jname);
    /* Bind & store it */
    jhost_bind(jhost, host, env);
    MSG_host_set_data(host, (void *) jhost);
  } else {
    jhost = (jobject) MSG_host_get_data(host);
  }

  return jhost;
}
Esempio n. 6
0
 xbt_dynar_foreach (host_list, i, host) {
   RngStream stream = (RngStream)MSG_host_get_data(host);
   RngStream_DeleteStream(&stream);
   MSG_host_set_data(host, NULL);
 }