Ejemplo n.º 1
0
/*******************************************************************************
*
* Name: CreateEngineAndConnectToViewer
*
* Purpose: Intialize the engine and connect to the viewer.
*
* Author: Jeremy Meredith, B Division, Lawrence Livermore National Laboratory
*
* Modifications:
*
*******************************************************************************/
static int CreateEngineAndConnectToViewer(void)
{
    /* get the engine */
    engine = v_getengine();
    if (!engine)
    {
        return FALSE;
    }

    if (!v_initialize(engine, engine_argc, engine_argv))
    {
        VisItDisconnect();
        return FALSE;
    }

    if (!v_connectviewer(engine, engine_argc, engine_argv))
    {
        VisItDisconnect();
        return FALSE;
    }

    return TRUE;
}
Ejemplo n.º 2
0
void mainloop(simulation_data *sim)
{
    int blocking, visitstate, err = 0;

    do
    {
        blocking = (sim->runMode == VISIT_SIMMODE_RUNNING) ? 0 : 1;
        /* Get input from VisIt or timeout so the simulation can run. */
        visitstate = VisItDetectInput(blocking, -1);

        /* Do different things depending on the output from VisItDetectInput. */
        if(visitstate >= -5 && visitstate <= -1)
        {
            fprintf(stderr, "Can't recover from error!\n");
            err = 1;
        }
        else if(visitstate == 0)
        {
            /* There was no input from VisIt, return control to sim. */
            simulate_one_timestep(sim);
        }
        else if(visitstate == 1)
        {
            /* VisIt is trying to connect to sim. */
            if(VisItAttemptToCompleteConnection())
            {
                fprintf(stderr, "VisIt connected\n");

                /* Register data access callbacks */
                VisItSetGetMetaData(SimGetMetaData, (void*)sim);
            }
            else
                fprintf(stderr, "VisIt did not connect\n");
        }
        else if(visitstate == 2)
        {
            /* VisIt wants to tell the engine something. */
            sim->runMode = VISIT_SIMMODE_STOPPED;
            if(!VisItProcessEngineCommand())
            {
                /* Disconnect on an error or closed connection. */
                VisItDisconnect();
                /* Start running again if VisIt closes. */
                sim->runMode = VISIT_SIMMODE_RUNNING;
            }
        }
    } while(!sim->done && err == 0);
}
Ejemplo n.º 3
0
void mainloop(simulation_data *sim)
{
    int blocking, visitstate, err = 0;

    do
    {
        blocking = (sim->runMode == VISIT_SIMMODE_RUNNING) ? 0 : 1;
/* CHANGE 3 */
        /* Get input from VisIt or timeout so the simulation can run. */
        if(sim->par_rank == 0)
            visitstate = VisItDetectInput(blocking, -1);
#ifdef PARALLEL
        MPI_Bcast(&visitstate, 1, MPI_INT, 0, MPI_COMM_WORLD);
#endif
        /* Do different things depending on the output from VisItDetectInput. */
        if(visitstate >= -5 && visitstate <= -1)
        {
            fprintf(stderr, "Can't recover from error!\n");
            err = 1;
        }
        else if(visitstate == 0)
        {
            /* There was no input from VisIt, return control to sim. */
            simulate_one_timestep(sim);
        }
        else if(visitstate == 1)
        {
            /* VisIt is trying to connect to sim. */
            if(VisItAttemptToCompleteConnection())
                fprintf(stderr, "VisIt connected\n");
            else
                fprintf(stderr, "VisIt did not connect\n");
        }
        else if(visitstate == 2)
        {
            /* VisIt wants to tell the engine something. */
            sim->runMode = VISIT_SIMMODE_STOPPED;
/* CHANGE 4 */
            if(!ProcessVisItCommand(sim))
            {
                /* Disconnect on an error or closed connection. */
                VisItDisconnect();
                /* Start running again if VisIt closes. */
                sim->runMode = VISIT_SIMMODE_RUNNING;
            }
        }
    } while(!sim->done && err == 0);
}
Ejemplo n.º 4
0
void mainloop(simulation_data *sim)
{
    int blocking, visitstate, err = 0;

    /* If we're not running by default then simulate once there's something
     * once VisIt connects.
     */
    if(sim->runMode == SIM_STOPPED)
        simulate_one_timestep(sim);

    if (sim->par_rank == 0)
    {
        fprintf(stderr, "command> ");
        fflush(stderr);
    }

    do
    {
        blocking = (sim->runMode == SIM_RUNNING) ? 0 : 1;
        /* Get input from VisIt or timeout so the simulation can run. */
        if(sim->par_rank == 0)
        {
            visitstate = VisItDetectInput(blocking, fileno(stdin));
        }
#ifdef PARALLEL
        /* Broadcast the return value of VisItDetectInput to all procs. */
        MPI_Bcast(&visitstate, 1, MPI_INT, 0, sim->par_comm);
#endif
        /* Do different things depending on the output from VisItDetectInput. */
        switch(visitstate)
        {
        case 0:
            /* There was no input from VisIt, return control to sim. */
            simulate_one_timestep(sim);
            break;
        case 1:
            /* VisIt is trying to connect to sim. */
            if(VisItAttemptToCompleteConnection() == VISIT_OKAY)
            {
                fprintf(stderr, "VisIt connected\n");
                VisItSetCommandCallback(ControlCommandCallback, (void*)sim);
                VisItSetSlaveProcessCallback2(SlaveProcessCallback, (void*)sim);

                VisItSetGetMetaData(SimGetMetaData, (void*)sim);
                VisItSetGetMesh(SimGetMesh, (void*)sim);
                VisItSetGetVariable(SimGetVariable, (void*)sim);
                VisItSetGetDomainList(SimGetDomainList, (void*)sim);
            }
            else 
            {
                /* Print the error message */
                char *err = VisItGetLastError();
                fprintf(stderr, "VisIt did not connect: %s\n", err);
                free(err);
            }
            break;
        case 2:
            /* VisIt wants to tell the engine something. */
            if(!ProcessVisItCommand(sim))
            {
                /* Disconnect on an error or closed connection. */
                VisItDisconnect();
                /* Start running again if VisIt closes. */
                /*sim->runMode = SIM_RUNNING;*/
            }
            break;
        case 3:
            /* VisItDetectInput detected console input - do something with it.
             * NOTE: you can't get here unless you pass a file descriptor to
             * VisItDetectInput instead of -1.
             */
            ProcessConsoleCommand(sim);
            if (sim->par_rank == 0)
            {
                fprintf(stderr, "command> ");
                fflush(stderr);
            }
            break;
        default:
            fprintf(stderr, "Can't recover from error %d!\n", visitstate);
            err = 1;
            break;
        }
    } while(!sim->done && err == 0);
}
Ejemplo n.º 5
0
void mainloop(simulation_data *sim)
{
    int blocking, visitstate, err = 0;

    /* Do one iteration */
    simulate_one_timestep(sim);

    /* main loop */
    fprintf(stderr, "command> ");
    fflush(stderr);
    do
    {
        blocking = (sim->runMode == SIM_RUNNING) ? 0 : 1;
        /* Get input from VisIt or timeout so the simulation can run. */
        visitstate = VisItDetectInput(blocking, fileno(stdin));

        /* Do different things depending on the output from VisItDetectInput. */
        if(visitstate >= -5 && visitstate <= -1)
        {
            fprintf(stderr, "Can't recover from error!\n");
            err = 1;
        }
        else if(visitstate == 0)
        {
            /* There was no input from VisIt, return control to sim. */
            simulate_one_timestep(sim);
        }
        else if(visitstate == 1)
        {
            /* VisIt is trying to connect to sim. */
            if(VisItAttemptToCompleteConnection() == VISIT_OKAY)
            {
                sim->runMode = SIM_STOPPED;
                fprintf(stderr, "VisIt connected\n");
                VisItSetCommandCallback(ControlCommandCallback, (void*)sim);

                VisItSetGetMetaData(SimGetMetaData, (void*)sim);
                VisItSetGetCurve(SimGetCurve, (void*)sim);
            }
            else
                fprintf(stderr, "VisIt did not connect\n");
        }
        else if(visitstate == 2)
        {
            /* VisIt wants to tell the engine something. */
            if(VisItProcessEngineCommand() == VISIT_ERROR)
            {
                /* Disconnect on an error or closed connection. */
                VisItDisconnect();
                /* Start running again if VisIt closes. */
                sim->runMode = SIM_RUNNING;
            }
        }
        else if(visitstate == 3)
        {
            /* VisItDetectInput detected console input - do something with it.
             * NOTE: you can't get here unless you pass a file descriptor to
             * VisItDetectInput instead of -1.
             */
            ProcessConsoleCommand(sim);
            fprintf(stderr, "command> ");
            fflush(stderr);
        }
    } while(!sim->done && err == 0);
}
Ejemplo n.º 6
0
Archivo: stubs.c Proyecto: ybouret/iics
void mainloop(simulation_data *sim)
{
    int blocking, visitstate, err = 0;
    //char buffer[100];
    //  double startTime,endTime;
    
    /* If we're not running by default then simulate once there's something
     * once VisIt connects.
     
     if(sim->runMode == SIM_STOPPED)
     simulate_one_timestep(sim);
     */
    VisItUI_valueChanged("MU",     ui_Mu_changed, sim);
    VisItUI_valueChanged("MUTEXT", do_nothing, NULL);
    paramMu=1;
	//sprintf(buffer,"%g",paramMu);
    //VisItUI_setValueS("MUTEXT",buffer,0);
    
    
    
    VisItUI_valueChanged("A", ui_A_changed, sim);
    VisItUI_valueChanged("ATEXT", ui_A_changed, sim);
    
    VisItUI_clicked("RUN",  ui_run_clicked, sim);
    VisItUI_clicked("HALT", ui_halt_clicked, sim);
    VisItUI_clicked("RAZ" , ui_raz_clicked, sim);
    
    if (sim->par_rank == 0)
    {
        fprintf(stderr, "command> ");
        fflush(stderr);
    }
    
    do
    {
        blocking = (sim->runMode == SIM_RUNNING) ? 0 : 1;
        /* Get input from VisIt or timeout so the simulation can run. */
        if(sim->par_rank == 0)
        {
            visitstate = VisItDetectInput(blocking, fileno(stdin));
        }
        
        
        MPI_Bcast(&visitstate, 1, MPI_INT, 0, MPI_COMM_WORLD);
        
        switch(visitstate)
        {
            case 0:
                /* There was no input from VisIt, return control to sim. */
                simulate_one_timestep(sim);
                break;
            case 1:
                /* VisIt is trying to connect to sim. */
                if(VisItAttemptToCompleteConnection() == VISIT_OKAY)
                {
                    fprintf(stderr, "VisIt connected\n");
                    VisItSetCommandCallback(ControlCommandCallback, (void*)sim);
                    VisItSetSlaveProcessCallback(SlaveProcessCallback);
                    
                    VisItSetGetMetaData(SimGetMetaData, (void*)sim);
                    VisItSetGetMesh(SimGetMesh, (void*)sim);
                    //VisItSetGetCurve(SimGetCurve, (void*)sim);
                    VisItSetGetVariable(SimGetVariable, (void*)sim);
                    VisItSetGetDomainList(SimGetDomainList, (void*)sim);
                    sim->visitIsConnected=1;
                    
                }
                else
                {
                    /* Print the error message */
                    char *errString = VisItGetLastError();
                    fprintf(stderr, "VisIt did not connect: %s\n", errString);
                    free(errString);
                }
                break;
            case 2:
                /* VisIt wants to tell the engine something. */
                if(!ProcessVisItCommand(sim))
                {
                    /* Disconnect on an error or closed connection. */
                    VisItDisconnect();
                    sim->visitIsConnected=0;
                    
                    /* Start running again if VisIt closes. */
                    /*sim->runMode = SIM_RUNNING;*/
                }
                break;
            case 3:
                /* VisItDetectInput detected console input - do something with it.
                 * NOTE: you can't get here unless you pass a file descriptor to
                 * VisItDetectInput instead of -1.
                 */
                ProcessConsoleCommand(sim);
                if (sim->par_rank == 0)
                {
                    fprintf(stderr, "command> ");
                    fflush(stderr);
                }
                break;
            default:
                fprintf(stderr, "Can't recover from error %d!\n", visitstate);
                err = 1;
                break;
        }
    } while(!sim->done && err == 0);
}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
    int i,nx = 50, ny = 50,nz = 50, batch = 0, echo = 0;
    char *env = NULL;
    simulation_data sim;

