コード例 #1
0
static void dump_em_all(int nlist,t_dlist dlist[],int nf,real time[],
			real **dih,int maxchi,
			gmx_bool bPhi,gmx_bool bPsi,gmx_bool bChi,gmx_bool bOmega, gmx_bool bRAD,
                        const output_env_t oenv)
{
  char name[256], titlestr[256], ystr[256]; 
  real *data ; 
  int  i,j,Xi;
  
  snew(data,nf); 
  if (bRAD) 
    strcpy(ystr,"Angle (rad)"); 
  else
    strcpy(ystr,"Angle (degrees)"); 
    
  /* Dump em all */
  j = 0;
  for(i=0; (i<nlist); i++) {
      /* grs debug  printf("OK i %d j %d\n", i, j) ; */
    if (bPhi) {
      copy_dih_data(dih[j],data,nf,bRAD); 
      print_one(oenv,"phi",dlist[i].name,"\\xf\\f{}",ystr, nf,time,data); 
    }
    j++;
  }
  for(i=0; (i<nlist); i++) {
    if (bPsi) {
      copy_dih_data(dih[j],data,nf,bRAD); 
      print_one(oenv,"psi",dlist[i].name,"\\xy\\f{}",ystr, nf,time,data);
    }
    j++;
  }  
  for(i=0; (i<nlist); i++)
    if (has_dihedral(edOmega,&(dlist[i]))) {
      if (bOmega){
	copy_dih_data(dih[j],data,nf,bRAD); 
	print_one(oenv,"omega",dlist[i].name,"\\xw\\f{}",ystr,nf,time,data);
      }
      j++;
    }
  
  for(Xi=0; (Xi<maxchi); Xi++)
    for(i=0; (i<nlist); i++)
      if (dlist[i].atm.Cn[Xi+3] != -1) {
	if (bChi) {
	  sprintf(name,"chi%d",Xi+1);
	  sprintf(titlestr,"\\xc\\f{}\\s%d\\N",Xi+1);
	  copy_dih_data(dih[j],data,nf,bRAD); 
	  print_one(oenv,name,dlist[i].name,titlestr,ystr, nf,time,data);
	}
	j++; 
      }
  fprintf(stderr,"\n");
}
コード例 #2
0
ファイル: options.cpp プロジェクト: casadi/casadi
  void Options::check(const Dict& opts) const {
    // Make sure all options exist and have the correct type
    for (auto&& op : opts) {
      const Options::Entry* entry = find(op.first);

      // Informative error message if option does not exist
      if (entry==nullptr) {
        stringstream ss;
        ss << "Unknown option: " << op.first << endl;
        ss << endl;
        ss << "Did you mean one of the following?" << endl;
        for (auto&& s : suggestions(op.first)) {
          print_one(s, ss);
        }
        ss << "Use print_options() to get a full list of options." << endl;
        casadi_error(ss.str());
      }

      // Check type
      casadi_assert(op.second.can_cast_to(entry->type),
                            "Illegal type for " + op.first + ": " +
                            op.second.get_description() +
                            " cannot be cast to " +
                            GenericType::get_type_description(entry->type) + ".");

    }
  }
コード例 #3
0
ファイル: disassembler.cpp プロジェクト: evanphx/marius
void Disassembler::print(int indent) {
    Instruction* seq = code_->code();

    int le = 0;

    for(int ip = 0; ip < code_->size();) {
        if(le >= 0 && code_->lines()->at(le) == ip) {
            for(int j = 0; j < indent; j++) printf(" ");
            printf("       LINE %d\n", code_->lines()->at(le+1));
            le += 2;

            if(le >= code_->lines()->size()) le = -1;
        }

        for(int j = 0; j < indent; j++) printf(" ");

        printf("[%02d] ", ip);

        ip += print_one(seq + ip);
    }

    indent += 4;

    for(int i = 0; i < code_->codes_size(); i++) {
        printf("\n");
        for(int j = 0; j < indent; j++) printf(" ");
        printf("== CODE[%d] %s ==\n", i, code_->code(i)->name()->c_str());

        Disassembler dis(code_->code(i));
        dis.print(indent);
    }
}
コード例 #4
0
static void do_dihcorr(const char *fn,int nf,int ndih,real **dih,real dt,
		       int nlist,t_dlist dlist[],real time[],int maxchi,
		       gmx_bool bPhi,gmx_bool bPsi,gmx_bool bChi,gmx_bool bOmega,
                       const output_env_t oenv)
{
  char name1[256],name2[256];
  int  i,j,Xi;
  
  do_autocorr(fn,oenv,"Dihedral Autocorrelation Function",
	      nf,ndih,dih,dt,eacCos,FALSE);
  /* Dump em all */
  j=0;
  for(i=0; (i<nlist); i++) {
    if (bPhi)
      print_one(oenv,"corrphi",dlist[i].name,"Phi ACF for", "C(t)", nf/2,time,
                          dih[j]);
    j++;
  }
  for(i=0; (i<nlist); i++) {
    if (bPsi)
      print_one(oenv,"corrpsi",dlist[i].name,"Psi ACF for","C(t)",nf/2,time,
                dih[j]);
    j++;
  }
  for(i=0; (i<nlist); i++) {
    if (has_dihedral(edOmega,&dlist[i])) {
      if (bOmega)
	print_one(oenv,"corromega",dlist[i].name,"Omega ACF for","C(t)",
                  nf/2,time,dih[j]);
      j++;
    }
  }
  for(Xi=0; (Xi<maxchi); Xi++) {
    sprintf(name1, "corrchi%d", Xi+1);
    sprintf(name2, "Chi%d ACF for", Xi+1);
    for(i=0; (i<nlist); i++) {
      if (dlist[i].atm.Cn[Xi+3] != -1) {
	if (bChi)
	  print_one(oenv,name1,dlist[i].name,name2,"C(t)",nf/2,time,dih[j]);
	j++;
      }
    }
  }
  fprintf(stderr,"\n");
}
コード例 #5
0
ファイル: lastlog.c プロジェクト: brauner/shadow
static void print (void)
{
	const struct passwd *pwent;
	if (uflg && has_umin && has_umax && (umin == umax)) {
		print_one (getpwuid ((uid_t)umin));
	} else {
		setpwent ();
		while ( (pwent = getpwent ()) != NULL ) {
			if (   uflg
			    && (   (has_umin && (pwent->pw_uid < (uid_t)umin))
			        || (has_umax && (pwent->pw_uid > (uid_t)umax)))) {
				continue;
			}
			print_one (pwent);
		}
		endpwent ();
	}
}
コード例 #6
0
ファイル: arp.c プロジェクト: Hooman3/minix
static void show_one(char *hostname, int do_num)
{
	int r;
	ipaddr_t ipaddr;
	nwio_arp_t arp;

	ipaddr= nametoipaddr(hostname);

	arp.nwa_ipaddr= ipaddr;
	r= ioctl(ipfd, NWIOARPGIP, &arp);
	if (r == -1 && errno == ENOENT)
	{
		print_one(ipaddr, NULL, do_num);
		exit(1);
	}
	if (r == -1)
		fatal("NWIOARPGIP failed: %s", strerror(errno));
	print_one(ipaddr, &arp, do_num);
}
コード例 #7
0
ファイル: faillog.c プロジェクト: daxxog/shadow-utils-slitaz
static void print (void)
{
	uid_t uid;
	off_t offset;
	struct faillog faillog;

	if (uflg) {
		offset = user * sizeof faillog;
		if (fstat (fileno (fail), &statbuf)) {
			perror (FAILLOG_FILE);
			return;
		}
		if (offset >= statbuf.st_size)
			return;

		fseek (fail, (off_t) user * sizeof faillog, SEEK_SET);
		if (fread ((char *) &faillog, sizeof faillog, 1, fail) ==
		    1)
			print_one (&faillog, user);
		else
			perror (FAILLOG_FILE);
	} else {
		for (uid = 0;
		     fread ((char *) &faillog, sizeof faillog, 1,
			    fail) == 1; uid++) {

			if (aflg == 0 && faillog.fail_cnt == 0)
				continue;

			if (aflg == 0 && tflg &&
			    NOW - faillog.fail_time > seconds)
				continue;

			if (aflg && faillog.fail_time == 0)
				continue;

			print_one (&faillog, uid);
		}
	}
}
コード例 #8
0
ファイル: bin_extra.c プロジェクト: illust/Huffman
void		print_bin_string(t_print *print, char *str)
{
    if (!str)
        return ;
    while (*str)
    {
        if (*str == '1')
            print_one(print);
        else
            print_zero(print);
        str++;
    }
}
コード例 #9
0
ファイル: sysmain.c プロジェクト: veekxt/make_admin_sys
//显示一页,page为页数-
void print_list_one_page(list L,int page)
{
    int i;
    int page_to_num=(page-1)*NPAGE+1;
    for(i=0; i<page_to_num&&L!=NULL; i++)
    {
        L=L->next;
    }
    for(i= page_to_num; i< page_to_num+NPAGE&&L!=NULL; i++)
    {
        print_one(L,1+i-page_to_num);
        L=L->next;
    }
}
コード例 #10
0
ファイル: gen_code.c プロジェクト: jwrona/VYPe
void print_one(int n_param, struct tac * tac, int i_tac, int offset, int * func_params, FILE * f_out) {
	// find the type in tac
	//   go back through tac
	//   if call then ignore func_params[label] pushes before
	//   if push and ignore == 0, we have the type
	int ignore_pushes = 0;
	data_type_t type;
	for (i_tac; ; i_tac--) {
		struct tac_instruction inst = tac->instructions[i_tac];
		if (inst.operator == OPERATOR_CALL) {
			ignore_pushes += func_params[inst.op1.value.num];	
		}
		else if (inst.operator == OPERATOR_PUSH) {
			if (ignore_pushes > 0) {
				ignore_pushes--;
			}
			else {
				type = inst.data_type;
				i_tac--;
				break;
			}
		}
	}

	if (n_param > 0) {
		print_one(n_param - 1, tac, i_tac, offset + 4, func_params, f_out);
	}

	// print the param on SP + offset of type 'type'
	fprintf(f_out, "\tlw $25,%d($sp)\n", offset);
	switch (type) {
        	case DATA_TYPE_INT:
			fprintf(f_out, "\tprint_int $25\n");
			break;
        	case DATA_TYPE_CHAR:
			fprintf(f_out, "\tprint_char $25\n");
			break;
        	case DATA_TYPE_STRING:
			fprintf(f_out, "\tprint_string $25\n");
			break;
		default:
			break;
	}
	
}
コード例 #11
0
ファイル: mount.nilfs2.c プロジェクト: popen2/nilfs2-utils
/*
 * based on similar function in util-linux-2.12r/mount/mount.c
 */
