void sciddicaTLoadConfig()
{
	//load configuration
	calLoadSubstate2Dr(s3hex, Q.z, DEM_PATH);
	calLoadSubstate2Dr(s3hex, Q.d, REGOLITH_PATH);
	calLoadSubstate2Di(s3hex, Q.s, SOURCE_PATH);
}
Esempio n. 2
0
int main()
{
    time_t start_time, end_time;

    //cadef and rundef
    struct CALModel2D* sciddicaT = calCADef2D (ROWS, COLS, CAL_VON_NEUMANN_NEIGHBORHOOD_2D, CAL_SPACE_TOROIDAL, CAL_OPT_ACTIVE_CELLS);
    struct CALRun2D* sciddicaT_simulation = calRunDef2D(sciddicaT, 1, STEPS, CAL_UPDATE_IMPLICIT);

    //add transition function's elementary processes
    calAddElementaryProcess2D(sciddicaT, sciddicaT_transition_function);
    calAddElementaryProcess2D(sciddicaT, sciddicaT_remove_inactive_cells);

    //add substates
    Q.z = calAddSingleLayerSubstate2Dr(sciddicaT);
    Q.h = calAddSubstate2Dr(sciddicaT);

    //load configuration
    calLoadSubstate2Dr(sciddicaT, Q.z, DEM_PATH);
    calLoadSubstate2Dr(sciddicaT, Q.h, SOURCE_PATH);

    //simulation run
    calRunAddInitFunc2D(sciddicaT_simulation, sciddicaT_simulation_init);
    printf ("Starting simulation...\n");
    start_time = time(NULL);
    calRun2D(sciddicaT_simulation);
    end_time = time(NULL);
    printf ("Simulation terminated.\nElapsed time: %d\n", end_time-start_time);


    //saving configuration
    calSaveSubstate2Dr(sciddicaT, Q.h, OUTPUT_PATH);

    //finalizations
    calRunFinalize2D(sciddicaT_simulation);
    calFinalize2D(sciddicaT);

    return 0;
}
Esempio n. 3
0
void sciddicaTLoadConfig()
{
	//load configuration
	calLoadSubstate2Dr(sciddicaT, Q.z, DEM_PATH);
	calLoadSubstate2Dr(sciddicaT, Q.h, SOURCE_PATH);
}
Esempio n. 4
0
int main(int argc, char** argv)
{
    // read from argv the number of steps
    int steps;
    if (sscanf (argv[2], "%i", &steps)!=1 && steps >=0) {
        printf ("number of steps is not an integer");
        exit(-1);
    }
		// read from argv the number of loops
    if (sscanf (argv[3], "%i", &numberOfLoops)!=1 && numberOfLoops >=0) {
        printf ("number of loops is not an integer");
        exit(-1);
    }

    int platform;
    if (sscanf (argv[4], "%i", &platform)!=1 && platform >=0) {
        printf ("platform number is not an integer");
        exit(-1);
    }
    int deviceNumber;
    if (sscanf (argv[5], "%i", &deviceNumber)!=1 && deviceNumber >=0) {
        printf ("device number is not an integer");
        exit(-1);
    }


	struct CALCLDeviceManager * calcl_device_manager;
	CALCLcontext context;
	CALCLdevice device;
	CALCLprogram program;
	struct CALCLModel2D * device_CA;
#ifdef ACTIVE_CELLS
	char * kernelSrc = KERNEL_SRC_AC;
	char * kernelInc = KERNEL_INC_AC;
#else
	char * kernelSrc = KERNEL_SRC;
	char * kernelInc = KERNEL_INC;
#endif
	CALCLkernel kernel_elem_proc_flow_computation;
	CALCLkernel kernel_elem_proc_width_update;
	CALCLkernel kernel_elem_proc_rm_act_cells;
	CALCLkernel kernel_steering;
	CALCLmem * buffersKernelFlowComp;
	CALCLmem bufferEpsilonParameter;
	CALCLmem bufferRParameter;

	calcl_device_manager = calclCreateManager();
	//calclGetPlatformAndDeviceFromStdIn(calcl_device_manager, &device);
    device = calclGetDevice(calcl_device_manager, platform, deviceNumber);
	context = calclCreateContext(&device);
	program = calclLoadProgram2D(context, device, kernelSrc, kernelInc);


	// Define of the host-side CA objects
#ifdef ACTIVE_CELLS
    host_CA = calCADef2D(ROWS, COLS, CAL_VON_NEUMANN_NEIGHBORHOOD_2D, CAL_SPACE_TOROIDAL, CAL_OPT_ACTIVE_CELLS_NAIVE);
#else
	host_CA = calCADef2D(ROWS, COLS, CAL_VON_NEUMANN_NEIGHBORHOOD_2D, CAL_SPACE_TOROIDAL, CAL_NO_OPT);
#endif

	// Add substates
	Q.f[0] = calAddSubstate2Dr(host_CA);
	Q.f[1] = calAddSubstate2Dr(host_CA);
	Q.f[2] = calAddSubstate2Dr(host_CA);
	Q.f[3] = calAddSubstate2Dr(host_CA);
	Q.z = calAddSubstate2Dr(host_CA);
	Q.h = calAddSubstate2Dr(host_CA);

	// Load configuration
	calLoadSubstate2Dr(host_CA, Q.z, DEM_PATH);
	calLoadSubstate2Dr(host_CA, Q.h, SOURCE_PATH);

	// Initialization
	sciddicaTSimulationInit(host_CA);
	calUpdate2D(host_CA);

	// Define a device-side CA
	device_CA = calclCADef2D(host_CA, context, program, device);

	//Set the workgroup dimensions
	calclSetWorkGroupDimensions(device_CA, 8, 8);

	// Extract kernels from program
	kernel_elem_proc_flow_computation = calclGetKernelFromProgram(&program, KERNEL_ELEM_PROC_FLOW_COMPUTATION);
	kernel_elem_proc_width_update = calclGetKernelFromProgram(&program, KERNEL_ELEM_PROC_WIDTH_UPDATE);
#ifdef ACTIVE_CELLS
	kernel_elem_proc_rm_act_cells = calclGetKernelFromProgram(&program, KERNEL_ELEM_PROC_RM_ACT_CELLS);
#endif
	kernel_steering = calclGetKernelFromProgram(&program, KERNEL_STEERING);

	bufferEpsilonParameter = calclCreateBuffer(context, &P.epsilon, sizeof(CALParameterr));
	bufferRParameter = calclCreateBuffer(context, &P.r, sizeof(CALParameterr));

	calclSetKernelArg2D(&kernel_elem_proc_flow_computation, 0, sizeof(CALCLmem), &bufferEpsilonParameter);
	calclSetKernelArg2D(&kernel_elem_proc_flow_computation, 1, sizeof(CALCLmem), &bufferRParameter);
	calclSetKernelArg2D(&kernel_elem_proc_flow_computation, 2, sizeof(int), &numberOfLoops);

	calclSetKernelArg2D(&kernel_elem_proc_width_update, 0, sizeof(int), &numberOfLoops);

  // Register transition function's elementary processes kernels
	calclAddElementaryProcess2D(device_CA, &kernel_elem_proc_flow_computation);
	calclAddElementaryProcess2D(device_CA, &kernel_elem_proc_width_update);
	calclAddSteeringFunc2D(device_CA, &kernel_steering);
#ifdef ACTIVE_CELLS
	calclSetKernelArg2D(&kernel_elem_proc_rm_act_cells, 0, sizeof(CALCLmem), &bufferEpsilonParameter);
	calclAddElementaryProcess2D(device_CA, &kernel_elem_proc_rm_act_cells);
#endif

	// Simulation run
    struct OpenCALTime * opencalTime= (struct OpenCALTime *)malloc(sizeof(struct OpenCALTime));
    startTime(opencalTime);

    calclRun2D(device_CA, 1, steps);

    endTime(opencalTime);

	// Saving results
	calSaveSubstate2Dr(host_CA, Q.h,"./testsout/other/1.txt");

	// Finalizations
	calclFinalizeManager(calcl_device_manager);
	calclFinalize2D(device_CA);
	calFinalize2D(host_CA);

	return 0;
}