#ifdef PARALLEL
    /* Initialize MPI */
    MPI_Init(&argc, &argv);
#endif

    /* Check for command line arguments. */
    for(i = 1; i < argc; ++i)
    {
        if((i+1) < argc)
        {
            if(strcmp(argv[i], "-nx") == 0)
            {
                sscanf(argv[i+1], "%d", &nx);
                i++;
            }
            else if(strcmp(argv[i], "-ny") == 0)
            {
                sscanf(argv[i+1], "%d", &ny);
                i++;
            }
            else if(strcmp(argv[i], "-nz") == 0)
            {
                sscanf(argv[i+1], "%d", &nz);
                i++;
            }
            else if(strcmp(argv[i], "-dir") == 0)
            {
                /* Specify the path to VisIt installation. */
                VisItSetDirectory(argv[i+1]);
                i++;
            }
        }
        else if(strcmp(argv[i], "-batch") == 0)
        {
            batch = 1;
        }
        else if(strcmp(argv[i], "-echo") == 0)
        {
            echo = 1;
        }
    }

    /* Initialize environment variables. */
    SimulationArguments(argc, argv);

    simulation_data_ctor(&sim, nx, ny, nz);
    sim.echo = echo;

#ifdef PARALLEL
    /* Create a new communicator. */
    if (MPI_Comm_dup(MPI_COMM_WORLD, &sim.par_comm) != MPI_SUCCESS)
        sim.par_comm = MPI_COMM_WORLD;
    MPI_Comm_rank (sim.par_comm, &sim.par_rank);
    MPI_Comm_size (sim.par_comm, &sim.par_size);

    /* Install callback functions for global communication. */
    VisItSetBroadcastIntFunction2(SimBroadcastInt, (void*)&sim);
    VisItSetBroadcastStringFunction2(SimBroadcastString, (void*)&sim);

    /* Tell libsim whether the simulation is parallel. */
    VisItSetParallel(sim.par_size > 1);
    VisItSetParallelRank(sim.par_rank);

    /* Tell libsim which communicator to use. You must pass the address of
     * an MPI_Comm object.
     */
    VisItSetMPICommunicator((void *)&sim.par_comm);
#endif

    /* Only read the environment on rank 0. This could happen before MPI_Init if
     * we are using an MPI that does not like to let us spawn processes but we
     * would not know our processor rank.
     */
    if(sim.par_rank == 0)
        env = VisItGetEnvironment();

    /* Pass the environment to all other processors collectively. */
    VisItSetupEnvironment2(env);
    if(env != NULL)
        free(env);

    /* Call the main loop. */
    if(batch)
        mainloop_batch(&sim);
    else
    {
        if(sim.par_rank == 0)
        {
            /* Write out .sim file that VisIt uses to connect. */
            VisItInitializeSocketAndDumpSimFile(
#ifdef PARALLEL
            "zerocopy_par",
#else
            "zerocopy",
#endif
            "Demonstrates VariableData setArrayData functions for zero copy",
            "/path/to/where/sim/was/started",
            NULL, NULL, SimulationFilename());
        }

        mainloop_interactive(&sim);
    }

    if(VisItIsConnected())
        VisItDisconnect();

    simulation_data_dtor(&sim);
#ifdef PARALLEL
    MPI_Finalize();
#endif

    return 0;
}
Ejemplo n.º 8
0
void mainloop(simulation_data *sim)
{
  int blocking, visitstate, err = 0;
  char Filename[256];

#ifdef VISIT_INSITU
  if(sim->runMode == SIM_STOPPED)
    simulate_one_timestep(sim);
  do
    {
    blocking = (sim->runMode == SIM_RUNNING) ? 0 : 1;

// Get input from VisIt or timeout so the simulation can run.
    if(sim->par_rank == 0)
      visitstate = VisItDetectInput(blocking, -1);
    MPI_Bcast(&visitstate, 1, MPI_INT, 0, sim->comm_cart);

// Do different things depending on the output from VisItDetectInput
    switch(visitstate)
      {
      case 0:
// There was no input from VisIt, return control to sim
        simulate_one_timestep(sim);
      break;
      case 1:
// VisIt is trying to connect to sim.
        if(VisItAttemptToCompleteConnection() == VISIT_OKAY)
          {
          //fprintf(stderr, "VisIt connected\n");
          VisItSetCommandCallback(ControlCommandCallback, (void*)sim);
          VisItSetSlaveProcessCallback2(SlaveProcessCallback, (void*)sim);

          VisItSetGetMetaData(SimGetMetaData, (void*)sim);
          VisItSetGetMesh(SimGetMesh, (void*)sim);
          VisItSetGetVariable(SimGetVariable, (void*)sim);
          VisItSetGetDomainList(SimGetDomainList, (void*)sim);
          }
        else
          {
          char *err = VisItGetLastError();
          fprintf(stderr, "VisIt did not connect: %s\n", err);
          free(err);
          }
      break;
      case 2:
// VisIt wants to tell the engine something
        if(!ProcessVisItCommand(sim))
          {
// Disconnect on an error or closed connection.
           VisItDisconnect();
// Start running again if VisIt closes.
           sim->runMode = SIM_RUNNING;
          }
      break;
      default:
        fprintf(stderr, "Can't recover from error %d!\n", visitstate);
        err = 1;
      break;
      }
    } while(!sim->done && err == 0);
#else
  do
    {
    simulate_one_timestep(sim);
    char postfix[4];
#ifdef ADIOS
    strcpy(postfix, "bp");
    DumpData(sim, sim->filename, sim->saveCounter++, postfix);
#elif NETCDF4
#ifdef PARIO
    strcpy(postfix, "p.nc");
    DumpData(sim, sim->filename, sim->saveCounter++, postfix);
#else
    strcpy(postfix, "s.nc");
    DumpData(sim, sim->filename, sim->saveCounter++, postfix);
#endif
#elif HDF5
    strcpy(postfix, "h5");
    DumpData(sim, sim->filename, sim->saveCounter++, postfix);
#elif BOV
    strcpy(postfix, "bof");
    char name[512];
    char cmd[512];
    int l0 =  strlen(strrchr(sim->filename, '/'));
    int l =  1+strlen(sim->filename) - l0;
    strncpy(name, sim->filename, l);
    sprintf(&name[l], "%05d/", sim->saveCounter);
    sprintf(cmd, "mkdir %s", &name[0]);
    if(!sim->par_rank){
      system(cmd);
    }
    MPI_Barrier(sim->comm_cart);
    strncpy(&name[l+6], &sim->filename[l], l0);
    //fprintf(stderr, "creating a subdirectory %s %d\n",name, l0);
    //fprintf(stderr, "creating a subdirectory %s %d\n",sim->filename, sim->saveCounter);
    DumpData(sim, name, sim->saveCounter++, postfix);
#else
    strcpy(postfix, "bin");
    DumpData(sim, sim->filename, sim->saveCounter++, postfix);
#endif

    //if(sim->par_rank == 0) printf("Saved file %s\n", Filename);

    if(sim->cycle == NUMBER_OF_ITERATIONS)
      {
      sim->done = 1;
      }
    } while(!sim->done && err == 0);
#endif
}