Fatal error in MPI_Init:Other MPI error, error stack

一个MPI程序,出现这样的错误,仔细看看后续的提示行,是否出现如下的错误:gethostbyname failed
出现这种错误的原因是hosts文件中没有列入当前主机的hostname先看看主机的hostname是什么,用uname -a查看,比如我的是Linux scdzj 2.6.32-696.6.3.el6.x86_64 #1 SMP Wed Jul 12 14:17:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux则第二个字段scdzj是hostname打开/etc/hosts文件,在127.0.0.1的后面加上hostname,保存退出。这个问题即可解决。
stackoverflow. com/questions/23112515/mpich2-gethostbyname-failed

pandas的date_range时间偏置

想用pandas.data_range(start=’1970′,end=’2020′,freq=’Y’)来生成一个按年分布的时间序列,但实际结果是生成了这样的:1970-12-31,1971-12-31… …我需要的是每年开始的日期,经查找,发现可用如下办法:pandas.date_range(start=’1970′,end=’2020′,freq=pandas.offsets.YearBegin(1))即可。

===========================
也可以简单写成pandas.date_range(start=’1970′,end=’2020′,freq=’1YS’)

illustrator无法编辑matplotlib保存的矢量图中的文本

stackoverflow.com    /questions/5956182/cannot-edit-text-in-chart-exported-by-matplotlib-and-opened-in-illustrator

是由于默认的fonttype=3引起的,illustrator不能处理这种类型,可改为42(TrueType)就可以了:

>>> import matplotlib as mpl 

>>> mpl.rcParams['pdf.fonttype'] = 42

ICONV字符GB2312转换UTF8

指令:

  #iconv -f GB2312 -t UTF-8 gb1.txt >gb2.txt 

         将gb1里的编码从GB2312转化成UTF-8  并重定向到gb2.txt

  除了iconv命令,我们在linux系统下的man page的第三节还可以看到一组iconv函数。它们分别是

  iconv_t   iconv_open(const char *tocode, const char *fromcode);

  size_t    iconv(iconv_t cd,  char **inbuf,    size_t *inbytesleft,    char **outbuf,    size_t *outbytesleft);

  int        iconv_close(iconv_t cd);

  iconv_open函数用来打开一个编码转换的流,iconv函数的作用是实际进行转换,iconv_close函数的作用就是关闭这个流。实际用法参见下面的例子,下面是一个将UTF-8码转换成GBK码的例子,我们假设已经有了一个uft8编码的输入缓冲区inbuf以及这个缓冲区的长度inlen。

  iconv_t cd = iconv_open( "GBK", "UTF-8");

  char *outbuf = (char *)malloc(inlen * 4 );

  bzero( outbiuf, inlen * 4);

  char *in = inbuf;

  char *out = outbuf;

  size_t outlen = inlen *4;

  iconv(cd, &in, (size_t *)&inlen, &out,&outlen);

  outlen = strlen(outbuf);

  printf("%sn",outbuf);

  free(outbuf);

  iconv_close(cd);

  非常值得注意的地方是:iconv函数会修改参数in和参数out指针所指向的地方,也就是说,在调用iconv函数之前,我们的in和inbuf指针以及out和outbuf指针指向的是同一块内存区域,但是调用之后out指针所指向的地方就不是outbuf了,同理in指针。所以要

  char *in = inbuf;

  char *out = outbuf;

  另存一下,使用或者释放内存的时候也要使用原先的那个指针outbuf和inbuf。

 

例子:

#iconv -f gb2312 -t utf8 buy_msg.htm >buy_msg.html

将buy_msg.htm 内的字符GB2312转换为UTF8