{"id":6071,"date":"2024-08-20T16:01:01","date_gmt":"2024-08-20T08:01:01","guid":{"rendered":""},"modified":"2024-08-20T16:01:01","modified_gmt":"2024-08-20T08:01:01","slug":"droptable\u4e0etruncatetable_droptable\u4e0etruncatetable","status":"publish","type":"post","link":"https:\/\/mushiming.com\/6071.html","title":{"rendered":"droptable\u4e0etruncatetable_droptable\u4e0etruncatetable"},"content":{"rendered":"
\n
\n
\n

<\/p>\n

<\/span><\/p>\n

\n
\n

\u7ec8\u4e8e\u5f00\u59cb\u653b\u514b\u5e76\u884c\u8fd9\u4e00\u5757\u4e86\uff0c\u6709\u70b9\u5c0f\u5174\u594b\uff0c\u6765\u770b\u770b\u7f51\u7edc\u4e0aR\u8bed\u8a00\u5e76\u884c\u529e\u6cd5\u6709\u54ea\u4e9b\uff1a<\/span><\/p>\n

     \u8d75\u9e4f\u8001\u5e08\uff08R\u4e0e\u5e76\u884c\u8ba1\u7b97<\/span>\uff09\u505a\u7684\u603b\u7ed3\u5df2\u7ecf\u5f88\u5230\u4f4d\u3002\u73b0\u5728\u5e76\u884c\u53ef\u4ee5\u5206\u4e3a\uff1a<\/span><\/p>\n


<\/span><\/p>\n

    <\/span> \u9690\u5f0f\u5e76\u884c\uff1a<\/span>\u9690\u5f0f\u8ba1\u7b97\u5bf9\u7528\u6237\u9690\u85cf\u4e86\u5927\u90e8\u5206\u7ec6\u8282\uff0c\u7528\u6237\u4e0d\u9700\u8981\u77e5\u9053\u5177\u4f53\u6570\u636e\u5206\u914d\u65b9\u5f0f \uff0c\u7b97\u6cd5\u7684\u5b9e\u73b0\u6216\u8005\u5e95\u5c42\u7684\u786c\u4ef6\u8d44\u6e90\u5206\u914d\u3002\u7cfb\u7edf\u4f1a\u6839\u636e\u5f53\u524d\u7684\u786c\u4ef6\u8d44\u6e90\u6765\u81ea\u52a8\u542f\u52a8\u8ba1\u7b97\u6838\u5fc3\u3002\u663e\u7136\uff0c\u8fd9\u79cd\u6a21\u5f0f\u5bf9\u4e8e\u5927\u591a\u6570\u7528\u6237\u6765\u8bf4\u662f\u6700\u559c\u95fb\u4e50\u89c1\u7684\u3002<\/span><\/span><\/span><\/p>\n

    \u663e\u6027\u5e76\u884c\uff1a<\/span>\u663e\u5f0f\u8ba1\u7b97\u5219\u8981\u6c42\u7528\u6237\u80fd\u591f\u81ea\u5df1\u5904\u7406\u7b97\u4f8b\u4e2d\u6570\u636e\u5212\u5206\uff0c\u4efb\u52a1\u5206\u914d\uff0c\u8ba1\u7b97\u4ee5\u53ca\u6700\u540e\u7684\u7ed3\u679c\u6536\u96c6\u3002\u56e0\u6b64\uff0c\u663e\u5f0f\u8ba1\u7b97\u6a21\u5f0f\u5bf9\u7528\u6237\u7684\u8981\u6c42\u66f4\u9ad8\uff0c\u7528\u6237\u4e0d\u4ec5\u9700\u8981\u7406\u89e3\u81ea\u5df1\u7684\u7b97\u6cd5\uff0c\u8fd8\u9700\u8981\u5bf9\u5e76\u884c\u8ba1\u7b97\u548c\u786c\u4ef6\u6709\u4e00\u5b9a\u7684\u7406\u89e3\u3002\u503c\u5f97\u5e86\u5e78\u7684\u662f\uff0c\u73b0\u6709R\u4e2d\u7684\u5e76\u884c\u8ba1\u7b97\u6846\u67b6\uff0c\u5982parallel (snow,multicores)\uff0cRmpi\u548cforeach\u7b49\u91c7\u7528\u7684\u662f\u6620\u5c04\u5f0f\u5e76\u884c\u6a21\u578b\uff08Mapping\uff09\uff0c\u4f7f\u7528\u65b9\u6cd5\u7b80\u5355\u6e05\u6670\uff0c\u6781\u5927\u5730\u7b80\u5316\u4e86\u7f16\u7a0b\u590d\u6742\u5ea6\u3002R\u7528\u6237\u53ea\u9700\u8981\u5c06\u73b0\u6709\u7a0b\u5e8f\u8f6c\u5316\u4e3a*apply\u6216\u8005for\u7684\u5faa\u73af\u5f62\u5f0f\u4e4b\u540e\uff0c\u901a\u8fc7\u7b80\u5355\u7684API\u66ff\u6362\u6765\u5b9e\u73b0\u5e76\u884c\u8ba1\u7b97\u3002<\/span><\/span><\/p>\n


<\/span><\/p>\n

\u7b80\u5355\u603b\u7ed3\u5c31\u662f\uff1a<\/span><\/p>\n

    \u9690\u5f0f\u5e76\u884c\uff1a<\/span>OpenBLAS\uff0cIntel MKL\uff0cNVIDIA cuBLAS\uff0cH2O(\u53c2\u8003\u6211\u7684\u535a\u5ba2)\u7b49<\/span>
<\/span><\/p>\n

    \u663e\u6027\u5e76\u884c\uff1a<\/span>parallel\uff08\u4e3b\u6253lapply\u5e94\u7528\uff09\u3001foreach\uff08\u4e3b\u6253for\u5faa\u73af\uff09\u3001SupR\u3001\u8fd8\u6709\u5229\u7528GPU\u7684\u529e\u6cd5\uff08gpuR\uff09
<\/span><\/p>\n


<\/span><\/p>\n

      \u540c\u65f6\u5e76\u884c\u65f6\u5bf9\u5185\u5b58\u7684\u6d88\u8017\u6781\u5927\uff0c\u8d85\u7ea7\u5bb9\u6613\u7206\u53d1\u5185\u5b58\u95ee\u9898\uff0c\u800c\u4e14R\u7684\u5185\u5b58\u95ee\u9898\u4e00\u76f4\u90fd\u662fR\u5f88\u96be\u89e3\u51b3\u7684\u95ee\u9898\uff0c\u8fd9\u8fb9\u7b14\u8005\u4e5f\u628a\u770b\u5230\u7684\u4e00\u4e9b\u65b9\u5f0f\u5217\u51fa\u6765\u3002<\/span><\/p>\n

      \u5f53\u7136\u5728\u4f7f\u7528\u4e00\u4e9b\u9ad8\u5927\u4e0a\u7684\u5e76\u884c\u5305\u4ee5\u53ca\u6846\u67b6\u4e4b\u524d\uff0c\u5982\u679c\u4f60\u80fd\u591f\u4ece\u7f16\u7801\u5c0f\u7ec6\u8282\u4f18\u5316\uff0c\u6548\u7387\u4e5f\u80fd\u63d0\u9ad8\u5f88\u591a<\/span><\/span>\uff0c\u8b6c\u5982\uff1a<\/span><\/p>\n<\/p>\n

 <\/span><\/p>\n

\n
\n
\n [html]<\/strong>  view plain
\n  copy<\/span> <\/p>\n
<\/div>\n

<\/span>\n <\/div>\n<\/p><\/div>\n

    \n
  1. \u65b9\u6cd5\uff1a\u901f\u5ea6\uff0c nrow(df)\/<\/span>time_taken<\/span> = <\/span>n<\/span> \u884c\u6bcf\u79d2  <\/span><\/span><\/li>\n
  2. \u539f\u59cb\u65b9\u6cd5\uff1a1X, 856.2255\u884c\u6bcf\u79d2(\u6b63\u5219\u5316\u4e3a1)  <\/span><\/li>\n
  3. \u5411\u91cf\u5316\u65b9\u6cd5\uff1a738X, \u884c\u6bcf\u79d2  <\/span><\/li>\n
  4. \u53ea\u8003\u8651\u771f\u503c\u60c5\u51b5\uff1a1002X\uff0c.9\u884c\u6bcf\u79d2  <\/span><\/li>\n
  5. ifelse\uff1a1752X\uff0c\u884c\u6bcf\u79d2  <\/span><\/li>\n
  6. which\uff1a8806X\uff0c\u884c\u6bcf\u79d2  <\/span><\/li>\n
  7. Rcpp\uff1a13476X\uff0c\u884c\u6bcf\u79d2  <\/span><\/li>\n
  8. apply\u5904\u7406\u5e76\u884c  <\/span><\/li>\n<\/ol><\/div>\n

    <\/p>\n

    <\/p>\n

    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n

    <\/p>\n

    \u5728\u6700\u540e\u7b14\u8005\u5728\u5b9e\u8df5\u4e2d\u9047\u5230\u7684\u95ee\u9898\uff0c\u8fdb\u884c\u5bf9\u5e94\u7684\u89e3\u51b3\uff1a<\/span><\/span><\/p>\n<\/p>\n

    \u5e94\u7528\u4e00\uff1a\u4f7f\u7528parallel\u5305\u65f6\uff0c\u80fd\u4e0d\u80fdclusterExport\u6574\u4e2a\u51fd\u6570\u5462\uff1f<\/span><\/h2>\n

    \u5e94\u7528\u4e8c\uff1a\u5728\u4f7f\u7528parallel\u5305\u65f6\uff0c\u62a5\u9519\uff1aError in unserialize(node$con) : error reading from connection<\/span><\/h2>\n<\/p>\n


    <\/span><\/p>\n

    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span><\/p>\n


    <\/span><\/p>\n

    \u4e00\u3001parallel\u5305\u7684\u4f7f\u7528\u65b9\u6cd5<\/span><\/h2>\n


    <\/span><\/p>\n

    \u591a\u6570\u5185\u5bb9\u53c2\u8003\uff1aR\u8bed\u8a00\u5e76\u884c\u5316\u57fa\u7840\u4e0e\u63d0\u9ad8<\/span><\/p>\n

    parallel\u662fbase\u5305\uff0c\u6240\u4ee5\u4e0d\u7528install.packages\u5c31\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u3002<\/span><\/p>\n

    \u539f\u7406<\/span><\/span>\uff1a\u662f\u5229\u7528CPU\u7684\u6838\u5fc3\u8fdb\u884c\u8bad\u7ec3\u3002<\/span><\/p>\n

    \u5e94\u7528\u573a\u666f<\/span><\/span>\uff1a\u8ddfapply\u65cf\uff08lapply\/sapply\u6548\u679c\u4e00\u81f4\uff09\uff08 <\/span><\/span><\/span><\/p>\n

    R\u8bed\u8a00\ufe31\u6570\u636e\u5206\u7ec4\u7edf\u8ba1\u51fd\u6570\u65cf\u2014\u2014apply\u65cf\u7528\u6cd5\u4e0e\u5fc3\u5f97<\/span><\/h2>\n

    \uff09 <\/p>\n


    <\/span><\/p>\n

    1\u3001\u4f7f\u7528\u6b65\u9aa4<\/span><\/h3>\n

         \u8bbe\u7f6e\u6838\u5fc3\u6570\uff1ano_cores <- detectCores() - 1<\/span><\/p>\n

         \u6b65\u9aa4\u5206\u7fa4\u73af\u5883\uff1acl <- makeCluster(no_cores)<\/span><\/p>\n

         \u7528\u5230\u7684\u53d8\u91cf\u4e0e\u5305\u590d\u5236\u7ed9\u4e0d\u540c\u7684\u6838\u5fc3\uff1aclusterEvalQ\uff08\u5305\uff09\u3001clusterExport\uff08\u53d8\u91cf\uff09<\/span><\/p>\n

         \u8fd0\u884c\u7b97\u6cd5\uff1aclusterApply(cl, c(9,5), get(\"+\"), 3) <\/span><\/p>\n

         \u5173\u95ed\u96c6\u7fa4\uff1a<\/span><\/p>\n

    stopCluster(cl)<\/code><\/pre>\n<\/p>\n


    <\/span><\/p>\n

         \u5c31OK\u5566\u3002\u4f46\u662f\u8fd9\u91cc\u9762\u5f88\u4ece\u524d\u4e0d\u4e00\u6837\u7684\u662f\uff0c\u5982\u679c\u6709\u73af\u5883\u91cc\u9762\u7684\u5916\u7f6e\u53d8\u91cf\uff08\u81ea\u5df1\u5b9a\u4e49\uff09\u90a3\u4e48\u9700\u8981\u989d\u5916\u63d2\u5165\uff0c\u590d\u5236\u5230\u4e0d\u540c\u6838\u4e0a\u9762\uff0c\u800c\u4e14\u5982\u679c\u6709\u4e0d\u540c\u5305\u91cc\u9762\u7684\u51fd\u6570\uff0c\u90fd\u8981\u989d\u5916\u52a0\u8f7d\u3001\u590d\u5236\u591a\u4efd\u7ed9\u4e0d\u540c\u7684\u7535\u8111\u6838\u5fc3\u3002<\/span><\/p>\n


    <\/span><\/p>\n

    2\u3001\u6848\u4f8b<\/span><\/h3>\n

    <\/span><\/p>\n

    \n
    \n
    \n [html]<\/strong>  view plain
    \n  copy<\/span> <\/p>\n
    <\/div>\n

    <\/span>\n <\/div>\n<\/p><\/div>\n

      \n
    1. library(parallel)  <\/span><\/span><\/li>\n
    2. cl <<\/span>-<\/span> makeCluster(getOption(\"cl.cores\", 2))  <\/span><\/span><\/li>\n
    3. clusterApply(cl, c(9,5), get(\"+\"), 3)   #\u52a0\u51cf\u4e58\u9664  <\/span><\/li>\n
    4. parSapply(cl, c(9,5), get(\"+\"), 3)     <\/span><\/li>\n<\/ol><\/div>\n

             \u6848\u4f8b\u4e00\uff1ac1\u5c31\u662f\u8bbe\u7f6e\u7684\u6838\u5fc3\u6570\uff0c\u6b64\u65f6\u662f2\u6838\u5fc3\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u5229\u7528clusterApply\/parSapply\u7b49\u51fd\u6570\u8fdb\u884c\u8c03\u7528\u3002<\/span>
      \n <\/p>\n

      \n
      \n
      \n [html]<\/strong>  view plain
      \n  copy<\/span> <\/p>\n
      <\/div>\n

      <\/span>\n <\/div>\n<\/p><\/div>\n

        \n
      1. xx <\/span><<\/span>-<\/span> 1  <\/span><\/span><\/li>\n
      2. clusterExport(cl, \"xx\")  <\/span><\/li>\n
      3. clusterCall(cl, function(y) xx + y, 2)  <\/span><\/li>\n<\/ol><\/div>\n

              \u6848\u4f8b\u4e8c\uff1a\u8fd9\u4e2a\u91cc\u9762\u6709xx\u8fd9\u4e2a\u53d8\u91cf\u662f\u989d\u5916\u5b9a\u4e49\u7684\uff0c\u6240\u4ee5\u9700\u8981\u989d\u5916\u52a0\u8f7d\uff0c\u9700\u8981\u7528clusterExport\u51fd\u6570\uff0c\u5bfc\u5165\u5230\u5e76\u884c\u73af\u5883\u4e2d\u3002<\/span> <\/p>\n

        3\u3001parallel\u5185\u5b58\u4f18\u5316\u4e0e\u7ba1\u7406<\/span><\/h3>\n

        \uff081\uff09\u6ce8\u610f\u6570\u636e\u5bb9\u91cf\u7684\u5747\u5300\u5206\u5e03<\/span><\/h4>\n

        <\/span><\/p>\n

        \n
        \n
        \n [html]<\/strong>  view plain
        \n  copy<\/span> <\/p>\n
        <\/div>\n

        <\/span>\n <\/div>\n<\/p><\/div>\n

          \n
        1. parLapply <\/span><<\/span>-<\/span> function (<\/span>cl<\/span> = <\/span>NULL<\/span>, X, fun, ...)   <\/span><\/span><\/li>\n
        2. {  <\/span><\/li>\n
        3.     cl <<\/span>-<\/span> defaultCluster(cl)  <\/span><\/span><\/li>\n
        4.     do.call(c, clusterApply(cl, x<\/span> = <\/span>splitList<\/span>(X, length(cl)),   <\/span><\/span><\/li>\n
        5.         fun<\/span> = <\/span>lapply<\/span>, fun, ...), <\/span>quote<\/span> = <\/span>TRUE<\/span>)  <\/span><\/span><\/li>\n
        6. }  <\/span><\/li>\n<\/ol><\/div>\n


          \n     \u6ce8\u610f\u5230<\/span>splitList(X, length(cl))<\/span> \uff0c\u4ed6\u4f1a\u5c06\u4efb\u52a1\u5206\u5272\u6210\u591a\u4e2a\u90e8\u5206\uff0c\u7136\u540e\u5c06\u4ed6\u4eec\u53d1\u9001\u5230\u4e0d\u540c\u7684\u96c6\u7fa4\u4e2d\u3002\u8fd9\u91cc\u4e00\u4e2a\u95ee\u9898\u5c31\u662f\uff0c\u8b6c\u5982\u5047\u8bbe\u6709\u4e00\u4e2alist\uff0c\u91cc\u9762\u6570\u636e\u91cf\u5206\u522b\u662f\uff1a<\/span><\/span> <\/p>\n

          \uff0899,99,99,2,5,2\uff09<\/span><\/span>
          <\/span><\/p>\n

              \u5982\u679c\u662f\u4e24\u4e2a\u6838\u6570\u636e\u5206\u4e3a\u4e86\uff0899,99,99\uff09\u3001\uff082,5,2\uff09\uff0c\u7b2c\u4e00\u4e2a\u6838\u5206\u4e3a\u5230\u4e86\u90a3\u4e48\u591a\u4efb\u52a1\uff0c\u7b2c\u4e8c\u4e2a\u6838\u5f88\u5c11\uff0c\u90a3\u4e48\u5c31\u4f1a\u7a7a\u95f2\uff0c\u4e8e\u662f\u4e4e\uff0c\u6548\u7387\u8fd8\u662f\u4e0d\u9ad8\uff0c\u6240\u4ee5\u6570\u636e\u5bb9\u91cf\u8981\u5c3d\u91cf\u5747\u5300\u5206\u5e03\u3002<\/span><\/span><\/span><\/span><\/p>\n


          <\/span><\/p>\n

          \uff082\uff09\u96c6\u7fa4\u5185\u5b58\u7c7b\u578b\uff1aFORK\u548cPSOCK<\/span><\/h4>\n

          FORK\u9002\u7528unix\/max\uff0c\u5b9e\u73b0\u5185\u5b58\u5171\u4eab\u4ee5\u53ca\u8282\u7701\u5185\u5b58\uff0c\u5927\u6570\u636e\u73af\u5883\u4e0b\u5185\u5b58\u95ee\u9898\u62a5\u9519\u5c11<\/span>
          <\/span><\/p>\n

          PSOCK\u9002\u7528\u6240\u6709\uff08\u4e00\u822cwindow\u90fd\u662f\u8fd9\u4e2a\uff09<\/span><\/p>\n

          <\/p>\n

          parallel\u5305\u4e2d\u901a\u8fc7\u51fd\u6570\u6765\u8bbe\u7f6e\uff1a<\/span><\/span><\/span><\/p>\n

          \n
          \n
          \n [html]<\/strong>  view plain
          \n  copy<\/span> <\/p>\n
          <\/div>\n

          <\/span>\n <\/div>\n<\/p><\/div>\n

            \n
          1. makeCluster\uff084\uff0c<\/span>type<\/span>=<\/span>\"FORK\"<\/span>\uff09  <\/span><\/span><\/li>\n<\/ol><\/div>\n


            \n FORK\u5bf9\u6027\u80fd\u63d0\u5347\u5f88\u663e\u8457\uff0c\u4f46\u662fwindow\u4e0b\u4e0d\u53ef\u9002\u7528\u3002<\/span> <\/p>\n


            <\/span><\/p>\n

            4\u3001parallel\u4e07\u4e00\u62a5\u9519\u4e86\u548b\u529e\uff1f<\/span><\/span><\/h3>\n

                  lapply\u5728\u4f7f\u7528\u7684\u65f6\u5019\u4e5f\u4f1a\u51fa\u73b0\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u5982\u679c\u51fa\u73b0\u95ee\u9898\uff0c\u90a3\u4e48\u5c31\u767d\u8dd1\u4e86\uff0c\u800c\u4e14\u4e5f\u4e0d\u53ef\u80fd\u7ed9\u4f60\u505c\u987f\u4e0b\u6765\u3002\u90a3\u4e48\u5982\u4f55\u8ba9lapply\u8fd0\u884c\u4e2d\u8df3\u8fc7\u62a5\u9519\u7684\u529e\u6cd5\u5462\uff1f<\/span><\/p>\n

                  R\u8bed\u8a00\u76f8\u5173\u7684\u62a5\u9519\u5904\u7406\u51fd\u6570\u53ef\u89c1\uff1a<\/span>R\u8bed\u8a00-\u5904\u7406\u5f02\u5e38\u503c\u6216\u62a5\u9519\u7684\u4e09\u4e2a\u793a\u4f8b<\/p>\n

                  \u7528tryCatch\u8df3\u8fc7\uff1a<\/span><\/p>\n

            <\/span><\/p>\n

            \n
            \n
            \n [html]<\/strong>  view plain
            \n  copy<\/span> <\/p>\n
            <\/div>\n

            <\/span>\n <\/div>\n<\/p><\/div>\n

              \n
            1. result<\/span> = <\/span>tryCatch<\/span>(  <\/span><\/span><\/li>\n
            2.         {expr},   <\/span><\/li>\n
            3.         warning<\/span> = <\/span>function<\/span>(w) {warning-handler-code},   <\/span><\/span><\/li>\n
            4.         error<\/span> = <\/span>function<\/span>(e) { error-handler-code},   <\/span><\/span><\/li>\n
            5.         finally<\/span> = {cleanup-code}  <\/span><\/span><\/li>\n
            6.         )  <\/span><\/li>\n<\/ol><\/div>\n

              \u51fa\u73b0warning\u3001error\u65f6\u5019\u600e\u4e48\u5904\u7406\uff0c\u5c31\u53ef\u4ee5\u8df3\u8fc7\u4e86\u3002\u4f8b\u5b50\uff1a<\/span> <\/p>\n

              <\/span><\/p>\n

              \n
              \n
              \n [html]<\/strong>  view plain
              \n  copy<\/span> <\/p>\n
              <\/div>\n

              <\/span>\n <\/div>\n<\/p><\/div>\n

                \n
              1. result<\/span> = <\/span>tryCatch<\/span>(  <\/span><\/span><\/li>\n
              2.         {segmentCN(txt)},   <\/span><\/li>\n
              3.         warning<\/span> = <\/span>function<\/span>(w) {\"\u51fa\u8b66\u544a\u5566\"},   <\/span><\/span><\/li>\n
              4.         error<\/span> = <\/span>function<\/span>(e) { \"\u51fa\u9519\u5566\"},   <\/span><\/span><\/li>\n
              5.         )  <\/span><\/li>\n<\/ol><\/div>\n

                \u5206\u8bcd\u65f6\u5019\uff0c\u5bb9\u6613\u56e0\u4e3aLapply\u4e2d\u65ad\u4e4b\u540e\uff0c\u5c31\u4e0d\u4f1a\u8fd0\u884c\u4e86\uff0c\u8fd9\u6837\u529f\u4e8f\u4e00\u7bd1\u6240\u4ee5\u53ef\u4ee5\u7528\u8fd9\u4e2a\u529e\u6cd5\u8df3\u8fc7\u3002<\/span><\/p>\n


                <\/span><\/p>\n

                5\u3001parSapply\/parLapply\u51fd\u6570\u4f7f\u7528\u6280\u5de7<\/span><\/h3>\n

                       \u51fd\u6570\u7684\u5927\u4f53\u7ed3\u6784\u662f\uff1a<\/span><\/p>\n<\/p>\n

                \n
                \n
                \n [html]<\/strong>  view plain
                \n  copy<\/span> <\/p>\n
                <\/div>\n

                <\/span>\n <\/div>\n<\/p><\/div>\n

                  \n
                1. parSapply(cl,x,fun)  <\/span><\/span><\/li>\n<\/ol><\/div>\n


                  \n       \u5176\u4e2dcl\u662f\u9884\u5148\u8bbe\u5b9a\u597d\u7684\uff0cx\u662f\u9700\u8981\u5faa\u73af\u7684\u53d8\u91cf\uff0c\u800cfun\u662f\u51fd\u6570\u3002<\/span> <\/p>\n

                        \u90a3\u4e48\u4e00\u822c\u6765\u8bf4\uff0cfun\u4e4b\u4e2d\u8981\u4f7f\u7528\u7684\u4efb\u4f55\u5185\u5bb9\u90fd\u9700\u8981\u7528clusterEvalQ\uff08\u5305\uff09\u3001clusterExport\uff08\u53d8\u91cf\uff09\u590d\u5236\u5230\u4e0d\u540c\u7684\u6838\u5fc3\u4e4b\u4e2d\u3002<\/span><\/p>\n

                         \u800cx\u5219\u53ef\u4ee5\u4e0d\u7528\u5e03\u7f6e\u5230\u5168\u5c40\uff0c\u56e0\u4e3a\u4ed6\u662f\u5728\u6e90\u73af\u5883\u4e0b\u8c03\u7528\u51fa\u6765\uff0c\u5e76\u62c6\u5206\u4efb\u52a1\u7684\u3002<\/span><\/p>\n


                  <\/span><\/p>\n


                  <\/span><\/p>\n


                  <\/span><\/p>\n


                  <\/span><\/p>\n<\/p>\n

                  \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span>
                  <\/span><\/p>\n


                  <\/span><\/p>\n

                  \u4e8c\u3001foreach\u5305\u7684\u4f7f\u7528\u65b9\u6cd5<\/span><\/h2>\n


                  <\/span><\/p>\n

                  1\u3001\u7b80\u5355\u4f7f\u7528\u6848\u4f8b<\/span><\/p>\n

                  <\/span><\/p>\n

                  \u8bbe\u8ba1foreach<\/code>\u5305\u7684\u601d\u60f3\u53ef\u80fd\u60f3\u8981\u521b\u5efa\u4e00\u4e2alapply\u548cfor\u5faa\u73af\u7684\u6807\u51c6\uff0c\u521d\u59cb\u5316\u7684\u8fc7\u7a0b\u6709\u4e9b\u4e0d\u540c\uff0c\u4f60\u9700\u8981register<\/code>\u6ce8\u518c\u96c6\u7fa4:<\/p>\n

                  library(foreach) library(doParallel) cl<-makeCluster(no_cores) registerDoParallel(cl)<\/code><\/pre>\n

                  \u8981\u8bb0\u5f97\u6700\u540e\u8981\u7ed3\u675f\u96c6\u7fa4\uff08\u4e0d\u662f\u7528stopCluster()<\/code>\uff09\uff1a<\/p>\n

                  stopImplicitCluster()<\/code><\/pre>\n

                  foreach\u51fd\u6570\u53ef\u4ee5\u4f7f\u7528\u53c2\u6570.combine<\/code>\u63a7\u5236\u4f60\u6c47\u603b\u7ed3\u679c\u7684\u65b9\u6cd5\uff1a<\/p>\n

                  > foreach(exponent = 2:4, .combine = c) %dopar% base^exponent [1] 4 8 16<\/code><\/pre>\n
                  > <\/span>foreach<\/span>(exponent =<\/span> 2<\/span>:4<\/span>, .combine =<\/span> rbind) %dopar% <\/span>  <\/span>base^exponent [,1<\/span>] result.1<\/span> 4<\/span> result.2<\/span> 8<\/span> result.3<\/span> 16<\/span><\/code><\/pre>\n
                  foreach<\/span>(exponent =<\/span> 2<\/span>:4<\/span>, .combine =<\/span> list, .multicombine =<\/span> TRUE<\/span>) %dopar% <\/span>  <\/span>base^exponent [[1<\/span>]] [1<\/span>] 4<\/span> [[2<\/span>]] [1<\/span>] 8<\/span> [[3<\/span>]] [1<\/span>] 16<\/span><\/code><\/pre>\n

                  \u6ce8\u610f\u5230\u6700\u540elist\u7684combine\u65b9\u6cd5\u662f\u9ed8\u8ba4\u7684\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\u7528\u5230\u4e00\u4e2a.multicombine<\/code>\u53c2\u6570\uff0c\u4ed6\u53ef\u4ee5\u5e2e\u52a9\u4f60\u907f\u514d\u5d4c\u5957\u5217\u8868\u3002\u6bd4\u5982\u8bf4list(list(result.1, result.2), result.3)<\/code> :<\/p>\n

                  > foreach(exponent = 2:4, .combine = list) %dopar% base^exponent [[1]] [[1]][[1]] [1] 4 [[1]][[2]] [1] 8 [[2]] [1] 16<\/code><\/pre>\n

                  <\/span><\/h5>\n
                  2\u3001\u53d8\u91cf\u4f5c\u7528\u57df<\/span><\/h5>\n

                  \u5728foreach\u4e2d\uff0c\u53d8\u91cf\u4f5c\u7528\u57df\u6709\u4e9b\u4e0d\u540c\uff0c\u5b83\u4f1a\u81ea\u52a8\u52a0\u8f7d\u672c\u5730\u7684\u73af\u5883\u5230\u51fd\u6570\u4e2d\uff1a<\/p>\n

                  > base <- 2 > cl<-makeCluster(2) > registerDoParallel(cl) > foreach(exponent = 2:4, .combine = c) %dopar% base^exponent stopCluster(cl) [1] 4 8 16<\/code><\/pre>\n

                  \u4f46\u662f\uff0c\u5bf9\u4e8e\u7236\u73af\u5883\u7684\u53d8\u91cf\u5219\u4e0d\u4f1a\u52a0\u8f7d\uff0c\u4ee5\u4e0b\u8fd9\u4e2a\u4f8b\u5b50\u5c31\u4f1a\u629b\u51fa\u9519\u8bef\uff1a<\/p>\n

                  test <- function (exponent) { foreach(exponent = 2:4, .combine = c) %dopar% base^exponent } test() Error in base^exponent : task 1 failed - \"object 'base' not found\" <\/code><\/pre>\n

                  \u4e3a\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u4f60\u53ef\u4ee5\u4f7f\u7528.export<\/code>\u8fd9\u4e2a\u53c2\u6570\u800c\u4e0d\u9700\u8981\u4f7f\u7528clusterExport<\/code>\u3002\u6ce8\u610f\u7684\u662f\uff0c\u4ed6\u53ef\u4ee5\u52a0\u8f7d\u6700\u7ec8\u7248\u672c\u7684\u53d8\u91cf\uff0c\u5728\u51fd\u6570\u8fd0\u884c\u524d\uff0c\u53d8\u91cf\u90fd\u662f\u53ef\u4ee5\u6539\u53d8\u7684\uff1a<\/p>\n

                  base <- 2 cl<-makeCluster(2) registerDoParallel(cl) base <- 4 test <- function (exponent) { foreach(exponent = 2:4, .combine = c, .export = \"base\") %dopar% base^exponent } test() stopCluster(cl) [1] 4 8 16<\/code><\/pre>\n

                  \u76f8\u4f3c\u7684\u4f60\u53ef\u4ee5\u4f7f\u7528.packages<\/code>\u53c2\u6570\u6765\u52a0\u8f7d\u5305,\u6bd4\u5982\u8bf4\uff1a.packages = c(\"rms\", \"mice\")<\/code><\/p>\n

                  <\/p>\n

                  \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span>
                  <\/span><\/p>\n


                  <\/span><\/p>\n

                  \u4e09\u3001SupR<\/span><\/h2>\n

                  \u901a\u8fc7\u5bf9\u73b0\u6709R \u5185\u6838\u7684\u6539\u8fdb\u5b9e\u73b0\u5728\u5355\u673a\u4e0a\u7684\u591a\u7ebf\u7a0b\u548c\u5728\u96c6\u7fa4\u4e0a\u7684\u5206\u5e03\u5f0f\u8ba1\u7b97\u529f\u80fd\u3002SupR\u76ee\u524d\u4ecd\u5904\u5728\u5185\u90e8\u8bd5\u7528\u548c\u8865\u5145\u5b8c\u5584\u9636\u6bb5\u3002<\/span><\/span><\/p>\n

                  \"droptable\u4e0etruncatetable_droptable\u4e0etruncatetable
                  <\/span><\/p>\n

                         \u636e\u8bf4supR\u5f88\u597d\u7528\uff0c\u800c\u4e14\u5c0f\u8c61\u5b66\u9662\u7684\u8bb2\u5e08\uff08\u6e38\u7693\u9e9f<\/span><\/span>\uff09\u5df2\u7ecf\u5f00\u59cb\u6559\u6388\u8fd9\u4e2a\u7cfb\u7edf\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u633a\u597d\u7528\u7684\u3002<\/span><\/p>\n


                  <\/span><\/p>\n

                  \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span>
                  <\/span><\/p>\n


                  <\/span><\/p>\n

                  \u56db\u3001\u5185\u5b58\u7ba1\u7406<\/span><\/h2>\n


                  <\/span><\/p>\n

                  \u65b9\u6cd5\u6709\u4e09\uff1a<\/span>
                        \u4e00\u3001\u5347\u7ea7\u786c\u4ef6<\/span>
                        \u4e8c\u3001\u6539\u8fdb\u7b97\u6cd5<\/span>
                        \u4e09\u3001\u4fee\u6539\u64cd\u4f5c\u7cfb\u7edf\u5206\u914d\u7ed9R\u7684\u5185\u5b58\u4e0a\u9650, memory.size(T)\u67e5\u770b\u5df2\u5206\u914d\u5185\u5b58 <\/span>
                  <\/span><\/p>\n

                  <\/span><\/p>\n

                  \n

                  \n
                  \n
                  \n [html]<\/strong>  view plain
                  \n  copy<\/span> <\/p>\n
                  <\/div>\n

                  <\/span>\n <\/div>\n<\/p><\/div>\n

                    \n
                  1. memory.size(F)#\u67e5\u770b\u5df2\u4f7f\u7528\u5185\u5b58    <\/span><\/span><\/li>\n
                  2. memory.limit()#\u67e5\u770b\u5185\u5b58\u4e0a\u9650   <\/span><\/li>\n
                  3. object.size()#\u770b\u6bcf\u4e2a\u53d8\u91cf\u5360\u591a\u5927\u5185\u5b58\u3002  <\/span><\/li>\n
                  4. memory.size()#\u67e5\u770b\u73b0\u5728\u7684work space\u7684\u5185\u5b58\u4f7f\u7528  <\/span><\/li>\n
                  5. memory.limit()#\u67e5\u770b\u7cfb\u7edf\u89c4\u5b9a\u7684\u5185\u5b58\u4f7f\u7528\u4e0a\u9650\u3002\u5982\u679c\u73b0\u5728\u7684\u5185\u5b58\u4e0a\u9650\u4e0d\u591f\u7528\uff0c\u53ef\u4ee5\u901a\u8fc7memory.limit(newLimit)\u66f4\u6539\u5230\u4e00\u4e2a\u65b0\u7684\u4e0a\u9650\u3002\u6ce8\u610f\uff0c\u572832\u4f4d\u7684R\u4e2d\uff0c\u5c01\u9876\u4e0a\u9650\u4e3a4G\uff0c\u65e0\u6cd5\u5728\u4e00\u4e2a\u7a0b\u5e8f\u4e0a\u4f7f\u7528\u8d85\u8fc74G \uff08\u6570\u4f4d\u4e0a\u9650\uff09\u3002\u8fd9\u79cd\u65f6\u5019\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u752864\u4f4d\u7684\u7248\u672c\u3002  <\/span><\/li>\n<\/ol><\/div>\n

                    \u8be6\u60c5\u770b\uff1a R\u8bed\u8a00\ufe31\u5927\u6570\u636e\u96c6\u4e0b\u8fd0\u884c\u5185\u5b58\u7ba1\u7406   \u4ee5\u53ca   R\u8bed\u8a00\u4e4b\u5185\u5b58\u7ba1\u7406 <\/p>\n

                    <\/p>\n

                    \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span>
                    <\/span><\/p>\n


                    <\/span><\/p>\n

                    \u5e94\u7528\u4e00\uff1a\u4f7f\u7528parallel\u5305\u65f6\uff0c\u80fd\u4e0d\u80fdclusterExport\u6574\u4e2a\u51fd\u6570\u5462\uff1f<\/span><\/h2>\n


                    <\/span><\/span><\/p>\n


                    <\/span><\/span><\/p>\n

                          R\u8bed\u8a00\u5728\u4f7f\u7528Parallel\u65f6\u5019\uff0c\u4f1a\u51fa\u73b0\u8fd9\u6837\u7684\u7591\u95ee\uff0c\u4e00\u4e9b\u4e1c\u897f\u90fd\u9700\u8981\u5e7f\u64ad\u7ed9\u4e0d\u540c\u7684\u6838\u5fc3\uff0c\u90a3\u4e48\u5728clusterExport\u6b65\u9aa4\u600e\u4e48\u529e\u5462\uff1f\u80fd\u4e0d\u80fdclusterExport\u4e00\u6574\u4e2a\u51fd\u6570\uff1f\u7136\u540e\u76f4\u63a5parLapply\u5462\uff1f<\/span><\/span><\/span><\/p>\n

                          \u7b54\u6848\u5426\u5b9a\u7684\u3002\u7b14\u8005\u5728\u7528\u7684\u65f6\u5019\uff0c\u600e\u4e48\u6837\u90fd\u4e0d\u80fd\u628a\u6574\u4e2a\u51fd\u6570\u52a0\u8f7d\u8fdb\u53bb\uff0c\u6240\u4ee5\u53ea\u80fd\u53e6\u60f3\u529e\u6cd5\u3002<\/span><\/span><\/p>\n

                          \u65e2\u7136\u4e0d\u80fdclusterExport\u6574\u4e2a\u51fd\u6570\uff0c\u90a3\u5c31\u53ea\u80fd\u6539\u9020\u6211\u4eec\u7684\u51fd\u6570\u53bb\u9002\u5e94parallel\u5305\u4e86\u3002<\/span><\/span><\/span><\/span><\/p>\n

                          \u6765\u770b\u51e0\u4e2a\u51fd\u6570\u201c\u88ab\u201d\u6539\u9020\u7684\u4f8b\u5b50\uff0c\u4e00\u822c\u6765\u8bf4\u6709\u4e24\u4e2a\u529e\u6cd5\uff1a<\/span><\/span><\/p>\n


                    <\/span><\/span><\/p>\n

                    1\u3001\u65b9\u6cd5\u4e00\uff1a\u901a\u8fc7.GlobalEnv\u5e7f\u64ad\u6210\u5168\u5c40\u53d8\u91cf<\/span><\/h3>\n

                    <\/span><\/span><\/span><\/p>\n

                    \n
                    \n
                    \n [plain]<\/strong>  view plain
                    \n  copy<\/span> <\/p>\n
                    <\/div>\n

                    <\/span>\n <\/div>\n<\/p><\/div>\n

                      \n
                    1. clusterExport(cl=cl, varlist=c(\"text.var\", \"ntv\", \"gc.rate\", \"pos\"), envir=environment())  <\/span><\/span><\/li>\n<\/ol><\/div>\n

                            \u5728\u51fd\u6570\u5bfc\u5165\u7684\u65f6\u5019\uff0c\u52a0\u5165envir\u53d8\u91cf\u8ba9\u5176\u5e7f\u64ad\u7ed9\u4e0d\u540c\u7684\u6838\u5fc3\uff0c\u8fd9\u4e2a\u53ef\u4ee5\u653e\u5728\u51fd\u6570\u4e4b\u4e2d\u6765\u4f7f\u7528\u3002 <\/p>\n


                      <\/span><\/span><\/p>\n

                      2\u3001\u65b9\u6cd5\u4e8c\uff1a\u628aparLapply\u5d4c\u5957\u8fdb\u51fd\u6570\u4e4b\u4e2d<\/span><\/span><\/h3>\n

                      <\/span><\/span><\/span><\/p>\n

                      \n
                      \n
                      \n [plain]<\/strong>  view plain
                      \n  copy<\/span> <\/p>\n
                      <\/div>\n

                      <\/span>\n <\/div>\n<\/p><\/div>\n

                        \n
                      1. par.test <- function(text.var, gc.rate=10){   <\/span><\/span><\/li>\n
                      2.     require(parallel)  <\/span><\/li>\n
                      3.     pos <-  function(i) {  <\/span><\/li>\n
                      4.         paste(sapply(strsplit(tolower(i), \" \"), nchar), collapse=\" | \")  <\/span><\/li>\n
                      5.     }  <\/span><\/li>\n
                      6.     cl <- makeCluster(mc <- getOption(\"cl.cores\", 4))  <\/span><\/li>\n
                      7.     parLapply(cl, text.var, function(text.vari, gc.rate, pos) {  <\/span><\/li>\n
                      8.         x <- pos(text.vari)  <\/span><\/li>\n
                      9.         if (i%%gc.rate==0) gc()  <\/span><\/li>\n
                      10.         x  <\/span><\/li>\n
                      11.     }, gc.rate, pos)  <\/span><\/li>\n
                      12. }  <\/span><\/li>\n<\/ol><\/div>\n

                               \u53ef\u4ee5\u770b\u5230\u7684\u8fd9\u4e2a \u4f8b\u5b50\uff0c\u5c31\u662f\u628a\u5185\u5bb9\u5d4c\u5957\u5230parLapply\u4e4b\u4e2d\u4e86\u3002\u540c\u65f6\u4e5f\u53ef\u4ee5\u5b66\u4e60\u5230\uff0cparLapply\u4f7f\u7528\u65b9\u6cd5\u4e5f\u5f88\u4e0d\u9519\uff0c\u4e5f\u53ef\u4ee5\u5b66\u4e60\u4e00\u4e0b\u3002 <\/p>\n

                              \u518d\u6765\u770b\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/span><\/p>\n

                        <\/span><\/p>\n

                        \n
                        \n
                        \n [plain]<\/strong>  view plain
                        \n  copy<\/span> <\/p>\n
                        <\/div>\n

                        <\/span>\n <\/div>\n<\/p><\/div>\n

                          \n
                        1. mainFunction <- function(cl) {  <\/span><\/span><\/li>\n
                        2.     fa <- function(x) fb(x)  <\/span><\/li>\n
                        3.     fb <- function(x) fc(x)  <\/span><\/li>\n
                        4.     fc <- function(x) x  <\/span><\/li>\n
                        5.     y <- 7  <\/span><\/li>\n
                        6.     workerFunction <- function(i) {  <\/span><\/li>\n
                        7.         do.call(functionNames[[i]], list(y))  <\/span><\/li>\n
                        8.     }  <\/span><\/li>\n
                        9.     environment(workerFunction) <- .GlobalEnv  <\/span><\/li>\n
                        10.     environment(fa) <- .GlobalEnv  <\/span><\/li>\n
                        11.     environment(fb) <- .GlobalEnv  <\/span><\/li>\n
                        12.     environment(fc) <- .GlobalEnv  <\/span><\/li>\n
                        13.     functionNames <- c(\"fa\", \"fb\", \"fc\")  <\/span><\/li>\n
                        14.     clusterExport(cl, varlist=c(\"functionNames\", functionNames, \"y\"),  <\/span><\/li>\n
                        15.                   envir=environment())  <\/span><\/li>\n
                        16.     parLapply(cl, seq_along(functionNames), workerFunction)  <\/span><\/li>\n
                        17. }  <\/span><\/li>\n
                        18.   <\/span><\/li>\n
                        19. library(parallel)  <\/span><\/li>\n
                        20. cl <- makeCluster(detectCores())  <\/span><\/li>\n
                        21. mainFunction(cl)  <\/span><\/li>\n
                        22. stopCluster(cl)  <\/span><\/li>\n<\/ol><\/div>\n

                          <\/p>\n

                          \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span><\/p>\n

                          \u5e94\u7528\u4e8c\uff1a\u5728\u4f7f\u7528parallel\u5305\u65f6\uff0c\u62a5\u9519\uff1aError in unserialize(node$con) : error reading from connection<\/span><\/span><\/h2>\n


                          <\/span><\/p>\n

                                \u5728R\u8bed\u8a00\u4e2d\u4f7f\u7528\u5e76\u884c\u7b97\u6cd5\u7684\u65f6\u5019\uff0c\u4f1a\u51fa\u73b0\u62a5\u9519\uff0c\u65e0\u6cd5\u8fde\u63a5\u5230\u6838\u5fc3\uff0c\u5373\u4f7f\u5728\u672c\u6765\u8fde\u63a5\u4e0a\u7684\u65f6\u5019\u3002\u901a\u8fc7\u67e5\u9605\u6587\u732e\u770b\u5230\u4e86\uff0c\u8fd9\u662f\u56e0\u4e3a\u201c\u8c03\u7528\u6838\u5fc3\u6570--\u8ba1\u7b97\u673a\u5185\u5b58\u201d\u7684\u4e0d\u5339\u914d\u9020\u6210\u7684\u3002<\/span><\/span><\/span><\/p>\n

                                \u5982\u679c\u4f60\u7684\u6570\u636e\u96c6\u5f88\u5927\uff0c\u8c03\u7528\u4e86\u5f88\u591a\u6838\u5fc3\uff0c\u90a3\u4e48\u4f60\u7684\u8ba1\u7b97\u673a\u5185\u5b58\u5982\u679c\u4e0d\u591f\u5339\u914d\uff0c\u5c31\u4f1a\u51fa\u73b0\u8fde\u63a5\u4e0d\u4e0a\u7684\u4e0d\u9519\uff0c\u751a\u81f3\u8fd8\u51fa\u73b0\u5361\u673a\uff0c\u4e00\u52a8\u4e0d\u52a8\u7684\u60c5\u51b5\uff08\u5f53\u7136\uff0c\u53ea\u8981\u8010\u5fc3\u7b49\u5f85\uff0c\u5176\u5b9e\u4ed6\u8fd8\u662f\u4f1a\u7ee7\u7eed\u8fd0\u884c\u7684...\u7b49\u5f85\u7684\u65f6\u5019\u4f1a\u6709\u70b9\u957f\uff09<\/span><\/p>\n


                          <\/span><\/p>\n

                          \u89e3\u51b3\u529e\u6cd5\u4e00\uff1a\u8c03\u7528FORK\uff0cwindow\u4e0d\u80fd...<\/span><\/span><\/span><\/p>\n

                          <\/span><\/p>\n

                                FORK\u9002\u7528unix\/max\uff0c\u5b9e\u73b0\u5185\u5b58\u5171\u4eab\u4ee5\u53ca\u8282\u7701\u5185\u5b58\uff0c\u5927\u6570\u636e\u73af\u5883\u4e0b\u5185\u5b58\u95ee\u9898\u62a5\u9519\u5c11
                          <\/span><\/p>\n

                                PSOCK\u9002\u7528\u6240\u6709\uff08\u4e00\u822cwindow\u90fd\u662f\u8fd9\u4e2a\uff09<\/span><\/p>\n

                                \u4e0d\u8fc7\u8c03\u7528FORK\u4e5f\u8fd8\u662f\u6cbb\u6807\u4e0d\u6cbb\u672c\u3002 <\/p>\n


                          <\/span><\/p>\n

                          \u89e3\u51b3\u529e\u6cd5\u4e8c\uff1a\u5206\u5f00\u5e76\u884c\uff0c\u5c0f\u6b65\u8fed\u4ee3<\/span><\/span><\/p>\n

                                \u8b6c\u598210\u4e07\u6570\u636e\uff0c\u90a3\u4e48\u5c31\u201c2\u4e07+2\u4e07+<\/span>2\u4e07+<\/span>2\u4e07+<\/span>2\u4e07<\/span>\u201d\u7684\u8dd1\uff0c\u5982\u679c\u8fd8\u51fa\u73b0\u8131\u673a\uff0c\u5c31\u7528\u4e4b\u524dtryCatch\u8df3\u8fc7\uff0c\u8ba9\u635f\u5931\u964d\u4f4e\u5230\u6700\u5c0f\u3002<\/span><\/span><\/p>\n

                                \u6700\u597d\u7684\u529e\u6cd5\u4e86\u3002<\/span><\/span><\/p>\n

                          <\/p>\n

                          <\/p>\n

                          \u53c2\u8003\u6587\u732e\uff1aHow-to go parallel in R \u2013 basics + tips<\/span><\/span><\/p>\n

                          <\/p>\n

                          \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span><\/p>\n


                          <\/span><\/p>\n

                          \u53c2\u8003\u6587\u732e<\/span><\/h2>\n


                          <\/span><\/span><\/span><\/p>\n

                          1\u3001R\u8bed\u8a00\u5e76\u884c\u5316\u57fa\u7840\u4e0e\u63d0\u9ad8<\/span><\/span><\/span><\/p>\n<\/p>\n

                          2\u3001R\u4e0e\u5e76\u884c\u8ba1\u7b97<\/span><\/span><\/h2>\n<\/p>\n

                          3\u3001sparklyr\u5305\uff1a\u5b9e\u73b0Spark\u4e0eR\u7684\u63a5\u53e3\uff0c\u4f1a\u7528dplyr\u5c31\u80fd\u73a9Spark<\/span><\/span><\/p>\n

                          4\u3001Sparklyr\u4e0eDocker\u7684\u63a8\u8350\u7cfb\u7edf\u5b9e\u6218
                          <\/span><\/span><\/p>\n

                          \n

                          5\u3001R\u8bed\u8a00\ufe31H2o\u6df1\u5ea6\u5b66\u4e60\u7684\u4e00\u4e9bR\u8bed\u8a00\u5b9e\u8df5\u2014\u2014H2o\u5305<\/span><\/span><\/p>\n

                          \n

                          6\u3001R\u7528\u6237\u7684\u798f\u97f3\ufe31TensorFlow\uff1aTensorFlow\u7684R\u63a5\u53e3<\/span><\/span><\/span> <\/p>\n

                          7\u3001mxnet\uff1a\u7ed3\u5408R\u4e0eGPU\u52a0\u901f\u6df1\u5ea6\u5b66\u4e60<\/span><\/span><\/span><\/span><\/p>\n

                          8\u3001\u788e\u7247\ufe31R\u8bed\u8a00\u4e0e\u6df1\u5ea6\u5b66\u4e60<\/span><\/span><\/p>\n<\/p><\/div>\n<\/p><\/div>\n

                          \n \u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3a\u535a\u4e3b\u539f\u521b\u6587\u7ae0\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u6765\u6e90\u201c\u7d20\u8d28\u4e91\u535a\u5ba2\u201d\uff0c\u8c22\u8c22\u5408\u4f5c\uff01\uff01\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u7d20\u8d28\u4e91\u7b14\u8bb0 https:\/\/blog.csdn.net\/sinat_\/article\/details\/\n <\/div>\n

                          \u7ec8\u4e8e\u5f00\u59cb\u653b\u514b\u5e76\u884c\u8fd9\u4e00\u5757\u4e86\uff0c\u6709\u70b9\u5c0f\u5174\u594b\uff0c\u6765\u770b\u770b\u7f51\u7edc\u4e0aR\u8bed\u8a00\u5e76\u884c\u529e\u6cd5\u6709\u54ea\u4e9b\uff1a <\/p>\n

                               \u8d75\u9e4f\u8001\u5e08\uff08R\u4e0e\u5e76\u884c\u8ba1\u7b97<\/span>\uff09\u505a\u7684\u603b\u7ed3\u5df2\u7ecf\u5f88\u5230\u4f4d\u3002\u73b0\u5728\u5e76\u884c\u53ef\u4ee5\u5206\u4e3a\uff1a<\/span><\/p>\n


                          <\/span><\/p>\n

                              <\/span> \u9690\u5f0f\u5e76\u884c\uff1a<\/span>\u9690\u5f0f\u8ba1\u7b97\u5bf9\u7528\u6237\u9690\u85cf\u4e86\u5927\u90e8\u5206\u7ec6\u8282\uff0c\u7528\u6237\u4e0d\u9700\u8981\u77e5\u9053\u5177\u4f53\u6570\u636e\u5206\u914d\u65b9\u5f0f \uff0c\u7b97\u6cd5\u7684\u5b9e\u73b0\u6216\u8005\u5e95\u5c42\u7684\u786c\u4ef6\u8d44\u6e90\u5206\u914d\u3002\u7cfb\u7edf\u4f1a\u6839\u636e\u5f53\u524d\u7684\u786c\u4ef6\u8d44\u6e90\u6765\u81ea\u52a8\u542f\u52a8\u8ba1\u7b97\u6838\u5fc3\u3002\u663e\u7136\uff0c\u8fd9\u79cd\u6a21\u5f0f\u5bf9\u4e8e\u5927\u591a\u6570\u7528\u6237\u6765\u8bf4\u662f\u6700\u559c\u95fb\u4e50\u89c1\u7684\u3002<\/span><\/span><\/span><\/p>\n

                              \u663e\u6027\u5e76\u884c\uff1a<\/span>\u663e\u5f0f\u8ba1\u7b97\u5219\u8981\u6c42\u7528\u6237\u80fd\u591f\u81ea\u5df1\u5904\u7406\u7b97\u4f8b\u4e2d\u6570\u636e\u5212\u5206\uff0c\u4efb\u52a1\u5206\u914d\uff0c\u8ba1\u7b97\u4ee5\u53ca\u6700\u540e\u7684\u7ed3\u679c\u6536\u96c6\u3002\u56e0\u6b64\uff0c\u663e\u5f0f\u8ba1\u7b97\u6a21\u5f0f\u5bf9\u7528\u6237\u7684\u8981\u6c42\u66f4\u9ad8\uff0c\u7528\u6237\u4e0d\u4ec5\u9700\u8981\u7406\u89e3\u81ea\u5df1\u7684\u7b97\u6cd5\uff0c\u8fd8\u9700\u8981\u5bf9\u5e76\u884c\u8ba1\u7b97\u548c\u786c\u4ef6\u6709\u4e00\u5b9a\u7684\u7406\u89e3\u3002\u503c\u5f97\u5e86\u5e78\u7684\u662f\uff0c\u73b0\u6709R\u4e2d\u7684\u5e76\u884c\u8ba1\u7b97\u6846\u67b6\uff0c\u5982parallel (snow,multicores)\uff0cRmpi\u548cforeach\u7b49\u91c7\u7528\u7684\u662f\u6620\u5c04\u5f0f\u5e76\u884c\u6a21\u578b\uff08Mapping\uff09\uff0c\u4f7f\u7528\u65b9\u6cd5\u7b80\u5355\u6e05\u6670\uff0c\u6781\u5927\u5730\u7b80\u5316\u4e86\u7f16\u7a0b\u590d\u6742\u5ea6\u3002R\u7528\u6237\u53ea\u9700\u8981\u5c06\u73b0\u6709\u7a0b\u5e8f\u8f6c\u5316\u4e3a*apply\u6216\u8005for\u7684\u5faa\u73af\u5f62\u5f0f\u4e4b\u540e\uff0c\u901a\u8fc7\u7b80\u5355\u7684API\u66ff\u6362\u6765\u5b9e\u73b0\u5e76\u884c\u8ba1\u7b97\u3002<\/span><\/span><\/p>\n


                          <\/span><\/p>\n

                          \u7b80\u5355\u603b\u7ed3\u5c31\u662f\uff1a<\/span><\/p>\n

                              \u9690\u5f0f\u5e76\u884c\uff1a<\/span>OpenBLAS\uff0cIntel MKL\uff0cNVIDIA cuBLAS\uff0cH2O(\u53c2\u8003\u6211\u7684\u535a\u5ba2)\u7b49<\/span>
                          <\/span><\/p>\n

                              \u663e\u6027\u5e76\u884c\uff1a<\/span>parallel\uff08\u4e3b\u6253lapply\u5e94\u7528\uff09\u3001foreach\uff08\u4e3b\u6253for\u5faa\u73af\uff09\u3001SupR\u3001\u8fd8\u6709\u5229\u7528GPU\u7684\u529e\u6cd5\uff08gpuR\uff09
                          <\/span><\/p>\n


                          <\/span><\/p>\n

                                \u540c\u65f6\u5e76\u884c\u65f6\u5bf9\u5185\u5b58\u7684\u6d88\u8017\u6781\u5927\uff0c\u8d85\u7ea7\u5bb9\u6613\u7206\u53d1\u5185\u5b58\u95ee\u9898\uff0c\u800c\u4e14R\u7684\u5185\u5b58\u95ee\u9898\u4e00\u76f4\u90fd\u662fR\u5f88\u96be\u89e3\u51b3\u7684\u95ee\u9898\uff0c\u8fd9\u8fb9\u7b14\u8005\u4e5f\u628a\u770b\u5230\u7684\u4e00\u4e9b\u65b9\u5f0f\u5217\u51fa\u6765\u3002<\/span><\/p>\n

                                \u5f53\u7136\u5728\u4f7f\u7528\u4e00\u4e9b\u9ad8\u5927\u4e0a\u7684\u5e76\u884c\u5305\u4ee5\u53ca\u6846\u67b6\u4e4b\u524d\uff0c\u5982\u679c\u4f60\u80fd\u591f\u4ece\u7f16\u7801\u5c0f\u7ec6\u8282\u4f18\u5316\uff0c\u6548\u7387\u4e5f\u80fd\u63d0\u9ad8\u5f88\u591a<\/span><\/span>\uff0c\u8b6c\u5982\uff1a<\/span><\/p>\n<\/p>\n

                           <\/span><\/p>\n

                          \n
                          \n
                          \n [html]<\/strong>  view plain
                          \n  copy<\/span> <\/p>\n
                          <\/div>\n

                          <\/span>\n <\/div>\n<\/p><\/div>\n

                            \n
                          1. \u65b9\u6cd5\uff1a\u901f\u5ea6\uff0c nrow(df)\/<\/span>time_taken<\/span> = <\/span>n<\/span> \u884c\u6bcf\u79d2  <\/span><\/span><\/li>\n
                          2. \u539f\u59cb\u65b9\u6cd5\uff1a1X, 856.2255\u884c\u6bcf\u79d2(\u6b63\u5219\u5316\u4e3a1)  <\/span><\/li>\n
                          3. \u5411\u91cf\u5316\u65b9\u6cd5\uff1a738X, \u884c\u6bcf\u79d2  <\/span><\/li>\n
                          4. \u53ea\u8003\u8651\u771f\u503c\u60c5\u51b5\uff1a1002X\uff0c.9\u884c\u6bcf\u79d2  <\/span><\/li>\n
                          5. ifelse\uff1a1752X\uff0c\u884c\u6bcf\u79d2  <\/span><\/li>\n
                          6. which\uff1a8806X\uff0c\u884c\u6bcf\u79d2  <\/span><\/li>\n
                          7. Rcpp\uff1a13476X\uff0c\u884c\u6bcf\u79d2  <\/span><\/li>\n
                          8. apply\u5904\u7406\u5e76\u884c  <\/span><\/li>\n<\/ol><\/div>\n

                            <\/p>\n

                            <\/p>\n

                            \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n

                            <\/p>\n

                            \u5728\u6700\u540e\u7b14\u8005\u5728\u5b9e\u8df5\u4e2d\u9047\u5230\u7684\u95ee\u9898\uff0c\u8fdb\u884c\u5bf9\u5e94\u7684\u89e3\u51b3\uff1a<\/span><\/span><\/p>\n<\/p>\n

                            \u5e94\u7528\u4e00\uff1a\u4f7f\u7528parallel\u5305\u65f6\uff0c\u80fd\u4e0d\u80fdclusterExport\u6574\u4e2a\u51fd\u6570\u5462\uff1f<\/span><\/h2>\n

                            \u5e94\u7528\u4e8c\uff1a\u5728\u4f7f\u7528parallel\u5305\u65f6\uff0c\u62a5\u9519\uff1aError in unserialize(node$con) : error reading from connection<\/span><\/h2>\n<\/p>\n


                            <\/span><\/p>\n

                            \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span><\/p>\n


                            <\/span><\/p>\n

                            \u4e00\u3001parallel\u5305\u7684\u4f7f\u7528\u65b9\u6cd5<\/span><\/h2>\n


                            <\/span><\/p>\n

                            \u591a\u6570\u5185\u5bb9\u53c2\u8003\uff1aR\u8bed\u8a00\u5e76\u884c\u5316\u57fa\u7840\u4e0e\u63d0\u9ad8<\/span><\/p>\n

                            parallel\u662fbase\u5305\uff0c\u6240\u4ee5\u4e0d\u7528install.packages\u5c31\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u3002<\/span><\/p>\n

                            \u539f\u7406<\/span><\/span>\uff1a\u662f\u5229\u7528CPU\u7684\u6838\u5fc3\u8fdb\u884c\u8bad\u7ec3\u3002<\/span><\/p>\n

                            \u5e94\u7528\u573a\u666f<\/span><\/span>\uff1a\u8ddfapply\u65cf\uff08lapply\/sapply\u6548\u679c\u4e00\u81f4\uff09\uff08 <\/span><\/span><\/span><\/p>\n

                            R\u8bed\u8a00\ufe31\u6570\u636e\u5206\u7ec4\u7edf\u8ba1\u51fd\u6570\u65cf\u2014\u2014apply\u65cf\u7528\u6cd5\u4e0e\u5fc3\u5f97<\/span><\/h2>\n

                            \uff09 <\/p>\n


                            <\/span><\/p>\n

                            1\u3001\u4f7f\u7528\u6b65\u9aa4<\/span><\/h3>\n

                                 \u8bbe\u7f6e\u6838\u5fc3\u6570\uff1ano_cores <- detectCores() - 1<\/span><\/p>\n

                                 \u6b65\u9aa4\u5206\u7fa4\u73af\u5883\uff1acl <- makeCluster(no_cores)<\/span><\/p>\n

                                 \u7528\u5230\u7684\u53d8\u91cf\u4e0e\u5305\u590d\u5236\u7ed9\u4e0d\u540c\u7684\u6838\u5fc3\uff1aclusterEvalQ\uff08\u5305\uff09\u3001clusterExport\uff08\u53d8\u91cf\uff09<\/span><\/p>\n

                                 \u8fd0\u884c\u7b97\u6cd5\uff1aclusterApply(cl, c(9,5), get(\"+\"), 3) <\/span><\/p>\n

                                 \u5173\u95ed\u96c6\u7fa4\uff1a<\/span><\/p>\n

                            stopCluster(cl)<\/code><\/pre>\n<\/p>\n


                            <\/span><\/p>\n

                                 \u5c31OK\u5566\u3002\u4f46\u662f\u8fd9\u91cc\u9762\u5f88\u4ece\u524d\u4e0d\u4e00\u6837\u7684\u662f\uff0c\u5982\u679c\u6709\u73af\u5883\u91cc\u9762\u7684\u5916\u7f6e\u53d8\u91cf\uff08\u81ea\u5df1\u5b9a\u4e49\uff09\u90a3\u4e48\u9700\u8981\u989d\u5916\u63d2\u5165\uff0c\u590d\u5236\u5230\u4e0d\u540c\u6838\u4e0a\u9762\uff0c\u800c\u4e14\u5982\u679c\u6709\u4e0d\u540c\u5305\u91cc\u9762\u7684\u51fd\u6570\uff0c\u90fd\u8981\u989d\u5916\u52a0\u8f7d\u3001\u590d\u5236\u591a\u4efd\u7ed9\u4e0d\u540c\u7684\u7535\u8111\u6838\u5fc3\u3002<\/span><\/p>\n


                            <\/span><\/p>\n

                            2\u3001\u6848\u4f8b<\/span><\/h3>\n

                            <\/span><\/p>\n

                            \n
                            \n
                            \n [html]<\/strong>  view plain
                            \n  copy<\/span> <\/p>\n
                            <\/div>\n

                            <\/span>\n <\/div>\n<\/p><\/div>\n

                              \n
                            1. library(parallel)  <\/span><\/span><\/li>\n
                            2. cl <<\/span>-<\/span> makeCluster(getOption(\"cl.cores\", 2))  <\/span><\/span><\/li>\n
                            3. clusterApply(cl, c(9,5), get(\"+\"), 3)   #\u52a0\u51cf\u4e58\u9664  <\/span><\/li>\n
                            4. parSapply(cl, c(9,5), get(\"+\"), 3)     <\/span><\/li>\n<\/ol><\/div>\n

                                     \u6848\u4f8b\u4e00\uff1ac1\u5c31\u662f\u8bbe\u7f6e\u7684\u6838\u5fc3\u6570\uff0c\u6b64\u65f6\u662f2\u6838\u5fc3\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u5229\u7528clusterApply\/parSapply\u7b49\u51fd\u6570\u8fdb\u884c\u8c03\u7528\u3002<\/span>
                              \n <\/p>\n

                              \n
                              \n
                              \n [html]<\/strong>  view plain
                              \n  copy<\/span> <\/p>\n
                              <\/div>\n

                              <\/span>\n <\/div>\n<\/p><\/div>\n

                                \n
                              1. xx <\/span><<\/span>-<\/span> 1  <\/span><\/span><\/li>\n
                              2. clusterExport(cl, \"xx\")  <\/span><\/li>\n
                              3. clusterCall(cl, function(y) xx + y, 2)  <\/span><\/li>\n<\/ol><\/div>\n

                                      \u6848\u4f8b\u4e8c\uff1a\u8fd9\u4e2a\u91cc\u9762\u6709xx\u8fd9\u4e2a\u53d8\u91cf\u662f\u989d\u5916\u5b9a\u4e49\u7684\uff0c\u6240\u4ee5\u9700\u8981\u989d\u5916\u52a0\u8f7d\uff0c\u9700\u8981\u7528clusterExport\u51fd\u6570\uff0c\u5bfc\u5165\u5230\u5e76\u884c\u73af\u5883\u4e2d\u3002<\/span> <\/p>\n

                                3\u3001parallel\u5185\u5b58\u4f18\u5316\u4e0e\u7ba1\u7406<\/span><\/h3>\n

                                \uff081\uff09\u6ce8\u610f\u6570\u636e\u5bb9\u91cf\u7684\u5747\u5300\u5206\u5e03<\/span><\/h4>\n

                                <\/span><\/p>\n

                                \n
                                \n
                                \n [html]<\/strong>  view plain
                                \n  copy<\/span> <\/p>\n
                                <\/div>\n

                                <\/span>\n <\/div>\n<\/p><\/div>\n

                                  \n
                                1. parLapply <\/span><<\/span>-<\/span> function (<\/span>cl<\/span> = <\/span>NULL<\/span>, X, fun, ...)   <\/span><\/span><\/li>\n
                                2. {  <\/span><\/li>\n
                                3.     cl <<\/span>-<\/span> defaultCluster(cl)  <\/span><\/span><\/li>\n
                                4.     do.call(c, clusterApply(cl, x<\/span> = <\/span>splitList<\/span>(X, length(cl)),   <\/span><\/span><\/li>\n
                                5.         fun<\/span> = <\/span>lapply<\/span>, fun, ...), <\/span>quote<\/span> = <\/span>TRUE<\/span>)  <\/span><\/span><\/li>\n
                                6. }  <\/span><\/li>\n<\/ol><\/div>\n


                                  \n     \u6ce8\u610f\u5230<\/span>splitList(X, length(cl))<\/span> \uff0c\u4ed6\u4f1a\u5c06\u4efb\u52a1\u5206\u5272\u6210\u591a\u4e2a\u90e8\u5206\uff0c\u7136\u540e\u5c06\u4ed6\u4eec\u53d1\u9001\u5230\u4e0d\u540c\u7684\u96c6\u7fa4\u4e2d\u3002\u8fd9\u91cc\u4e00\u4e2a\u95ee\u9898\u5c31\u662f\uff0c\u8b6c\u5982\u5047\u8bbe\u6709\u4e00\u4e2alist\uff0c\u91cc\u9762\u6570\u636e\u91cf\u5206\u522b\u662f\uff1a<\/span><\/span> <\/p>\n

                                  \uff0899,99,99,2,5,2\uff09<\/span><\/span>
                                  <\/span><\/p>\n

                                      \u5982\u679c\u662f\u4e24\u4e2a\u6838\u6570\u636e\u5206\u4e3a\u4e86\uff0899,99,99\uff09\u3001\uff082,5,2\uff09\uff0c\u7b2c\u4e00\u4e2a\u6838\u5206\u4e3a\u5230\u4e86\u90a3\u4e48\u591a\u4efb\u52a1\uff0c\u7b2c\u4e8c\u4e2a\u6838\u5f88\u5c11\uff0c\u90a3\u4e48\u5c31\u4f1a\u7a7a\u95f2\uff0c\u4e8e\u662f\u4e4e\uff0c\u6548\u7387\u8fd8\u662f\u4e0d\u9ad8\uff0c\u6240\u4ee5\u6570\u636e\u5bb9\u91cf\u8981\u5c3d\u91cf\u5747\u5300\u5206\u5e03\u3002<\/span><\/span><\/span><\/span><\/p>\n


                                  <\/span><\/p>\n

                                  \uff082\uff09\u96c6\u7fa4\u5185\u5b58\u7c7b\u578b\uff1aFORK\u548cPSOCK<\/span><\/h4>\n

                                  FORK\u9002\u7528unix\/max\uff0c\u5b9e\u73b0\u5185\u5b58\u5171\u4eab\u4ee5\u53ca\u8282\u7701\u5185\u5b58\uff0c\u5927\u6570\u636e\u73af\u5883\u4e0b\u5185\u5b58\u95ee\u9898\u62a5\u9519\u5c11<\/span>
                                  <\/span><\/p>\n

                                  PSOCK\u9002\u7528\u6240\u6709\uff08\u4e00\u822cwindow\u90fd\u662f\u8fd9\u4e2a\uff09<\/span><\/p>\n

                                  <\/p>\n

                                  parallel\u5305\u4e2d\u901a\u8fc7\u51fd\u6570\u6765\u8bbe\u7f6e\uff1a<\/span><\/span><\/span><\/p>\n

                                  \n
                                  \n
                                  \n [html]<\/strong>  view plain
                                  \n  copy<\/span> <\/p>\n
                                  <\/div>\n

                                  <\/span>\n <\/div>\n<\/p><\/div>\n

                                    \n
                                  1. makeCluster\uff084\uff0c<\/span>type<\/span>=<\/span>\"FORK\"<\/span>\uff09  <\/span><\/span><\/li>\n<\/ol><\/div>\n


                                    \n FORK\u5bf9\u6027\u80fd\u63d0\u5347\u5f88\u663e\u8457\uff0c\u4f46\u662fwindow\u4e0b\u4e0d\u53ef\u9002\u7528\u3002<\/span> <\/p>\n


                                    <\/span><\/p>\n

                                    4\u3001parallel\u4e07\u4e00\u62a5\u9519\u4e86\u548b\u529e\uff1f<\/span><\/span><\/h3>\n

                                          lapply\u5728\u4f7f\u7528\u7684\u65f6\u5019\u4e5f\u4f1a\u51fa\u73b0\u8fd9\u6837\u7684\u95ee\u9898\uff0c\u5982\u679c\u51fa\u73b0\u95ee\u9898\uff0c\u90a3\u4e48\u5c31\u767d\u8dd1\u4e86\uff0c\u800c\u4e14\u4e5f\u4e0d\u53ef\u80fd\u7ed9\u4f60\u505c\u987f\u4e0b\u6765\u3002\u90a3\u4e48\u5982\u4f55\u8ba9lapply\u8fd0\u884c\u4e2d\u8df3\u8fc7\u62a5\u9519\u7684\u529e\u6cd5\u5462\uff1f<\/span><\/p>\n

                                          R\u8bed\u8a00\u76f8\u5173\u7684\u62a5\u9519\u5904\u7406\u51fd\u6570\u53ef\u89c1\uff1a<\/span>R\u8bed\u8a00-\u5904\u7406\u5f02\u5e38\u503c\u6216\u62a5\u9519\u7684\u4e09\u4e2a\u793a\u4f8b<\/p>\n

                                          \u7528tryCatch\u8df3\u8fc7\uff1a<\/span><\/p>\n

                                    <\/span><\/p>\n

                                    \n
                                    \n
                                    \n [html]<\/strong>  view plain
                                    \n  copy<\/span> <\/p>\n
                                    <\/div>\n

                                    <\/span>\n <\/div>\n<\/p><\/div>\n

                                      \n
                                    1. result<\/span> = <\/span>tryCatch<\/span>(  <\/span><\/span><\/li>\n
                                    2.         {expr},   <\/span><\/li>\n
                                    3.         warning<\/span> = <\/span>function<\/span>(w) {warning-handler-code},   <\/span><\/span><\/li>\n
                                    4.         error<\/span> = <\/span>function<\/span>(e) { error-handler-code},   <\/span><\/span><\/li>\n
                                    5.         finally<\/span> = {cleanup-code}  <\/span><\/span><\/li>\n
                                    6.         )  <\/span><\/li>\n<\/ol><\/div>\n

                                      \u51fa\u73b0warning\u3001error\u65f6\u5019\u600e\u4e48\u5904\u7406\uff0c\u5c31\u53ef\u4ee5\u8df3\u8fc7\u4e86\u3002\u4f8b\u5b50\uff1a<\/span> <\/p>\n

                                      <\/span><\/p>\n

                                      \n
                                      \n
                                      \n [html]<\/strong>  view plain
                                      \n  copy<\/span> <\/p>\n
                                      <\/div>\n

                                      <\/span>\n <\/div>\n<\/p><\/div>\n

                                        \n
                                      1. result<\/span> = <\/span>tryCatch<\/span>(  <\/span><\/span><\/li>\n
                                      2.         {segmentCN(txt)},   <\/span><\/li>\n
                                      3.         warning<\/span> = <\/span>function<\/span>(w) {\"\u51fa\u8b66\u544a\u5566\"},   <\/span><\/span><\/li>\n
                                      4.         error<\/span> = <\/span>function<\/span>(e) { \"\u51fa\u9519\u5566\"},   <\/span><\/span><\/li>\n
                                      5.         )  <\/span><\/li>\n<\/ol><\/div>\n

                                        \u5206\u8bcd\u65f6\u5019\uff0c\u5bb9\u6613\u56e0\u4e3aLapply\u4e2d\u65ad\u4e4b\u540e\uff0c\u5c31\u4e0d\u4f1a\u8fd0\u884c\u4e86\uff0c\u8fd9\u6837\u529f\u4e8f\u4e00\u7bd1\u6240\u4ee5\u53ef\u4ee5\u7528\u8fd9\u4e2a\u529e\u6cd5\u8df3\u8fc7\u3002<\/span><\/p>\n


                                        <\/span><\/p>\n

                                        5\u3001parSapply\/parLapply\u51fd\u6570\u4f7f\u7528\u6280\u5de7<\/span><\/h3>\n

                                               \u51fd\u6570\u7684\u5927\u4f53\u7ed3\u6784\u662f\uff1a<\/span><\/p>\n<\/p>\n

                                        \n
                                        \n
                                        \n [html]<\/strong>  view plain
                                        \n  copy<\/span> <\/p>\n
                                        <\/div>\n

                                        <\/span>\n <\/div>\n<\/p><\/div>\n

                                          \n
                                        1. parSapply(cl,x,fun)  <\/span><\/span><\/li>\n<\/ol><\/div>\n


                                          \n       \u5176\u4e2dcl\u662f\u9884\u5148\u8bbe\u5b9a\u597d\u7684\uff0cx\u662f\u9700\u8981\u5faa\u73af\u7684\u53d8\u91cf\uff0c\u800cfun\u662f\u51fd\u6570\u3002<\/span> <\/p>\n

                                                \u90a3\u4e48\u4e00\u822c\u6765\u8bf4\uff0cfun\u4e4b\u4e2d\u8981\u4f7f\u7528\u7684\u4efb\u4f55\u5185\u5bb9\u90fd\u9700\u8981\u7528clusterEvalQ\uff08\u5305\uff09\u3001clusterExport\uff08\u53d8\u91cf\uff09\u590d\u5236\u5230\u4e0d\u540c\u7684\u6838\u5fc3\u4e4b\u4e2d\u3002<\/span><\/p>\n

                                                 \u800cx\u5219\u53ef\u4ee5\u4e0d\u7528\u5e03\u7f6e\u5230\u5168\u5c40\uff0c\u56e0\u4e3a\u4ed6\u662f\u5728\u6e90\u73af\u5883\u4e0b\u8c03\u7528\u51fa\u6765\uff0c\u5e76\u62c6\u5206\u4efb\u52a1\u7684\u3002<\/span><\/p>\n


                                          <\/span><\/p>\n


                                          <\/span><\/p>\n


                                          <\/span><\/p>\n


                                          <\/span><\/p>\n<\/p>\n

                                          \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span>
                                          <\/span><\/p>\n


                                          <\/span><\/p>\n

                                          \u4e8c\u3001foreach\u5305\u7684\u4f7f\u7528\u65b9\u6cd5<\/span><\/h2>\n


                                          <\/span><\/p>\n

                                          1\u3001\u7b80\u5355\u4f7f\u7528\u6848\u4f8b<\/span><\/p>\n

                                          <\/span><\/p>\n

                                          \u8bbe\u8ba1foreach<\/code>\u5305\u7684\u601d\u60f3\u53ef\u80fd\u60f3\u8981\u521b\u5efa\u4e00\u4e2alapply\u548cfor\u5faa\u73af\u7684\u6807\u51c6\uff0c\u521d\u59cb\u5316\u7684\u8fc7\u7a0b\u6709\u4e9b\u4e0d\u540c\uff0c\u4f60\u9700\u8981register<\/code>\u6ce8\u518c\u96c6\u7fa4:<\/p>\n

                                          library(foreach) library(doParallel) cl<-makeCluster(no_cores) registerDoParallel(cl)<\/code><\/pre>\n

                                          \u8981\u8bb0\u5f97\u6700\u540e\u8981\u7ed3\u675f\u96c6\u7fa4\uff08\u4e0d\u662f\u7528stopCluster()<\/code>\uff09\uff1a<\/p>\n

                                          stopImplicitCluster()<\/code><\/pre>\n

                                          foreach\u51fd\u6570\u53ef\u4ee5\u4f7f\u7528\u53c2\u6570.combine<\/code>\u63a7\u5236\u4f60\u6c47\u603b\u7ed3\u679c\u7684\u65b9\u6cd5\uff1a<\/p>\n

                                          > foreach(exponent = 2:4, .combine = c) %dopar% base^exponent [1] 4 8 16<\/code><\/pre>\n
                                          > <\/span>foreach<\/span>(exponent =<\/span> 2<\/span>:4<\/span>, .combine =<\/span> rbind) %dopar% <\/span>  <\/span>base^exponent [,1<\/span>] result.1<\/span> 4<\/span> result.2<\/span> 8<\/span> result.3<\/span> 16<\/span><\/code><\/pre>\n
                                          foreach<\/span>(exponent =<\/span> 2<\/span>:4<\/span>, .combine =<\/span> list, .multicombine =<\/span> TRUE<\/span>) %dopar% <\/span>  <\/span>base^exponent [[1<\/span>]] [1<\/span>] 4<\/span> [[2<\/span>]] [1<\/span>] 8<\/span> [[3<\/span>]] [1<\/span>] 16<\/span><\/code><\/pre>\n

                                          \u6ce8\u610f\u5230\u6700\u540elist\u7684combine\u65b9\u6cd5\u662f\u9ed8\u8ba4\u7684\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\u7528\u5230\u4e00\u4e2a.multicombine<\/code>\u53c2\u6570\uff0c\u4ed6\u53ef\u4ee5\u5e2e\u52a9\u4f60\u907f\u514d\u5d4c\u5957\u5217\u8868\u3002\u6bd4\u5982\u8bf4list(list(result.1, result.2), result.3)<\/code> :<\/p>\n

                                          > foreach(exponent = 2:4, .combine = list) %dopar% base^exponent [[1]] [[1]][[1]] [1] 4 [[1]][[2]] [1] 8 [[2]] [1] 16<\/code><\/pre>\n

                                          <\/span><\/h5>\n
                                          2\u3001\u53d8\u91cf\u4f5c\u7528\u57df<\/span><\/h5>\n

                                          \u5728foreach\u4e2d\uff0c\u53d8\u91cf\u4f5c\u7528\u57df\u6709\u4e9b\u4e0d\u540c\uff0c\u5b83\u4f1a\u81ea\u52a8\u52a0\u8f7d\u672c\u5730\u7684\u73af\u5883\u5230\u51fd\u6570\u4e2d\uff1a<\/p>\n

                                          > base <- 2 > cl<-makeCluster(2) > registerDoParallel(cl) > foreach(exponent = 2:4, .combine = c) %dopar% base^exponent stopCluster(cl) [1] 4 8 16<\/code><\/pre>\n

                                          \u4f46\u662f\uff0c\u5bf9\u4e8e\u7236\u73af\u5883\u7684\u53d8\u91cf\u5219\u4e0d\u4f1a\u52a0\u8f7d\uff0c\u4ee5\u4e0b\u8fd9\u4e2a\u4f8b\u5b50\u5c31\u4f1a\u629b\u51fa\u9519\u8bef\uff1a<\/p>\n

                                          test <- function (exponent) { foreach(exponent = 2:4, .combine = c) %dopar% base^exponent } test() Error in base^exponent : task 1 failed - \"object 'base' not found\" <\/code><\/pre>\n

                                          \u4e3a\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u4f60\u53ef\u4ee5\u4f7f\u7528.export<\/code>\u8fd9\u4e2a\u53c2\u6570\u800c\u4e0d\u9700\u8981\u4f7f\u7528clusterExport<\/code>\u3002\u6ce8\u610f\u7684\u662f\uff0c\u4ed6\u53ef\u4ee5\u52a0\u8f7d\u6700\u7ec8\u7248\u672c\u7684\u53d8\u91cf\uff0c\u5728\u51fd\u6570\u8fd0\u884c\u524d\uff0c\u53d8\u91cf\u90fd\u662f\u53ef\u4ee5\u6539\u53d8\u7684\uff1a<\/p>\n

                                          base <- 2 cl<-makeCluster(2) registerDoParallel(cl) base <- 4 test <- function (exponent) { foreach(exponent = 2:4, .combine = c, .export = \"base\") %dopar% base^exponent } test() stopCluster(cl) [1] 4 8 16<\/code><\/pre>\n

                                          \u76f8\u4f3c\u7684\u4f60\u53ef\u4ee5\u4f7f\u7528.packages<\/code>\u53c2\u6570\u6765\u52a0\u8f7d\u5305,\u6bd4\u5982\u8bf4\uff1a.packages = c(\"rms\", \"mice\")<\/code><\/p>\n

                                          <\/p>\n

                                          \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span>
                                          <\/span><\/p>\n


                                          <\/span><\/p>\n

                                          \u4e09\u3001SupR<\/span><\/h2>\n

                                          \u901a\u8fc7\u5bf9\u73b0\u6709R \u5185\u6838\u7684\u6539\u8fdb\u5b9e\u73b0\u5728\u5355\u673a\u4e0a\u7684\u591a\u7ebf\u7a0b\u548c\u5728\u96c6\u7fa4\u4e0a\u7684\u5206\u5e03\u5f0f\u8ba1\u7b97\u529f\u80fd\u3002SupR\u76ee\u524d\u4ecd\u5904\u5728\u5185\u90e8\u8bd5\u7528\u548c\u8865\u5145\u5b8c\u5584\u9636\u6bb5\u3002<\/span><\/span><\/p>\n

                                          \"droptable\u4e0etruncatetable_droptable\u4e0etruncatetable
                                          <\/span><\/p>\n

                                                 \u636e\u8bf4supR\u5f88\u597d\u7528\uff0c\u800c\u4e14\u5c0f\u8c61\u5b66\u9662\u7684\u8bb2\u5e08\uff08\u6e38\u7693\u9e9f<\/span><\/span>\uff09\u5df2\u7ecf\u5f00\u59cb\u6559\u6388\u8fd9\u4e2a\u7cfb\u7edf\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u633a\u597d\u7528\u7684\u3002<\/span><\/p>\n


                                          <\/span><\/p>\n

                                          \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span>
                                          <\/span><\/p>\n


                                          <\/span><\/p>\n

                                          \u56db\u3001\u5185\u5b58\u7ba1\u7406<\/span><\/h2>\n


                                          <\/span><\/p>\n

                                          \u65b9\u6cd5\u6709\u4e09\uff1a<\/span>
                                                \u4e00\u3001\u5347\u7ea7\u786c\u4ef6<\/span>
                                                \u4e8c\u3001\u6539\u8fdb\u7b97\u6cd5<\/span>
                                                \u4e09\u3001\u4fee\u6539\u64cd\u4f5c\u7cfb\u7edf\u5206\u914d\u7ed9R\u7684\u5185\u5b58\u4e0a\u9650, memory.size(T)\u67e5\u770b\u5df2\u5206\u914d\u5185\u5b58 <\/span>
                                          <\/span><\/p>\n

                                          <\/span><\/p>\n

                                          \n

                                          \n
                                          \n
                                          \n [html]<\/strong>  view plain
                                          \n  copy<\/span> <\/p>\n
                                          <\/div>\n

                                          <\/span>\n <\/div>\n<\/p><\/div>\n

                                            \n
                                          1. memory.size(F)#\u67e5\u770b\u5df2\u4f7f\u7528\u5185\u5b58    <\/span><\/span><\/li>\n
                                          2. memory.limit()#\u67e5\u770b\u5185\u5b58\u4e0a\u9650   <\/span><\/li>\n
                                          3. object.size()#\u770b\u6bcf\u4e2a\u53d8\u91cf\u5360\u591a\u5927\u5185\u5b58\u3002  <\/span><\/li>\n
                                          4. memory.size()#\u67e5\u770b\u73b0\u5728\u7684work space\u7684\u5185\u5b58\u4f7f\u7528  <\/span><\/li>\n
                                          5. memory.limit()#\u67e5\u770b\u7cfb\u7edf\u89c4\u5b9a\u7684\u5185\u5b58\u4f7f\u7528\u4e0a\u9650\u3002\u5982\u679c\u73b0\u5728\u7684\u5185\u5b58\u4e0a\u9650\u4e0d\u591f\u7528\uff0c\u53ef\u4ee5\u901a\u8fc7memory.limit(newLimit)\u66f4\u6539\u5230\u4e00\u4e2a\u65b0\u7684\u4e0a\u9650\u3002\u6ce8\u610f\uff0c\u572832\u4f4d\u7684R\u4e2d\uff0c\u5c01\u9876\u4e0a\u9650\u4e3a4G\uff0c\u65e0\u6cd5\u5728\u4e00\u4e2a\u7a0b\u5e8f\u4e0a\u4f7f\u7528\u8d85\u8fc74G \uff08\u6570\u4f4d\u4e0a\u9650\uff09\u3002\u8fd9\u79cd\u65f6\u5019\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u752864\u4f4d\u7684\u7248\u672c\u3002  <\/span><\/li>\n<\/ol><\/div>\n

                                            \u8be6\u60c5\u770b\uff1a R\u8bed\u8a00\ufe31\u5927\u6570\u636e\u96c6\u4e0b\u8fd0\u884c\u5185\u5b58\u7ba1\u7406   \u4ee5\u53ca   R\u8bed\u8a00\u4e4b\u5185\u5b58\u7ba1\u7406 <\/p>\n

                                            <\/p>\n

                                            \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span>
                                            <\/span><\/p>\n


                                            <\/span><\/p>\n

                                            \u5e94\u7528\u4e00\uff1a\u4f7f\u7528parallel\u5305\u65f6\uff0c\u80fd\u4e0d\u80fdclusterExport\u6574\u4e2a\u51fd\u6570\u5462\uff1f<\/span><\/h2>\n


                                            <\/span><\/span><\/p>\n


                                            <\/span><\/span><\/p>\n

                                                  R\u8bed\u8a00\u5728\u4f7f\u7528Parallel\u65f6\u5019\uff0c\u4f1a\u51fa\u73b0\u8fd9\u6837\u7684\u7591\u95ee\uff0c\u4e00\u4e9b\u4e1c\u897f\u90fd\u9700\u8981\u5e7f\u64ad\u7ed9\u4e0d\u540c\u7684\u6838\u5fc3\uff0c\u90a3\u4e48\u5728clusterExport\u6b65\u9aa4\u600e\u4e48\u529e\u5462\uff1f\u80fd\u4e0d\u80fdclusterExport\u4e00\u6574\u4e2a\u51fd\u6570\uff1f\u7136\u540e\u76f4\u63a5parLapply\u5462\uff1f<\/span><\/span><\/span><\/p>\n

                                                  \u7b54\u6848\u5426\u5b9a\u7684\u3002\u7b14\u8005\u5728\u7528\u7684\u65f6\u5019\uff0c\u600e\u4e48\u6837\u90fd\u4e0d\u80fd\u628a\u6574\u4e2a\u51fd\u6570\u52a0\u8f7d\u8fdb\u53bb\uff0c\u6240\u4ee5\u53ea\u80fd\u53e6\u60f3\u529e\u6cd5\u3002<\/span><\/span><\/p>\n

                                                  \u65e2\u7136\u4e0d\u80fdclusterExport\u6574\u4e2a\u51fd\u6570\uff0c\u90a3\u5c31\u53ea\u80fd\u6539\u9020\u6211\u4eec\u7684\u51fd\u6570\u53bb\u9002\u5e94parallel\u5305\u4e86\u3002<\/span><\/span><\/span><\/span><\/p>\n

                                                  \u6765\u770b\u51e0\u4e2a\u51fd\u6570\u201c\u88ab\u201d\u6539\u9020\u7684\u4f8b\u5b50\uff0c\u4e00\u822c\u6765\u8bf4\u6709\u4e24\u4e2a\u529e\u6cd5\uff1a<\/span><\/span><\/p>\n


                                            <\/span><\/span><\/p>\n

                                            1\u3001\u65b9\u6cd5\u4e00\uff1a\u901a\u8fc7.GlobalEnv\u5e7f\u64ad\u6210\u5168\u5c40\u53d8\u91cf<\/span><\/h3>\n

                                            <\/span><\/span><\/span><\/p>\n

                                            \n
                                            \n
                                            \n [plain]<\/strong>  view plain
                                            \n  copy<\/span> <\/p>\n
                                            <\/div>\n

                                            <\/span>\n <\/div>\n<\/p><\/div>\n

                                              \n
                                            1. clusterExport(cl=cl, varlist=c(\"text.var\", \"ntv\", \"gc.rate\", \"pos\"), envir=environment())  <\/span><\/span><\/li>\n<\/ol><\/div>\n

                                                    \u5728\u51fd\u6570\u5bfc\u5165\u7684\u65f6\u5019\uff0c\u52a0\u5165envir\u53d8\u91cf\u8ba9\u5176\u5e7f\u64ad\u7ed9\u4e0d\u540c\u7684\u6838\u5fc3\uff0c\u8fd9\u4e2a\u53ef\u4ee5\u653e\u5728\u51fd\u6570\u4e4b\u4e2d\u6765\u4f7f\u7528\u3002 <\/p>\n


                                              <\/span><\/span><\/p>\n

                                              2\u3001\u65b9\u6cd5\u4e8c\uff1a\u628aparLapply\u5d4c\u5957\u8fdb\u51fd\u6570\u4e4b\u4e2d<\/span><\/span><\/h3>\n

                                              <\/span><\/span><\/span><\/p>\n

                                              \n
                                              \n
                                              \n [plain]<\/strong>  view plain
                                              \n  copy<\/span> <\/p>\n
                                              <\/div>\n

                                              <\/span>\n <\/div>\n<\/p><\/div>\n

                                                \n
                                              1. par.test <- function(text.var, gc.rate=10){   <\/span><\/span><\/li>\n
                                              2.     require(parallel)  <\/span><\/li>\n
                                              3.     pos <-  function(i) {  <\/span><\/li>\n
                                              4.         paste(sapply(strsplit(tolower(i), \" \"), nchar), collapse=\" | \")  <\/span><\/li>\n
                                              5.     }  <\/span><\/li>\n
                                              6.     cl <- makeCluster(mc <- getOption(\"cl.cores\", 4))  <\/span><\/li>\n
                                              7.     parLapply(cl, text.var, function(text.vari, gc.rate, pos) {  <\/span><\/li>\n
                                              8.         x <- pos(text.vari)  <\/span><\/li>\n
                                              9.         if (i%%gc.rate==0) gc()  <\/span><\/li>\n
                                              10.         x  <\/span><\/li>\n
                                              11.     }, gc.rate, pos)  <\/span><\/li>\n
                                              12. }  <\/span><\/li>\n<\/ol><\/div>\n

                                                       \u53ef\u4ee5\u770b\u5230\u7684\u8fd9\u4e2a \u4f8b\u5b50\uff0c\u5c31\u662f\u628a\u5185\u5bb9\u5d4c\u5957\u5230parLapply\u4e4b\u4e2d\u4e86\u3002\u540c\u65f6\u4e5f\u53ef\u4ee5\u5b66\u4e60\u5230\uff0cparLapply\u4f7f\u7528\u65b9\u6cd5\u4e5f\u5f88\u4e0d\u9519\uff0c\u4e5f\u53ef\u4ee5\u5b66\u4e60\u4e00\u4e0b\u3002 <\/p>\n

                                                      \u518d\u6765\u770b\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/span><\/p>\n

                                                <\/span><\/p>\n

                                                \n
                                                \n
                                                \n [plain]<\/strong>  view plain
                                                \n  copy<\/span> <\/p>\n
                                                <\/div>\n

                                                <\/span>\n <\/div>\n<\/p><\/div>\n

                                                  \n
                                                1. mainFunction <- function(cl) {  <\/span><\/span><\/li>\n
                                                2.     fa <- function(x) fb(x)  <\/span><\/li>\n
                                                3.     fb <- function(x) fc(x)  <\/span><\/li>\n
                                                4.     fc <- function(x) x  <\/span><\/li>\n
                                                5.     y <- 7  <\/span><\/li>\n
                                                6.     workerFunction <- function(i) {  <\/span><\/li>\n
                                                7.         do.call(functionNames[[i]], list(y))  <\/span><\/li>\n
                                                8.     }  <\/span><\/li>\n
                                                9.     environment(workerFunction) <- .GlobalEnv  <\/span><\/li>\n
                                                10.     environment(fa) <- .GlobalEnv  <\/span><\/li>\n
                                                11.     environment(fb) <- .GlobalEnv  <\/span><\/li>\n
                                                12.     environment(fc) <- .GlobalEnv  <\/span><\/li>\n
                                                13.     functionNames <- c(\"fa\", \"fb\", \"fc\")  <\/span><\/li>\n
                                                14.     clusterExport(cl, varlist=c(\"functionNames\", functionNames, \"y\"),  <\/span><\/li>\n
                                                15.                   envir=environment())  <\/span><\/li>\n
                                                16.     parLapply(cl, seq_along(functionNames), workerFunction)  <\/span><\/li>\n
                                                17. }  <\/span><\/li>\n
                                                18.   <\/span><\/li>\n
                                                19. library(parallel)  <\/span><\/li>\n
                                                20. cl <- makeCluster(detectCores())  <\/span><\/li>\n
                                                21. mainFunction(cl)  <\/span><\/li>\n
                                                22. stopCluster(cl)  <\/span><\/li>\n<\/ol><\/div>\n

                                                  <\/p>\n

                                                  \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span><\/p>\n

                                                  \u5e94\u7528\u4e8c\uff1a\u5728\u4f7f\u7528parallel\u5305\u65f6\uff0c\u62a5\u9519\uff1aError in unserialize(node$con) : error reading from connection<\/span><\/span><\/h2>\n


                                                  <\/span><\/p>\n

                                                        \u5728R\u8bed\u8a00\u4e2d\u4f7f\u7528\u5e76\u884c\u7b97\u6cd5\u7684\u65f6\u5019\uff0c\u4f1a\u51fa\u73b0\u62a5\u9519\uff0c\u65e0\u6cd5\u8fde\u63a5\u5230\u6838\u5fc3\uff0c\u5373\u4f7f\u5728\u672c\u6765\u8fde\u63a5\u4e0a\u7684\u65f6\u5019\u3002\u901a\u8fc7\u67e5\u9605\u6587\u732e\u770b\u5230\u4e86\uff0c\u8fd9\u662f\u56e0\u4e3a\u201c\u8c03\u7528\u6838\u5fc3\u6570--\u8ba1\u7b97\u673a\u5185\u5b58\u201d\u7684\u4e0d\u5339\u914d\u9020\u6210\u7684\u3002<\/span><\/span><\/span><\/p>\n

                                                        \u5982\u679c\u4f60\u7684\u6570\u636e\u96c6\u5f88\u5927\uff0c\u8c03\u7528\u4e86\u5f88\u591a\u6838\u5fc3\uff0c\u90a3\u4e48\u4f60\u7684\u8ba1\u7b97\u673a\u5185\u5b58\u5982\u679c\u4e0d\u591f\u5339\u914d\uff0c\u5c31\u4f1a\u51fa\u73b0\u8fde\u63a5\u4e0d\u4e0a\u7684\u4e0d\u9519\uff0c\u751a\u81f3\u8fd8\u51fa\u73b0\u5361\u673a\uff0c\u4e00\u52a8\u4e0d\u52a8\u7684\u60c5\u51b5\uff08\u5f53\u7136\uff0c\u53ea\u8981\u8010\u5fc3\u7b49\u5f85\uff0c\u5176\u5b9e\u4ed6\u8fd8\u662f\u4f1a\u7ee7\u7eed\u8fd0\u884c\u7684...\u7b49\u5f85\u7684\u65f6\u5019\u4f1a\u6709\u70b9\u957f\uff09<\/span><\/p>\n


                                                  <\/span><\/p>\n

                                                  \u89e3\u51b3\u529e\u6cd5\u4e00\uff1a\u8c03\u7528FORK\uff0cwindow\u4e0d\u80fd...<\/span><\/span><\/span><\/p>\n

                                                  <\/span><\/p>\n

                                                        FORK\u9002\u7528unix\/max\uff0c\u5b9e\u73b0\u5185\u5b58\u5171\u4eab\u4ee5\u53ca\u8282\u7701\u5185\u5b58\uff0c\u5927\u6570\u636e\u73af\u5883\u4e0b\u5185\u5b58\u95ee\u9898\u62a5\u9519\u5c11
                                                  <\/span><\/p>\n

                                                        PSOCK\u9002\u7528\u6240\u6709\uff08\u4e00\u822cwindow\u90fd\u662f\u8fd9\u4e2a\uff09<\/span><\/p>\n

                                                        \u4e0d\u8fc7\u8c03\u7528FORK\u4e5f\u8fd8\u662f\u6cbb\u6807\u4e0d\u6cbb\u672c\u3002 <\/p>\n


                                                  <\/span><\/p>\n

                                                  \u89e3\u51b3\u529e\u6cd5\u4e8c\uff1a\u5206\u5f00\u5e76\u884c\uff0c\u5c0f\u6b65\u8fed\u4ee3<\/span><\/span><\/p>\n

                                                        \u8b6c\u598210\u4e07\u6570\u636e\uff0c\u90a3\u4e48\u5c31\u201c2\u4e07+2\u4e07+<\/span>2\u4e07+<\/span>2\u4e07+<\/span>2\u4e07<\/span>\u201d\u7684\u8dd1\uff0c\u5982\u679c\u8fd8\u51fa\u73b0\u8131\u673a\uff0c\u5c31\u7528\u4e4b\u524dtryCatch\u8df3\u8fc7\uff0c\u8ba9\u635f\u5931\u964d\u4f4e\u5230\u6700\u5c0f\u3002<\/span><\/span><\/p>\n

                                                        \u6700\u597d\u7684\u529e\u6cd5\u4e86\u3002<\/span><\/span><\/p>\n

                                                  <\/p>\n

                                                  <\/p>\n

                                                  \u53c2\u8003\u6587\u732e\uff1aHow-to go parallel in R \u2013 basics + tips<\/span><\/span><\/p>\n

                                                  <\/p>\n

                                                  \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/span><\/p>\n


                                                  <\/span><\/p>\n

                                                  \u53c2\u8003\u6587\u732e<\/span><\/h2>\n


                                                  <\/span><\/span><\/span><\/p>\n

                                                  1\u3001R\u8bed\u8a00\u5e76\u884c\u5316\u57fa\u7840\u4e0e\u63d0\u9ad8<\/span><\/span><\/span><\/p>\n<\/p>\n

                                                  2\u3001R\u4e0e\u5e76\u884c\u8ba1\u7b97<\/span><\/span><\/h2>\n<\/p>\n

                                                  3\u3001sparklyr\u5305\uff1a\u5b9e\u73b0Spark\u4e0eR\u7684\u63a5\u53e3\uff0c\u4f1a\u7528dplyr\u5c31\u80fd\u73a9Spark<\/span><\/span><\/p>\n

                                                  4\u3001Sparklyr\u4e0eDocker\u7684\u63a8\u8350\u7cfb\u7edf\u5b9e\u6218
                                                  <\/span><\/span><\/p>\n

                                                  \n

                                                  5\u3001R\u8bed\u8a00\ufe31H2o\u6df1\u5ea6\u5b66\u4e60\u7684\u4e00\u4e9bR\u8bed\u8a00\u5b9e\u8df5\u2014\u2014H2o\u5305<\/span><\/span><\/p>\n

                                                  \n

                                                  6\u3001R\u7528\u6237\u7684\u798f\u97f3\ufe31TensorFlow\uff1aTensorFlow\u7684R\u63a5\u53e3<\/span><\/span><\/span> <\/p>\n

                                                  7\u3001mxnet\uff1a\u7ed3\u5408R\u4e0eGPU\u52a0\u901f\u6df1\u5ea6\u5b66\u4e60<\/span><\/span><\/span><\/span><\/p>\n

                                                  8\u3001\u788e\u7247\ufe31R\u8bed\u8a00\u4e0e\u6df1\u5ea6\u5b66\u4e60<\/span><\/span><\/p>\n<\/p><\/div>\n<\/p><\/div>\n

                                                  \n \u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3a\u535a\u4e3b\u539f\u521b\u6587\u7ae0\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u6765\u6e90\u201c\u7d20\u8d28\u4e91\u535a\u5ba2\u201d\uff0c\u8c22\u8c22\u5408\u4f5c\uff01\uff01\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u7d20\u8d28\u4e91\u7b14\u8bb0 https:\/\/blog.csdn.net\/sinat_\/article\/details\/\n <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"droptable\u4e0etruncatetable_droptable\u4e0etruncatetable\u7ec8\u4e8e\u5f00\u59cb\u653b\u514b\u5e76\u884c\u8fd9\u4e00\u5757\u4e86\uff0c\u6709\u70b9\u5c0f\u5174\u594b\uff0c\u6765\u770b\u770b\u7f51\u7edc\u4e0aR\u8bed\u8a00\u5e76\u884c\u529e\u6cd5\u6709\u54ea...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6071"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=6071"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6071\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=6071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=6071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=6071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}