message-passingprogramming(编辑修改稿)内容摘要:

6 p 3 id 6 p Copyright 169。 The McGrawHill Companies, Inc. Permission required for reproduction or display. What about External Variables? int total。 int main (int argc, char *argv[]) { int i。 int id。 int p。 …  Where is variable total stored? Copyright 169。 The McGrawHill Companies, Inc. Permission required for reproduction or display. Cyclic Allocation of Work for (i = id。 i 65536。 i += p) check_circuit (id, i)。  Parallelism is outside function check_circuit  It can be an ordinary, sequential function Copyright 169。 The McGrawHill Companies, Inc. Permission required for reproduction or display. Shutting Down MPI  Call after all other MPI library calls  Allows system to free up MPI resources MPI_Finalize()。 Copyright 169。 The McGrawHill Companies, Inc. Permission required for reproduction or display. include include int main (int argc, char *argv[]) { int i。 int id。 int p。 void check_circuit (int, int)。 MPI_Init (amp。 argc, amp。 argv)。 MPI_Comm_rank (MPI_COMM_WORLD, amp。 id)。 MPI_Comm_size (MPI_COMM_WORLD, amp。 p)。 for (i = id。 i 65536。 i += p) check_circuit (id, i)。 printf (Process %d is done\n, id)。 fflush (stdout)。 MPI_Finalize()。 return 0。 } Put fflush() after every printf() Copyright 169。 The McGrawHill Companies, Inc. Permission required for reproduction or display. /* Return 1 if 39。 i39。 th bit of 39。 n39。 is 1。 0 otherwise */ define EXTRACT_BIT(n,i) ((namp。 (1i))?1:0) void check_circuit (int id, int z) { int v[16]。 /* Each element is a bit of z */ int i。 for (i = 0。 i 16。 i++) v[i] = EXTRACT_BIT(z,i)。 if ((v[0] || v[1]) amp。 amp。 (!v[1] || !v[3]) amp。 amp。 (v[2] || v[3]) amp。 amp。 (!v[3] || !v[4]) amp。 amp。 (v[4] || !v[5]) amp。 amp。 (v[5] || !v[6]) amp。 amp。 (v[5] || v[6]) amp。 amp。 (v[6] || !v[15]) amp。 amp。 (v[7] || !v[8]) amp。 amp。 (!v[7] || !v[13]) amp。 amp。 (v[8] || v[9]) amp。 amp。 (v[8] || !v[9]) amp。 amp。 (!v[9] || !v[10]) amp。 amp。 (v[9] || v[11]) amp。 amp。 (v[10] || v[11]) amp。 amp。 (v[12] || v[13]) amp。 amp。 (v[13] || !v[14]) amp。 amp。 (v[14] || v[15])) { printf (%d) %d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d\n, id, v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9], v[10],v[11],v[12],v[13],v[14],v[15])。 fflush (stdout)。 } } Copyright 169。 The McGrawHill Companies, Inc. Permission required for reproduction or display. Compiling MPI Programs  mpicc: script to pile and link C+MPI programs  Flags: same meaning as C piler O  optimize o file  where to put executable mpicc O o foo Copyright 169。 The McGrawHill Companies, Inc. Permission required for reproduction or display. Running MPI Programs  mpirun np p exec arg1 … np p  number of processes exec  executable arg1 …  mandline arguments Copyright 169。 The McGrawHill Companies, Inc. Permission required for reproduction or display. Specifying Host Processors  File .mpimachines in home directory lists host processors in order of their use。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。