static void
update_mtab_entry(const char *spec, const char *node, const char *type,
		  const char *opts, int freq, int pass, int addnew)
{
	struct my_mntent mnt;

	mnt.mnt_fsname = canonicalize (spec);
	mnt.mnt_dir = canonicalize (node);
	mnt.mnt_type = xstrdup(type);
	mnt.mnt_opts = xstrdup(opts);
	mnt.mnt_freq = freq;
	mnt.mnt_passno = pass;

	/* We get chatty now rather than after the update to mtab since the
	   mount succeeded, even if the write to /etc/mtab should fail.  */
	if (verbose)
		print_one (&mnt);

	if (!addnew)
		update_mtab (mnt.mnt_dir, &mnt);
	else {
		mntFILE *mfp;

		lock_mtab();
		mfp = my_setmntent(MOUNTED, "a+");
		if (mfp == NULL || mfp->mntent_fp == NULL) {
			int errsv = errno;
			error(_("%s: can't open %s, %s"),
			      progname, MOUNTED, strerror(errsv));
		} else {
			if ((my_addmntent (mfp, &mnt)) == 1) {
				int errsv = errno;
				error(_("%s: error writing %s, %s"),
				      progname, MOUNTED, strerror(errsv));
			}
		}
		my_endmntent(mfp);
		unlock_mtab();
	}
	my_free(mnt.mnt_fsname);
	my_free(mnt.mnt_dir);
	my_free(mnt.mnt_type);
	my_free(mnt.mnt_opts);
}
コード例 #12
0
ファイル: mount.ocfs2.c プロジェクト: pepe5/ocfs2-tools
/*
 * Code based on similar function in util-linux-2.12p/mount/mount.c
 *
 */
static void update_mtab_entry(char *spec, char *node, char *type, char *opts,
			      int flags, int freq, int pass)
{
	struct my_mntent mnt;

	mnt.mnt_fsname = canonicalize (spec);
	mnt.mnt_dir = canonicalize (node);
	mnt.mnt_type = type;
	mnt.mnt_opts = opts;
	mnt.mnt_freq = freq;
	mnt.mnt_passno = pass;
      
	/* We get chatty now rather than after the update to mtab since the
	   mount succeeded, even if the write to /etc/mtab should fail.  */
	if (verbose)
		print_one (&mnt);

	if (!nomtab && mtab_is_writable()) {
		if (flags & MS_REMOUNT)
			update_mtab (mnt.mnt_dir, &mnt);
		else {
			mntFILE *mfp;

			lock_mtab();

			mfp = my_setmntent(MOUNTED, "a+");
			if (mfp == NULL || mfp->mntent_fp == NULL) {
				com_err(progname, OCFS2_ET_IO, "%s, %s",
					MOUNTED, strerror(errno));
			} else {
				if ((my_addmntent (mfp, &mnt)) == 1) {
					com_err(progname, OCFS2_ET_IO, "%s, %s",
						MOUNTED, strerror(errno));
				}
			}
			my_endmntent(mfp);
			unlock_mtab();
		}
	}
	my_free(mnt.mnt_fsname);
	my_free(mnt.mnt_dir);
}
コード例 #13
0
ファイル: arp.c プロジェクト: Hooman3/minix
static void show_all(int do_num)
{
	int ind, max, i, r;
	nwio_arp_t *arptab;
	nwio_arp_t arp;

	/* First get all entries */
	max= 10;
	ind= 0;
	arptab= malloc(max * sizeof(*arptab));
	if (arptab == NULL)
	{
		fatal("out of memory, can't get %d bytes",
			max*sizeof(*arptab));
	}
	arp.nwa_entno= 0;
	for (;;)
	{
		if (ind == max)
		{
			max *= 2;
			arptab= realloc(arptab, max * sizeof(*arptab));
			if (!arptab)
			{
				fatal("out of memory, can't get %d bytes",
					max*sizeof(*arptab));
			}
		}
		r= ioctl(ipfd, NWIOARPGNEXT, &arp);
		if (r == -1 && errno == ENOENT)
			break;
		if (r == -1)
			fatal("NWIOARPGNEXT failed: %s", strerror(errno));
		arptab[ind]= arp;
		ind++;
	}

	for (i= 0; i<ind; i++)
		print_one(0, &arptab[i], do_num);
}
コード例 #14
0
ファイル: sysmain.c プロジェクト: veekxt/make_admin_sys
//查找
void serch_list(list L)
{
    int rule,flag,num=0;
    char target[50];
    printf("输入两个数字,第一个选择在哪查找,第二个选择精确还是模糊,两个数字用空格隔开\n1-学号, 2-姓名, 3-数学, 4-语文, 5-英语  \n1-精确,2-模糊\n");
    scanf(" %d %d",&rule,&flag);
    printf("请输入关键字:\n");
    scanf(" %s",target);
    rst_stdin();
    puts("查找结果:\n");
    for(L=L->next; L!=NULL; L=L->next)
    {
        char *tmp;
        switch(rule)
        {
        case 1:
            tmp=L->num;
            break;
        case 2:
            tmp=L->name;
            break;
        case 3:
            tmp=L->Math;
            break;
        case 4:
            tmp=L->Chinese;
            break;
        case 5:
            tmp=L->English;
            break;
        }
        if((flag==1 && strcmp(tmp,target)==0) || (flag==2 && strstr(tmp,target)!=NULL))
        {
            print_one(L,++num);
        }
    }
    printf("\n找到 %d 条,任意键退出",num);
    getch();
}
コード例 #15
0
ファイル: disassembler.cpp プロジェクト: dalizard/marius
  void Disassembler::print(int indent) {
    Instruction* seq = code_->code();

    for(int ip = 0; ip < code_->size();) {
      for(int j = 0; j < indent; j++) printf(" ");

      printf("[%02d] ", ip);

      ip += print_one(seq + ip);
    }

    indent += 4;

    for(int i = 0; i < code_->codes_size(); i++) {
      printf("\n");
      for(int j = 0; j < indent; j++) printf(" ");
      printf("== CODE[%d] ==\n", i);

      Disassembler dis(code_->code(i));
      dis.print(indent);
    }
  }
