⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createa.c

📁 在MPI上用并行LU分解求解线性方程组的源程序。
💻 C
字号:
/*create a file which store a metrix with specific Row &Column in the file the first two int are the Row&column of the matrix*/#include "stdio.h"#include "stdlib.h"#define MAX 20/*assume the max value of every element of that matrix */int main()	{		  char *filename;		  FILE *fd;		  int size;		  int i,j;/*loop variable*/		  float value;		  printf("Open a new file for write only!\n");		  printf("WARING:If the file already exist,it will be truncated to zero length!\n");		  printf("Please enter file name:");		  filename=(char *)malloc(sizeof(char)*128);		  scanf("%s",filename);			    /* printf("the filename is %s\n",filename);*/		  fd=fopen(filename,"w");		  if (fd==NULL)		    /*CANNOT create the file and exit the system*/			  {				   printf("error in create the file %s\n",filename);				   exit(0);			  }/*if*/		  else			  printf("Successfully create a new file %s\n",filename);			    /*create a file for write only,or open a file and truncate it to zero length*/		  printf("Please input the SIZE of the file please?\n");		  printf("Size:");		  scanf("%d",&size);		  printf("Matrix size=%d\n",size);		 /* fwrite(&size,sizeof(int),1,fd) ; */		  srand(getpid());/*reset the seed,and initialize the pseudo-random creation process*/		  for (i=0;i<size;i++)			  {			    for (j=0;j<size;j++)				{     value=MAX*rand()/(RAND_MAX+1);				      printf("%f ",value);				      fwrite(&value,sizeof(float),1,fd);				} /*for  j*/			    printf("\n");			  } /*for i*/		  fclose(fd);		  free(filename);			   /*close the file fd*/		  return(0);	 }		/*main*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -