我已经为使用MPI执行Fox的块矩阵乘法方法的类编写了一个程序。我能够通过在中使用sqrt()函数来做到这一点,但是为了编译程序,我必须输入“ mpicc -lm -o ...”。有关hw状态的说明,可使用“ mpicc -o ...”而不使用-lm来编译程序。我只是想知道是否有一种方法可以找到数字的平方根(无需编写单独的程序即可)。如果没有,我将免责声明放在.txt文件顶部的注释中。以为这可能是个好地方。谢谢!
我正在研究一个类的程序,它采用Floyd-Warshall有向图(由矩阵表示)并为图中的每个节点创建一个新的距离矩阵,将使用pthreads在线程之间创建新矩阵的工作分开.我觉得我到底是对的,我可以得到矩阵来形成和打印,但我似乎无法弄清楚如何按顺序打印距离矩阵(首先由线程0创建的矩阵行,然后线程1,线程2等).我使用互斥锁允许每个线程一起打印它的部分而不会中断,我只是无法按顺序打印线程.
我想知道那里的pthread guru是否会帮助我.提前致谢!
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
int n, totaln, **C, **D; /* Variable declarations */
pthread_t *threads;
pthread_mutex_t mutexprint;
long thread, threadcount;
void *LowestTerm(void* rank);
int main(int argc, char *argv[]) {
int i, j, k; /* Variable declarations */
char filename[50];
threadcount = atoi(argv[1]);
threads = malloc (threadcount * sizeof(pthread_t));
printf("Enter filename: "); /* User enters filename for directed graph values */
scanf("%s", filename);
FILE *fp = fopen(filename, "r");
if (fp == NULL) { /* …Run Code Online (Sandbox Code Playgroud)