コード例 #16
0
ファイル: anadih.c プロジェクト: exianshine/gromacs
void get_chi_product_traj (real **dih, int nframes, int nlist,
                           int maxchi, t_dlist dlist[], real time[],
                           int **lookup, int *multiplicity, gmx_bool bRb, gmx_bool bNormalize,
                           real core_frac, gmx_bool bAll, const char *fnall,
                           const output_env_t oenv)
{

    gmx_bool bRotZero, bHaveChi = FALSE;
    int      accum = 0, index, i, j, k, Xi, n, b;
    real    *chi_prtrj;
    int     *chi_prhist;
    int      nbin;
    FILE    *fp, *fpall;
    char     hisfile[256], histitle[256], *namept;

    int      (*calc_bin)(real, int, real);

    /* Analysis of dihedral transitions */
    fprintf(stderr, "Now calculating Chi product trajectories...\n");

    if (bRb)
    {
        calc_bin = calc_RBbin;
    }
    else
    {
        calc_bin = calc_Nbin;
    }

    snew(chi_prtrj, nframes);

    /* file for info on all residues */
    if (bNormalize)
    {
        fpall = xvgropen(fnall, "Cumulative Rotamers", "Residue", "Probability", oenv);
    }
    else
    {
        fpall = xvgropen(fnall, "Cumulative Rotamers", "Residue", "# Counts", oenv);
    }

    for (i = 0; (i < nlist); i++)
    {

        /* get nbin, the nr. of cumulative rotamers that need to be considered */
        nbin = 1;
        for (Xi = 0; Xi < maxchi; Xi++)
        {
            index = lookup[i][Xi]; /* chi_(Xi+1) of res i (-1 if off end) */
            if (index >= 0)
            {
                n    = multiplicity[index];
                nbin = n*nbin;
            }
        }
        nbin += 1; /* for the "zero rotamer", outside the core region */

        for (j = 0; (j < nframes); j++)
        {

            bRotZero = FALSE;
            bHaveChi = TRUE;
            index    = lookup[i][0]; /* index into dih of chi1 of res i */
            if (index == -1)
            {
                b        = 0;
                bRotZero = TRUE;
                bHaveChi = FALSE;
            }
            else
            {
                b     = calc_bin(dih[index][j], multiplicity[index], core_frac);
                accum = b - 1;
                if (b == 0)
                {
                    bRotZero = TRUE;
                }
                for (Xi = 1; Xi < maxchi; Xi++)
                {
                    index = lookup[i][Xi]; /* chi_(Xi+1) of res i (-1 if off end) */
                    if (index >= 0)
                    {
                        n     = multiplicity[index];
                        b     = calc_bin(dih[index][j], n, core_frac);
                        accum = n * accum + b - 1;
                        if (b == 0)
                        {
                            bRotZero = TRUE;
                        }
                    }
                }
                accum++;
            }
            if (bRotZero)
            {
                chi_prtrj[j] = 0.0;
            }
            else
            {
                chi_prtrj[j] = accum;
                if (accum+1 > nbin)
                {
                    nbin = accum+1;
                }
            }
        }
        if (bHaveChi)
        {

            if (bAll)
            {
                /* print cuml rotamer vs time */
                print_one(oenv, "chiproduct", dlist[i].name, "chi product for",
                          "cumulative rotamer", nframes, time, chi_prtrj);
            }

            /* make a histogram pf culm. rotamer occupancy too */
            snew(chi_prhist, nbin);
            make_histo(NULL, nframes, chi_prtrj, nbin, chi_prhist, 0, nbin);
            if (bAll)
            {
                sprintf(hisfile, "histo-chiprod%s.xvg", dlist[i].name);
                sprintf(histitle, "cumulative rotamer distribution for %s", dlist[i].name);
                fprintf(stderr, "  and %s  ", hisfile);
                fp = xvgropen(hisfile, histitle, "number", "", oenv);
                fprintf(fp, "@ xaxis tick on\n");
                fprintf(fp, "@ xaxis tick major 1\n");
                fprintf(fp, "@ type xy\n");
                for (k = 0; (k < nbin); k++)
                {
                    if (bNormalize)
                    {
                        fprintf(fp, "%5d  %10g\n", k, (1.0*chi_prhist[k])/nframes);
                    }
                    else
                    {
                        fprintf(fp, "%5d  %10d\n", k, chi_prhist[k]);
                    }
                }
                fprintf(fp, "&\n");
                ffclose(fp);
            }

            /* and finally print out occupancies to a single file */
            /* get the gmx from-1 res nr by setting a ptr to the number part
             * of dlist[i].name - potential bug for 4-letter res names... */
            namept = dlist[i].name + 3;
            fprintf(fpall, "%5s ", namept);
            for (k = 0; (k < nbin); k++)
            {
                if (bNormalize)
                {
                    fprintf(fpall, "  %10g", (1.0*chi_prhist[k])/nframes);
                }
                else
                {
                    fprintf(fpall, "  %10d", chi_prhist[k]);
                }
            }
            fprintf(fpall, "\n");

            sfree(chi_prhist);
            /* histogram done */
        }
    }

    sfree(chi_prtrj);
    ffclose(fpall);
    fprintf(stderr, "\n");

}
コード例 #17
0
ファイル: kass.c プロジェクト: OpenCMISS-Dependencies/pastix
void kass(int            levelk,
          int            rat,
          SymbolMatrix * symbptr,
          PASTIX_INT            baseval,
          PASTIX_INT            vertnbr,
          PASTIX_INT            edgenbr,
          PASTIX_INT          * verttab,
          PASTIX_INT          * edgetab,
          Order        * orderptr,
          MPI_Comm       pastix_comm)
{
  PASTIX_INT snodenbr;
  PASTIX_INT *snodetab   = NULL;
  PASTIX_INT *treetab    = NULL;
  PASTIX_INT *ia         = NULL;
  PASTIX_INT *ja         = NULL;
  PASTIX_INT i, j, n;
  PASTIX_INT ind;
  csptr mat;
  PASTIX_INT *tmpj       = NULL;
  PASTIX_INT *perm       = NULL;
  PASTIX_INT *iperm      = NULL;
  PASTIX_INT newcblknbr;
  PASTIX_INT *newrangtab = NULL;
  Dof dofstr;
  Clock timer1;
  double nnzS;
  int procnum;
  (void)edgenbr;

  MPI_Comm_rank(pastix_comm,&procnum);

#ifdef DEBUG_KASS
  print_one("--- kass begin ---\n");
#endif
/*   graphData (graphptr,  */
/*           (SCOTCH_Num * )&baseval,  */
/*           (SCOTCH_Num * )&vertnbr,  */
/*           (SCOTCH_Num **)&verttab,  */
/*           NULL, NULL, NULL,  */
/*           (SCOTCH_Num * )&edgenbr,  */
/*           (SCOTCH_Num **)&edgetab,  */
/*           NULL); */

  n = vertnbr;
  ia = verttab;
  ja = edgetab;
  perm = orderptr->permtab;
  iperm = orderptr->peritab;

  /*** Convert Fortran to C numbering ***/
  if(baseval == 1)
    {
      for(i=0;i<=n;i++)
          ia[i]--;
      for(i=0;i<n;i++)
        for(j=ia[i];j<ia[i+1];j++)
          ja[j]--;
      for(i=0;i<n;i++)
        orderptr->permtab[i]--;
      for(i=0;i<n;i++)
        orderptr->peritab[i]--;
    }

  MALLOC_INTERN(treetab, n, PASTIX_INT);
#ifndef SCOTCH_SNODE
  /*if(rat != -1 )*/
    {
      /***** FIND THE SUPERNODE PARTITION FROM SCRATCH ********/

      /*** Find the supernodes of the direct factorization  ***/
      MALLOC_INTERN(snodetab, n+1, PASTIX_INT);


      clockInit(&timer1);
      clockStart(&timer1);
      find_supernodes(n, ia, ja, perm, iperm, &snodenbr, snodetab, treetab);
      clockStop(&timer1);
      print_one("Time to find the supernode (direct) %.3g s \n", clockVal(&timer1));

      /*memfree(treetab);*/
      print_one("Number of supernode for direct factorization %ld \n", (long)snodenbr);
    }
#else
  /*else*/
    {
      /***** USE THE SUPERNODE PARTITION OF SCOTCH  ********/
      snodenbr = orderptr->cblknbr;
      MALLOC_INTERN(snodetab, n+1, PASTIX_INT);
      memCpy(snodetab, orderptr->rangtab, sizeof(PASTIX_INT)*(snodenbr+1));
      print_one("Number of column block found in scotch (direct) %ld \n", (long)snodenbr);

    }
#endif

  /****************************************/
  /*  Convert the graph                   */
  /****************************************/
    MALLOC_INTERN(mat, 1, struct SparRow);
  initCS(mat, n);
  MALLOC_INTERN(tmpj, n, PASTIX_INT);
  /**** Convert and permute the matrix in sparrow form  ****/
  /**** The diagonal is not present in the CSR matrix, we have to put it in the matrix ***/
  bzero(tmpj, sizeof(PASTIX_INT)*n);
  for(i=0;i<n;i++)
    {
      /*** THE GRAPH DOES NOT CONTAIN THE DIAGONAL WE ADD IT ***/
      tmpj[0] = i;
      ind = 1;
      for(j=ia[i];j<ia[i+1];j++)
        tmpj[ind++] = ja[j];

      mat->nnzrow[i] = ind;
      MALLOC_INTERN(mat->ja[i], ind, PASTIX_INT);
      memCpy(mat->ja[i], tmpj, sizeof(PASTIX_INT)*ind);
      mat->ma[i] = NULL;
    }
  CS_Perm(mat, perm);
  /*** Reorder the matrix ***/
  sort_row(mat);
  memFree(tmpj);


  /***** COMPUTE THE SYMBOL MATRIX OF ILU(K) WITH AMALGAMATION *****/
  kass_symbol(mat, levelk, (double)(rat)/100.0, perm,
              iperm, snodenbr, snodetab, treetab, &newcblknbr, &newrangtab,
              symbptr, pastix_comm);


  cleanCS(mat);
  memFree(mat);
  memFree(treetab);

  dofInit(&dofstr);
  dofConstant(&dofstr, 0, symbptr->nodenbr, 1);
  nnzS =  recursive_sum(0, symbptr->cblknbr-1, nnz, symbptr, &dofstr);
  print_one("Number of non zero in the non patched symbol matrix = %g, fillrate1 %.3g \n",
            nnzS+n, (nnzS+n)/(ia[n]/2.0 +n));
  dofExit(&dofstr);


  if(symbolCheck(symbptr) != 0)
    {
      errorPrint("SymbolCheck after kass_symbol.");
      ASSERT(0, MOD_KASS);
    }



  if(levelk != -1)
    {
      /********************************************************/
      /** ADD BLOCKS IN ORDER TO GET A REAL ELIMINATION TREE **/
      /********************************************************/
      Patch_SymbolMatrix(symbptr);
    }



  dofInit(&dofstr);
  dofConstant(&dofstr, 0, symbptr->nodenbr, 1);
  nnzS =  recursive_sum(0, symbptr->cblknbr-1, nnz, symbptr, &dofstr);

  dofExit(&dofstr);
  print_one("Number of block in final symbol matrix = %ld \n", (long)symbptr->bloknbr);
  print_one("Number of non zero in final symbol matrix = %g, fillrate2 %.3g \n",  nnzS+n, (nnzS+n)/(ia[n]/2.0 +n));
  if(symbolCheck(symbptr) != 0)
    {
      errorPrint("SymbolCheck after Patch_SymbolMatrix.");
      ASSERT(0, MOD_KASS);
    }
#ifdef DEBUG_KASS
  print_one("--- kass end ---\n");
#endif
  memFree(snodetab);
  orderptr->cblknbr = newcblknbr;
  memFree(orderptr->rangtab);
  orderptr->rangtab = newrangtab;

}
コード例 #18
0
ファイル: kass.c プロジェクト: OpenCMISS-Dependencies/pastix
void  Build_SymbolMatrix(csptr P, PASTIX_INT cblknbr, PASTIX_INT *rangtab, SymbolMatrix *symbmtx)
{
  PASTIX_INT i, j, k, l;
  PASTIX_INT cblknum;
  PASTIX_INT ind;
  PASTIX_INT    *tmpj      = NULL;
  double *tmpa      = NULL;
  PASTIX_INT    *node2cblk = NULL;
  PASTIX_INT    *ja        = NULL;
  PASTIX_INT n;

  n = rangtab[cblknbr];

  /**** First we transform the P matrix to find the block ****/
  MALLOC_INTERN(tmpj, n, PASTIX_INT);
  MALLOC_INTERN(tmpa, n, double);
  MALLOC_INTERN(node2cblk, n, PASTIX_INT);


  for(k=0;k<cblknbr;k++)
    for(i=rangtab[k];i<rangtab[k+1];i++)
      node2cblk[i] = k;

  for(k=0;k<cblknbr;k++)
    {
      /*i = rangtab[k];*/ /*OLD VERSION QUAND P pas recompacte */
      i = k;
#ifdef DEBUG_KASS
      ASSERT(P->nnzrow[i] >= (rangtab[k+1]-rangtab[k]), MOD_KASS);

      for(l=0;l<rangtab[k+1]-rangtab[k];l++)
        {
          ASSERT(P->ja[i][l] == rangtab[k]+l, MOD_KASS);
          ASSERT(node2cblk[P->ja[i][l]] == i, MOD_KASS);
        }
#endif
      ja = P->ja[i];
      j = 0;
      ind = 0;
      while(j<P->nnzrow[i])
        {
          cblknum = node2cblk[ja[j]];
          l=j+1;
          while(l < P->nnzrow[i] && ja[l] == ja[l-1]+1 && node2cblk[ja[l]] == cblknum)
            l++;

          tmpj[ind] = ja[j];
          tmpa[ind] = (double)(l-j);
          j = l;
          ind++;
        }

      memFree(P->ja[i]);
      P->nnzrow[i] = ind;
      MALLOC_INTERN(P->ja[i], ind, PASTIX_INT);
      MALLOC_INTERN(P->ma[i], ind, double);
      memCpy(P->ja[i], tmpj, sizeof(PASTIX_INT)*ind);
      memCpy(P->ma[i], tmpa, sizeof(double)*ind);

    }


  memFree(tmpj);
  memFree(tmpa);

#ifdef DEBUG_KASS
  for(k=0;k<cblknbr;k++)
    {
      /*i = rangtab[k];*/
      i = k;
      assert(P->nnzrow[i] > 0);

      if(P->ma[i][0] != (double)(rangtab[k+1]-rangtab[k]))
        print_one("Cblk %ld ma %ld rg %ld \n", k, (PASTIX_INT)P->ma[i][0],rangtab[k+1]-rangtab[k]);

      assert(P->ma[i][0] == (double)(rangtab[k+1]-rangtab[k]));
    }
#endif

  /**********************************/
  /*** Compute the symbol matrix ****/
  /**********************************/
  symbmtx->baseval = 0;
  symbmtx->cblknbr = cblknbr;

  ind = 0;
  symbmtx->bloknbr = CSnnz(P);
  symbmtx->nodenbr = rangtab[cblknbr];

  MALLOC_INTERN(symbmtx->cblktab, cblknbr+1,        SymbolCblk);
  MALLOC_INTERN(symbmtx->bloktab, symbmtx->bloknbr, SymbolBlok);

  ind = 0;
  for(k=0;k<cblknbr;k++)
    {
      symbmtx->cblktab[k].fcolnum = rangtab[k];
      symbmtx->cblktab[k].lcolnum = rangtab[k+1]-1;
      symbmtx->cblktab[k].bloknum = ind;
      /*l = rangtab[k];*/ /** OLD VERSION **/
      l = k;
      for(i=0;i<P->nnzrow[l];i++)
        {
          j = P->ja[l][i];
          symbmtx->bloktab[ind].frownum = j;
          symbmtx->bloktab[ind].lrownum = j+(PASTIX_INT)(P->ma[l][i])-1;
          symbmtx->bloktab[ind].cblknum = node2cblk[j];
          symbmtx->bloktab[ind].levfval = 0;
          ind++;
        }
#ifdef DEBUG_KASS
      assert(symbmtx->bloktab[symbmtx->cblktab[k].bloknum].frownum == symbmtx->cblktab[k].fcolnum);
      assert(symbmtx->bloktab[symbmtx->cblktab[k].bloknum].lrownum == symbmtx->cblktab[k].lcolnum);
      assert(symbmtx->bloktab[symbmtx->cblktab[k].bloknum].cblknum == k);
#endif


    }
  /*  virtual cblk to avoid side effect in the loops on cblk bloks */
  symbmtx->cblktab[cblknbr].fcolnum = symbmtx->cblktab[cblknbr-1].lcolnum+1;
  symbmtx->cblktab[cblknbr].lcolnum = symbmtx->cblktab[cblknbr-1].lcolnum+1;
  symbmtx->cblktab[cblknbr].bloknum = ind;

#ifdef DEBUG_KASS
  if(ind != symbmtx->bloknbr)
    fprintf(stderr, "ind %ld bloknbr %ld \n", ind, symbmtx->bloknbr);
  assert(ind == symbmtx->bloknbr);
#endif


  memFree(node2cblk);
}
コード例 #19
0
ファイル: kass.c プロジェクト: OpenCMISS-Dependencies/pastix
void kass_symbol(csptr mat, PASTIX_INT levelk, double rat, PASTIX_INT *perm, PASTIX_INT *iperm, PASTIX_INT snodenbr, PASTIX_INT *snodetab, PASTIX_INT *streetab, PASTIX_INT *cblknbr, PASTIX_INT **rangtab, SymbolMatrix *symbmtx, MPI_Comm pastix_comm)
{
  /**************************************************************************************/
  /* This function computes a symbolic factorization ILU(k) given a CSR matrix and an   */
  /* ordering. Then it computes a block partition of the factor to get BLAS3            */
  /* efficiency                                                                         */
  /* NOTE: the CSC matrix is given symmetrized and without the diagonal                 */
  /**************************************************************************************/

  PASTIX_INT i, j;
  PASTIX_INT nnzL;
  PASTIX_INT *iperm2  = NULL;
  PASTIX_INT *treetab = NULL;
  PASTIX_INT n;
  csptr P;
  Clock timer1;
  int procnum;

  MPI_Comm_rank(pastix_comm,&procnum);

  n = mat->n;
  MALLOC_INTERN(iperm2, n, PASTIX_INT);

  /*compact_graph(mat, NULL, NULL, NULL);*/

  /*** Compute the ILU(k) pattern of the quotient matrix ***/
  MALLOC_INTERN(P, 1, struct SparRow);
  initCS(P, n);
  print_one("Level of fill = %ld\nAmalgamation ratio = %d \n", (long)levelk, (int)(rat*100));
  clockInit(&timer1);
  clockStart(&timer1);

  if(levelk == -1)
    {

      /***** FACTORISATION DIRECT *******/
      /***** (Re)compute also the streetab (usefull when SCOTCH_SNODE
             is active) ***/
      SF_Direct(mat, snodenbr, snodetab, streetab, P);

      clockStop(&timer1);
      print_one("Time to compute scalar symbolic direct factorization  %.3g s \n", clockVal(&timer1));
#ifdef DEBUG_KASS
      print_one("non-zeros in P = %ld \n", (long)CSnnz(P));
#endif
      nnzL = 0;
      for(i=0;i<P->n;i++)
        {
          PASTIX_INT ncol;
          ncol = snodetab[i+1]-snodetab[i];
          nnzL += (ncol*(ncol+1))/2;
#ifdef DEBUG_KASS
          ASSERT(P->nnzrow[i] >= ncol, MOD_KASS);
          if(P->nnzrow[i] >= n)
            fprintf(stderr,"P->nnzrow[%ld] = %ld \n", (long)i, (long)P->nnzrow[i]);
          ASSERT(P->nnzrow[i] < n, MOD_KASS);
#endif
          nnzL += (P->nnzrow[i]-ncol)*ncol;
        }
#ifdef DEBUG_KASS
      print_one("NNZL = %ld \n", (long)nnzL);
#endif
    }
  else
    {
      /***** FACTORISATION INCOMPLETE *******/
      nnzL = SF_level(2, mat, levelk, P);

      clockStop(&timer1);
      print_one("Time to compute scalar symbolic factorization of ILU(%ld) %.3g s \n",
              (long)levelk, clockVal(&timer1));

    }
  print_one("Scalar nnza = %ld nnzlk = %ld, fillrate0 = %.3g \n",
            (long)( CSnnz(mat) + n)/2, (long)nnzL, (double)nnzL/(double)( (CSnnz(mat)+n)/2.0 ));



  /** Sort the rows of the symbolic matrix */
  sort_row(P);

  clockInit(&timer1);
  clockStart(&timer1);

  if(levelk != -1)
    {

      /********************************/
      /** Compute the "k-supernodes" **/
      /********************************/

#ifdef KS
      assert(levelk >= 0);
      KSupernodes(P, rat, snodenbr, snodetab, cblknbr, rangtab);
#else

#ifdef SCOTCH_SNODE
      if(rat == -1)
        assert(0); /** do not have treetab with this version of Scotch **/
#endif

      MALLOC_INTERN(treetab, P->n, PASTIX_INT);
      for(j=0;j<snodenbr;j++)
        {
          for(i=snodetab[j];i<snodetab[j+1]-1;i++)
            treetab[i] = i+1;

          /*** Version generale ****/
          if(streetab[j] == -1 || streetab[j] == j)
            treetab[i] = -1;
          else
            treetab[i]=snodetab[streetab[j]];
          /*** Version restricted inside the supernode (like KSupernodes) ***/
          /*treetab[snodetab[j+1]-1] = -1;*/  /** this should give the same results than
                                                  KSupernodes **/
        }

      /** NEW ILUK + DIRECT **/
      amalgamate(rat, P, -1, NULL, treetab, cblknbr, rangtab, iperm2, pastix_comm);

      memFree(treetab);
      for(i=0;i<n;i++)
        iperm2[i] = iperm[iperm2[i]];
      memcpy(iperm, iperm2, sizeof(PASTIX_INT)*n);
      for(i=0;i<n;i++)
        perm[iperm[i]] = i;
#endif
    }
  else{


    /*if(0)*/
      {
        amalgamate(rat, P, snodenbr, snodetab, streetab, cblknbr,
                   rangtab, iperm2, pastix_comm);

        /** iperm2 is the iperm vector of P **/
        for(i=0;i<n;i++)
          iperm2[i] = iperm[iperm2[i]];
        memcpy(iperm, iperm2, sizeof(PASTIX_INT)*n);
        for(i=0;i<n;i++)
          perm[iperm[i]] = i;
      }
      /*else
      {
        fprintf(stderr, "RAT = 0 SKIP amalgamation \n");
        *cblknbr = snodenbr;
        MALLOC_INTERN(*rangtab, snodenbr+1, PASTIX_INT);
        memcpy(*rangtab, snodetab, sizeof(PASTIX_INT)*(snodenbr+1));
        }*/
  }

  clockStop(&timer1);
  print_one("Time to compute the amalgamation of supernodes %.3g s\n", clockVal(&timer1));

  print_one("Number of cblk in the amalgamated symbol matrix = %ld \n", (long)*cblknbr);


  Build_SymbolMatrix(P, *cblknbr, *rangtab, symbmtx);


  print_one("Number of block in the non patched symbol matrix = %ld \n", (long)symbmtx->bloknbr);


  memFree(iperm2);
  cleanCS(P);
  memFree(P);

}
コード例 #20
0
void sopalin_launch_thread(void * sopalin_data_ref,
                           PASTIX_INT procnum, PASTIX_INT procnbr, void *ptr, PASTIX_INT verbose,
                           PASTIX_INT calc_thrdnbr, void * (*calc_routine)(void *), void *calc_data,
                           PASTIX_INT comm_thrdnbr, void * (*comm_routine)(void *), void *comm_data,
                           PASTIX_INT ooc_thrdnbr,  void * (*ooc_routine)(void *),  void *ooc_data){
  sopthread_data_t  d_comm;
  sopthread_data_t  d_ooc;
  sopthread_data_t  d_calc;
  pthread_t         pthread_comm;
  pthread_t         pthread_ooc;
  pthread_attr_t    attr_comm;
  pthread_attr_t    attr_ooc;
  int               ret;
  Sopalin_Data_t   *sopalin_data = sopalin_data_ref;
  (void)procnbr; (void)ptr;

  /* Lancement d'un thread de chargement ooc si il est séparé */
  if (verbose > API_VERBOSE_NO)
    print_one("Launching %d threads"
              " (%d commputation, %d communication, %d out-of-core)",
              (int)(comm_thrdnbr+ooc_thrdnbr),
              0, (int)comm_thrdnbr, (int)ooc_thrdnbr);

  if (ooc_thrdnbr > 0)
    {
      pthread_attr_init(&attr_ooc);
      d_ooc.me   = 2;
      d_ooc.data = ooc_data;

      ret = pthread_create(&pthread_ooc, &attr_ooc, ooc_routine, (void *)&d_ooc);
      if (ret) {errorPrint("thread create."); EXIT(MOD_SOPALIN,THREAD_ERR);}
    }

  /* Lancement d'un thread de comm si il est séparé */
  if (comm_thrdnbr > 0)
    {

      pthread_attr_init(&attr_comm);
      d_comm.me   = 1;
      d_comm.data = comm_data;

      ret = pthread_create(&pthread_comm, &attr_comm, comm_routine, (void *)&d_comm);
      if (ret) {errorPrint("thread create."); EXIT(MOD_SOPALIN,THREAD_ERR);}
    }

  d_calc.me   = 0;
  d_calc.data = calc_data;

  calc_routine(&d_calc);

  /* Récupération du thread de comm */
  if (comm_thrdnbr > 0)
    {
      ret = pthread_join(pthread_comm,(void**)NULL);
      if (ret) {errorPrint("thread join."); EXIT(MOD_SOPALIN,THREAD_ERR);}
    }

  /* Récupération du thread de chargement ooc */
  if (ooc_thrdnbr > 0)
    {
      ret = pthread_join(pthread_ooc,(void**)NULL);
      if (ret) {errorPrint("thread join."); EXIT(MOD_SOPALIN,THREAD_ERR);}
    }
}
コード例 #21
0
void sopalin_launch_thread(void * sopalin_data_ref,
                           PASTIX_INT procnum, PASTIX_INT procnbr, void *ptr, PASTIX_INT verbose,
                           PASTIX_INT calc_thrdnbr, void * (*calc_routine)(void *), void *calc_data,
                           PASTIX_INT comm_thrdnbr, void * (*comm_routine)(void *), void *comm_data,
                           PASTIX_INT ooc_thrdnbr,  void * (*ooc_routine)(void *),  void *ooc_data)
{
  sopthread_data_t *d       = NULL;
  pthread_t        *calltab = NULL;
  PASTIX_INT               i;
  PASTIX_INT               ret;
  PASTIX_INT               thrdnbr;
  PASTIX_INT               thrdnbr_wo_ooc;
  Sopalin_Data_t   *sopalin_data = sopalin_data_ref;
  (void)procnbr; (void)ptr;

  thrdnbr = calc_thrdnbr + comm_thrdnbr + ooc_thrdnbr ;
  thrdnbr_wo_ooc = calc_thrdnbr + comm_thrdnbr;
  if (verbose > API_VERBOSE_NO)
    print_one("Launching %d threads"
              " (%d commputation, %d communication, %d out-of-core)\n",
              (int) thrdnbr, (int)calc_thrdnbr,
              (int)comm_thrdnbr, (int)ooc_thrdnbr);
  MALLOC_INTERN(calltab, thrdnbr, pthread_t);
  MALLOC_INTERN(d,       thrdnbr, sopthread_data_t);

  if (calc_thrdnbr > 1)
    {
      int comm_size;
      CHECK_MPI(MPI_Comm_size(MPI_COMM_WORLD, &comm_size));
      if (comm_size > 1)
        CHECK_THREAD_LEVEL(sopalin_data->sopar->iparm[IPARM_THREAD_COMM_MODE]);
    }
  /* Lancement des threads de calcul */
  for (i=0;i<calc_thrdnbr;i++)
    {
      pthread_attr_t attr;
      pthread_attr_init(&attr);

#ifdef MARCEL2
      {
        int cpu = (i+procnum*thrdnbr)%sysconf(_SC_NPROCESSORS_ONLN);
        if (thrdnbr <= sysconf(_SC_NPROCESSORS_ONLN))
          marcel_attr_setvpset(&attr, MARCEL_VPSET_VP(cpu));
      }
#endif

      d[i].me   = i;
      d[i].data = calc_data;
      ret = pthread_create(&calltab[i],&attr,calc_routine,(void *)&d[i]);
      if (ret) {errorPrint("thread create."); EXIT(MOD_SOPALIN,THREAD_ERR);}
    }

  /* Lancement des threads de chargement ooc */
  for (i=thrdnbr_wo_ooc; i<thrdnbr; i++)
    {
      pthread_attr_t attr;
      pthread_attr_init(&attr);
#ifdef MARCEL2
      {
        int cpu = (i+procnum*thrdnbr)%sysconf(_SC_NPROCESSORS_ONLN);

        if (thrdnbr <= sysconf(_SC_NPROCESSORS_ONLN))
          marcel_attr_setvpset(&attr, MARCEL_VPSET_VP(cpu));
      }
#endif

      d[i].me   = i;
      d[i].data = ooc_data;
      ret = pthread_create(&calltab[i],&attr,ooc_routine,(void *)&d[i]);
      if (ret) {errorPrint("thread create."); EXIT(MOD_SOPALIN,THREAD_ERR);}
    }

  /* Lancement des threads de communication */
  if ((comm_thrdnbr > 0)  && (comm_routine != NULL))
    {
      /*       print_one("-- Options Communication --\n"); */
      /*       print_one("    - Type            : %d\n", sopar->type_comm); */
      /*       print_one("    - Nbthread        : %d\n", sopar->nbthrdcomm);   */

      if (comm_thrdnbr > 1)
        {
          for (i=calc_thrdnbr;i<thrdnbr_wo_ooc;i++)
            {
              pthread_attr_t attr;
              pthread_attr_init(&attr);

              d[i].me   = i;
              d[i].data = comm_data;
              ret = pthread_create(&calltab[i], &attr,
                                   comm_routine, (void *)&d[i]);
              if (ret)
                {
                  errorPrint("thread create.");
                  EXIT(MOD_SOPALIN,THREAD_ERR);
                }
            }
        }
      else
        {
          d[calc_thrdnbr].me   = calc_thrdnbr;
          d[calc_thrdnbr].data = comm_data;
          comm_routine((void*)&d[calc_thrdnbr]);
        }
    }

  /* Recuperation de tous les threads lancés */
  for (i=0;i<thrdnbr;i++)
    {
      /* On ne recupere pas le thread qd il a pas été lancé */
      if ((comm_thrdnbr == 1) && (i == calc_thrdnbr)) continue;

      ret = pthread_join(calltab[i],(void**)NULL);
      if (ret) {errorPrint("thread join."); EXIT(MOD_SOPALIN,THREAD_ERR);}
    }

  memFree_null(calltab);
  memFree_null(d);
}
コード例 #22
0
ファイル: gen_code.c プロジェクト: jwrona/VYPe
void generate_built_in(int code, int n_params, struct tac * tac, int i_tac, 
			int * func_params, FILE * f_out, int * reg_mapping, int * var_mapping) {
	struct tac_instruction inst = tac->instructions[i_tac];
	int res_reg;
	switch (code) {
		case 2: // print
			print_one(n_params-1, tac, i_tac-1, 0, func_params, f_out);	
			fprintf(f_out, "\taddi $sp,$sp,%d\n", n_params*4);
			break;
		case 3: // read char
			res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out);
			fprintf(f_out, "\tread_char $%d\n", res_reg);
			break;
		case 4: // read int
			res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out);
			fprintf(f_out, "\tread_int $%d\n", res_reg);
			break;
		case 5: // read string
			res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out);
			fprintf(f_out, "\taddi $%d,$28,0\n", res_reg);
			fprintf(f_out, "\tread_string $%d,$25\n", res_reg);
			fprintf(f_out, "\tadd $28,$28,$25\n");
			fprintf(f_out, "\tsb $0,0($28)\n");
			fprintf(f_out, "\taddi $28,$28,1\n");
			break;
		case 6: // get_at
			res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out);
			fprintf(f_out, "\tlw $%d,0($sp)\n",res_reg);
			fprintf(f_out, "\tlw $25,4($sp)\n");
			fprintf(f_out, "\tadd $25,$25,$%d\n", res_reg);
			fprintf(f_out, "\tlb $%d,0($25)\n", res_reg);
			fprintf(f_out, "\taddi $sp,$sp,8\n");
			break;
		case 7: // set_at
			res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out);
			// store adresses of strings
			fprintf(f_out, "\taddi $%d,$28,0\n", res_reg); 
			fprintf(f_out, "\tlw $28,8($sp)\n"); 
			fprintf(f_out, "\taddi $sp,$sp,-4\n"); 
			fprintf(f_out, "\tsw $%d,0($sp)\n",res_reg); 
			// iterate through strings and do the copy
			fprintf(f_out, "label_copystr%d:\n", generic_label_id); 
			fprintf(f_out, "\tlb $25,0($28)\n"); 
			fprintf(f_out, "\tsb $25,0($%d)\n", res_reg); 
			fprintf(f_out, "\tbeq $25,$0,label_endcopystr%d\n", generic_label_id); 
			fprintf(f_out, "\taddi $28,$28,1\n"); 
			fprintf(f_out, "\taddi $%d,$%d,1\n", res_reg, res_reg); 
			fprintf(f_out, "\tj label_copystr%d\n",generic_label_id); 
			fprintf(f_out, "label_endcopystr%d:\n", generic_label_id); 
			fprintf(f_out, "\taddi $28,$%d,1\n",res_reg); 
			// restore adresses of strings
			fprintf(f_out, "\tlw $%d,0($sp)\n",res_reg); 
			fprintf(f_out, "\taddi $sp,$sp,4\n"); 
			// change the character
			fprintf(f_out, "\tlw $25,4($sp)\n"); 
			fprintf(f_out, "\tadd $%d,$%d,$25\n",res_reg,res_reg); 
			fprintf(f_out, "\tlw $25,0($sp)\n"); 
			fprintf(f_out, "\tsb $25,0($%d)\n", res_reg); 
			fprintf(f_out, "\tlw $25,4($sp)\n"); 
			fprintf(f_out, "\tsub $%d,$%d,$25\n",res_reg,res_reg); 
			fprintf(f_out, "\taddi $sp,$sp,12\n");
			generic_label_id++;
			break;
		case 8: //strcat
			res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out);
			// store adresses of strings
			fprintf(f_out, "\taddi $%d,$28,0\n", res_reg); 
			fprintf(f_out, "\tlw $28,4($sp)\n"); 
			fprintf(f_out, "\taddi $sp,$sp,-4\n"); 
			fprintf(f_out, "\tsw $%d,0($sp)\n",res_reg); 
			// iterate through strings and do the copy
			fprintf(f_out, "label_copystr%d:\n", generic_label_id); 
			fprintf(f_out, "\tlb $25,0($28)\n"); 
			fprintf(f_out, "\tsb $25,0($%d)\n", res_reg); 
			fprintf(f_out, "\tbeq $25,$0,label_endcopystr%d\n", generic_label_id); 
			fprintf(f_out, "\taddi $28,$28,1\n"); 
			fprintf(f_out, "\taddi $%d,$%d,1\n", res_reg, res_reg); 
			fprintf(f_out, "\tj label_copystr%d\n",generic_label_id); 
			fprintf(f_out, "label_endcopystr%d:\n", generic_label_id); 
			generic_label_id++;
			// store adresses of strings
			fprintf(f_out, "\tlw $28,4($sp)\n"); 
			// iterate through strings and do the copy
			fprintf(f_out, "label_copystr%d:\n", generic_label_id); 
			fprintf(f_out, "\tlb $25,0($28)\n"); 
			fprintf(f_out, "\tsb $25,0($%d)\n", res_reg); 
			fprintf(f_out, "\tbeq $25,$0,label_endcopystr%d\n", generic_label_id); 
			fprintf(f_out, "\taddi $28,$28,1\n"); 
			fprintf(f_out, "\taddi $%d,$%d,1\n", res_reg, res_reg); 
			fprintf(f_out, "\tj label_copystr%d\n",generic_label_id); 
			fprintf(f_out, "label_endcopystr%d:\n", generic_label_id); 
			// restore adresses of strings
			fprintf(f_out, "\taddi $28,$%d,1\n",res_reg);
			fprintf(f_out, "\tlw $%d,0($sp)\n",res_reg); 
			fprintf(f_out, "\taddi $sp,$sp,4\n"); 
			fprintf(f_out, "\taddi $sp,$sp,8\n");
			generic_label_id++;
			break;
	}
}
コード例 #23
0
void sopalin_launch_thread(void * sopalin_data_ref,
                           PASTIX_INT procnum, PASTIX_INT procnbr, void *ptr, PASTIX_INT verbose,
                           PASTIX_INT calc_thrdnbr, void * (*calc_routine)(void *), void *calc_data,
                           PASTIX_INT comm_thrdnbr, void * (*comm_routine)(void *), void *comm_data,
                           PASTIX_INT ooc_thrdnbr,  void * (*ooc_routine)(void *),  void *ooc_data){
  char             *name;
  pthread_t        *calltab;
  marcel_bubble_t  *bubbletab;
  BubbleTree       *btree;
  sopthread_data_t *d;
  int               bubbnbr;       /* Nombre de bulles crées */
  int               thrdnbr;       /* Nombre total de thread à lancer */
  int               nodenbr;       /* Nombre de noeud dans l'arbre de bulles */
  int               nbbub2alloc;
  int               ret;
  int               me = 0;
  int               i;
  Sopalin_Data_t   *sopalin_data = sopalin_data_ref;
  (void)procnbr;

  btree        = (BubbleTree *)ptr;
  nodenbr      = btree->nodenbr;
  calc_thrdnbr = btree->leavesnbr;
  bubbnbr      = nodenbr - calc_thrdnbr;
  thrdnbr      = calc_thrdnbr + comm_thrdnbr;
  nbbub2alloc  = MAX(bubbnbr, 1);
  if (verbose > API_VERBOSE_NO)
    print_one("Launching %d threads"
              " (%d commputation, %d communication, %d out-of-core)",
              thrdnbr, calc_thrdnbr, comm_thrdnbr, 0);

  if (comm_thrdnbr > 0)
    nbbub2alloc++;

  MALLOC_INTERN(name,      30,          char);
  MALLOC_INTERN(calltab,   thrdnbr,     pthread_t);
  MALLOC_INTERN(d,         thrdnbr,     sopthread_data_t);
  MALLOC_INTERN(bubbletab, nbbub2alloc, marcel_bubble_t);

#ifdef PROFILE
  marcel_start_playing();
#endif

  /* Lancement dans le cas ou on a un arbre de bulles */
  if (bubbnbr > 0)
    {
      for (i=0; i<bubbnbr; i++)
  marcel_bubble_init(&bubbletab[i]);

      for (i=1; i<bubbnbr; i++)
  marcel_bubble_insertbubble(&bubbletab[ btree->nodetab[i+calc_thrdnbr].fathnum - calc_thrdnbr ],
           &bubbletab[i]);

      /* Creation des threads feuilles */
      for(i=0; i<calc_thrdnbr; i++)
  {
    marcel_attr_t attr;
    sprintf(name, "thread%03d", i);
    marcel_attr_init(&attr);
    marcel_attr_setinitbubble(&attr, &bubbletab[btree->nodetab[i].fathnum - calc_thrdnbr]);
    marcel_attr_setid(&attr,0);
    marcel_attr_setprio(&attr,MA_MAX_RT_PRIO);
    marcel_attr_setname(&attr,name);

    d[i].me   = i;
    d[i].data = calc_data;

    ret = pthread_create(&calltab[i], &attr, calc_routine, (void *)&d[i]);
    if (ret) {errorPrint("thread create."); EXIT(MOD_SOPALIN,THREAD_ERR);}
  }

      /* Creation d'un thread par bulle */
/*       for (i=calc_thrdnbr; i<nodenbr; i++) */
/*  { */
/*    marcel_attr_t attr;  */
/*    int prio = MA_MAX_RT_PRIO+btree->nodetab[i].treelevel; /\* + [btsknbr[i][1]-btsknbr[i][0]+1);*\/ */
/*    sprintf(name, "threadBubble%03d", i); */
/*    if (prio > MA_DEF_PRIO) */
/*      prio = MA_DEF_PRIO; */
/*    if (prio < MA_MAX_RT_PRIO) */
/*      prio = MA_MAX_RT_PRIO; */
/*    marcel_attr_init(&attr); */
/*    marcel_attr_setinitbubble(&attr, &bubbletab[i-thrdnbr]); */
/*    marcel_attr_setid(&attr,1); */
/*    marcel_attr_setprio(&attr,prio); */
/*    marcel_attr_setname(&attr,name); */

/*    d[i].me   = i; */
/*    d[i].data = data; */

/*    ret = pthread_create(&calltab[i], &attr, calc_routine, (void *)&d[i]); */
/*    if (ret) {errorPrint("thread create."); EXIT(MOD_SOPALIN,THREAD_ERR);} */
/*  } */

    }
  /* Cas ou on a qu'un seul thread par noeud */
  else
    {
      marcel_attr_t attr;

      marcel_bubble_init(&bubbletab[0]);

      marcel_attr_init(&attr);
      marcel_attr_setinitbubble(&attr, &bubbletab[0]);
      marcel_attr_setid(&attr,0);
      marcel_attr_setprio(&attr,MA_MAX_RT_PRIO);
      marcel_attr_setname(&attr,"thread");

      d[0].me   = 0;
      d[0].data = calc_data;

      ret = pthread_create(&calltab[0], &attr, calc_routine, (void *)&d[0]);
      if (ret) {errorPrint("thread create."); EXIT(MOD_SOPALIN,THREAD_ERR);}
    }

#ifdef BUBBLE_SCHED_NULL
  print_one("ODONNANCEUR : sans\n");
#elif (defined BUBBLE_SCHED_SPREAD)
  print_one("ODONNANCEUR : bubble_spread\n");
#elif (defined BUBBLE_SCHED_AFFINITY)
  print_one("ODONNANCEUR : bubble_affinity\n");
#elif (defined BUBBLE_SCHED_MEMAWARE)
  print_one("ODONNANCEUR : bubble_memaware\n");
#else
  print_one("ODONNANCEUR : inconnu\n");
#endif

  /* Lancement des threads de communication */
  if ((comm_thrdnbr > 0)  && (comm_routine != NULL))
    {
      if (comm_thrdnbr > 1)
  {
    marcel_bubble_init(&bubbletab[bubbnbr]);
    marcel_bubble_insertbubble(&bubbletab[0], &bubbletab[bubbnbr]);

    for (i=calc_thrdnbr;i<thrdnbr;i++)
      {
        marcel_attr_t attr;
        sprintf(name, "threadComm%03d", i);
        marcel_attr_init(&attr);
        marcel_attr_setinitbubble(&attr, &bubbletab[bubbnbr]);
        marcel_attr_setid(&attr,0);
        marcel_attr_setprio(&attr,MA_MAX_RT_PRIO);
        marcel_attr_setname(&attr,name);

        d[i].me   = i;
        d[i].data = comm_data;
        ret = pthread_create(&calltab[i], &attr, comm_routine, (void *)&d[i]);
        if (ret) {errorPrint("thread create."); EXIT(MOD_SOPALIN,THREAD_ERR);}
      }
  }
      else
  {
    /* Reveil de la bulle principale */
    marcel_wake_up_bubble(&bubbletab[0]);
    d[calc_thrdnbr].me   = calc_thrdnbr;
    d[calc_thrdnbr].data = comm_data;
    thrdnbr--;
    comm_routine((void*)&d[calc_thrdnbr]);
  }
    }
  else
    {
      comm_thrdnbr = 0;
      thrdnbr = calc_thrdnbr;
    }

  /* Reveil de la bulle principale */
  marcel_wake_up_bubble(&bubbletab[0]);

  for (i=0;i<thrdnbr;i++)
    {
      ret = pthread_join(calltab[i],(void**)NULL);
      if (ret)
  {
    errorPrint("thread join bubbnum %d, ret %d", i, ret);
    perror("erreur join thread");
    EXIT(MOD_SOPALIN,THREAD_ERR);
  }
    }

  for(i=0; i<bubbnbr; i++)
    {
      marcel_bubble_destroy(&bubbletab[i]);
    }

  memFree_null(name);
  memFree_null(bubbletab);
  memFree_null(calltab);
  memFree_null(d);
}