示例#1
0
op_arg * generatePlanInputData ( char name[],
                                 int setId,
                                 int argsNumber,
                                 int args[],
                                 int idxs[],
                                 int maps[],
                                 int accs[],
                                 int indsNumber,
                                 int inds[],
                                 int argsType[]
                               )
{
  (void)name;
  (void)setId;
  (void)indsNumber;

  int i;

  op_dat_core * planDatArgs = calloc ( argsNumber, sizeof ( op_dat_core ) );
  op_map_core * planMaps = calloc ( argsNumber, sizeof ( op_map_core ) );
  int * planDims = calloc ( argsNumber, sizeof ( int ) );
  char ** planTypes = calloc ( argsNumber, sizeof ( char * ) );
  op_access * planAccs = calloc ( argsNumber, sizeof ( op_access ) );
  op_arg * planArguments;

  planArguments = calloc ( argsNumber, sizeof ( op_arg ) );

  /* build planDatArgs variable by accessing OP_dat_list with indexes(=positions) in args */
  for ( i = 0; i < argsNumber; i++ )
  {
    if ( argsType[i] != F_OP_ARG_GBL )
    {
      op_dat_core * tmp = OP_dat_list[args[i]];
      planDatArgs[i] = *tmp;
    }
    //      else
    //  planDatArgs[i] = NULL;
  }

  /* build planMaps variables by accessing OP_map_list with indexes(=positions) in args */
  for ( i = 0; i < argsNumber; i++ )
  {
    op_map_core * tmp;

    if ( inds[i] >= 0 ) /* another magic number !!! */
    {
      tmp = OP_map_list[maps[i]];
      planMaps[i] = *tmp;
    }
    else
    {
      /* build false map with index = -1 ... */
      op_map_core * falseMap = (op_map_core *) calloc ( 1, sizeof ( op_map_core ) ); //OP_ID;
      falseMap->index = -1;
      planMaps[i] = *falseMap;
    }
  }

  /* build dimensions of data using op_dat */
  for ( i = 0; i < argsNumber; i++ )
  {
    if ( argsType[i] != F_OP_ARG_GBL )
      planDims[i] = planDatArgs[i].dim;
    else
      planDims[i] = -1; //difference with C side!
  }

  /* build op_dat data type names (allocate precise space for name and copy it) */
  for ( i = 0; i < argsNumber; i++ )
  {
    if ( argsType[i] != F_OP_ARG_GBL )
    {
      /* obtain reference to next op_dat */
      op_dat_core * tmpDat = OP_dat_list[args[i]];

      /* allocate space and copy strings */
      int typeNameLen = strlen ( tmpDat->type );

      planTypes[i] = (char * ) calloc ( typeNameLen, sizeof ( char ) );
      strncpy ( planTypes[i], tmpDat->type, typeNameLen );
    }
  }

  /* build op_access array needed to build the plan */
  for ( i = 0; i < argsNumber; i++ )
  {
    planAccs[i] = getAccFromIntCode ( accs[i] );
  }

  /* now builds op_arg array */
  for ( i = 0; i < argsNumber; i++ )
  {
    planArguments[i].index = -1; //index is not specified nor used for now..
    if ( argsType[i] != F_OP_ARG_GBL )
      planArguments[i].dat = &(planDatArgs[i]);
    else
      planArguments[i].dat = NULL;

    if ( inds[i] >= 0 ) /* Mapping exists only if not in OP_ID or OP_GBL cases */
      planArguments[i].map = &(planMaps[i]);
    else
      planArguments[i].map = NULL;

    planArguments[i].dim = planDims[i];
    planArguments[i].idx = idxs[i];
    if ( argsType[i] != F_OP_ARG_GBL )
    {
      planArguments[i].size = planDatArgs[i].size;
      planArguments[i].data = planDatArgs[i].data;
      planArguments[i].data_d = planDatArgs[i].data_d;
      planArguments[i].type = planDatArgs[i].type;
    }
    else
    {
      planArguments[i].size = 0;
      planArguments[i].data = NULL;
      planArguments[i].data_d = NULL;
      planArguments[i].type = NULL;
    }

    planArguments[i].acc = planAccs[i];

    switch ( argsType[i] )
    {
      case F_OP_ARG_DAT :
        planArguments[i].argtype = OP_ARG_DAT;
        break;
      case F_OP_ARG_GBL :
        planArguments[i].argtype = OP_ARG_GBL;
        break;
      default :
        printf ( "Error while setting argument type\n" );
        exit ( 0 );
    }
  }

  return planArguments;
}
示例#2
0
//
//	wrapper from Fortran to plan function (see below)
//
op_plan * cplan ( char name[],
									int setId,
									int argsNumber,
									int args[],
									int idxs[],
									int maps[],
									int accs[],
									int indsNumber,
									int inds[]
								)
{
	
	int i, generatedPlanIndex = ERR;
	
	op_plan * generatedPlan = NULL;
	
	op_dat planArgs[argsNumber];
	op_map planMaps[argsNumber];
	int planDims[argsNumber];
	char * planTypes[argsNumber];
	op_access planAccs[argsNumber];
	op_set * iterationSet =  OP_set_list[setId];
	
	if ( iterationSet == NULL ) {
		printf ( "bad set index\n" );
		exit ( -1 );
	}
	
	// build planArgs variable by accessing OP_dat_list with indexes(=positions) in args
	for ( i = 0; i < argsNumber; i++ ) {
		op_dat * tmp = OP_dat_list[args[i]];
		planArgs[i] = *tmp;
	}

	// build planMaps variables by accessing OP_map_list with indexes(=positions) in args
	for ( i = 0; i < argsNumber; i++ ) {
		op_map * tmp;
		int j;
		
		if ( maps[i] != -1 ) { // another magic number !!!			
			int iter;
			tmp = OP_map_list[maps[i]];
			planMaps[i] = *tmp;			
		} else {
			// build false map with index = -1 ...
			planMaps[i] = OP_ID;
		}
	}
	
	// build dimensions of data using op_dat
	for ( i = 0; i < argsNumber; i++ ) {
		planDims[i] = planArgs[i].dim;
	}
	
	// build op_dat data type names (allocate precise space for name and copy it)
	for ( i = 0; i < argsNumber; i++ ) {
		// obtain reference to next op_dat
		op_dat * tmpDat = OP_dat_list[args[i]];
		
		// allocate space and copy strings 
		int typeNameLen =	strlen ( tmpDat->type );
		
		planTypes[i] = (char * ) calloc ( typeNameLen, sizeof ( char ) );
		strncpy ( planTypes[i], tmpDat->type, typeNameLen );
	}
	
	// build op_access array needed to build the plan
	for ( i = 0; i < argsNumber; i++ ){
		planAccs[i] = getAccFromIntCode ( accs[i] );
	}
	
	generatedPlan = plan ( name, *iterationSet, argsNumber, planArgs, idxs, planMaps, planDims, (const char **) planTypes, planAccs, indsNumber, inds);
	
//	printf ( "C Transfer = %f\n", generatedPlan->transfer );
	
	return generatedPlan;
}