记ParOSol学习

目录

求解器搭建

HDF5的搭建

MPI的安装

Eigen的安装


HDF5的搭建

包下载:Download HDF5® - The HDF Group

HDF5 Library and Tools 1.14.4 | The HDF Group

第一个链接拉到最后下Window的就好,是所谓的“Pre-built binary distributions for Unix and Windows”版本,第二个链接内有“Source Release for Windows”版本,没接触过,不会用。现在包内没有msi可以直接安装,其实只需要把包内的bin路径添加到系统path变量就行。

我是需要用的是C++,所以用的软件是VS。中间小问题记录一下。

后续要使用这个包,按照文件内的“USING_HDF5_VS.txt”操作就好,就下面的四步。

    /************************************************************

This example shows how to read and write data to a
dataset.  The program first writes integers to a dataset
with dataspace dimensions of DIM0xDIM1, then closes the
file.  Next, it reopens the file, reads back the data, and
outputs it to the screen.

This file is intended for use with HDF5 Library version 1.8

************************************************************/

#include "hdf5.h"
#include <stdio.h>
#include <stdlib.h>

#define FILE            "h5ex_d_rdwr.h5"
#define DATASET         "DS1"
#define DIM0            4
#define DIM1            7

int
main(void)
{
    hid_t       file, space, dset;          /* Handles */
    herr_t      status;
    hsize_t     dims[2] = { DIM0, DIM1 };
    int         wdata[DIM0][DIM1],          /* Write buffer */
        rdata[DIM0][DIM1];          /* Read buffer */
    hsize_t         i, j;

    /*
    * Initialize data.
    */
    for (i = 0; i<DIM0; i++)
        for (j = 0; j<DIM1; j++)
            wdata[i][j] = i * j - j;

    /*
    * Create a new file using the default properties.
    */
    file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /*
    * Create dataspace.  Setting maximum size to NULL sets the maximum
    * size to be the current size.
    */
    space = H5Screate_simple(2, dims, NULL);

    /*
    * Create the dataset.  We will use all default properties for this
    * example.
    */
    dset = H5Dcreate(file, DATASET, H5T_STD_I32LE, space, H5P_DEFAULT,
        H5P_DEFAULT, H5P_DEFAULT);

    /*
    * Write the data to the dataset.
    */
    status = H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
        wdata[0]);

    /*
    * Close and release resources.
    */
    status = H5Dclose(dset);
    status = H5Sclose(space);
    status = H5Fclose(file);


    /*
    * Now we begin the read section of this example.
    */

    /*
    * Open file and dataset using the default properties.
    */
    file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
    dset = H5Dopen(file, DATASET, H5P_DEFAULT);

    /*
    * Read the data using the default properties.
    */
    status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
        rdata[0]);

    /*
    * Output the data to the screen.
    */
    printf("%s:\n", DATASET);
    for (i = 0; i<DIM0; i++) {
        printf(" [");
        for (j = 0; j<DIM1; j++)
            printf(" %3d", rdata[i][j]);
        printf("]\n");
    }

    /*
    * Close and release resources.
    */
    status = H5Dclose(dset);
    status = H5Fclose(file);

    return 0;
}

这里参考这位老师的链接的程序运行一下,就算HDF5到位了

VS2013配置HDF5_vs cgns hdf5 无法解析外部-CSDN博客

//但是:HDF5目前的版本是1.14,安装过python或者Anaconda可能会自己安装一个1.8的版本,所以自己检查一下,否则会报“Warning! ***HDF5 library version mismatched error***”的警告:

广为流传的有三种解决办法:

1.pip uninstall h5py,pip install h5py,据说最有用的办法,对我无用;

2.HDF5_DISABLE_VERSION_CHECK' to a value of '1',官方给的解决办法,我的电脑可能有病,也无用。

3.卸载python或者Anaconda,卸了对我也没用。

最后我换了个电脑,搞不过搞不过,再学深点再来看看吧

----------------------------------------------------------------------------------

恭喜我:我的解决办法

系统变量添加:LD_LIBRARY_PATH=----------------\hdf5\lib

Path:添加----------------\hdf5\bin,并把它上移到path路径最前端(一定要移到最前,然后重启下软件就好了,推测应该是和哪个软件安的hdf5冲突了,导致调用的是该软件的老版本hdf5,看我之后哪个软件不能用吧)

HDF5并行版本:

好吧,ParOSol需要的是并行版本的,这个我在HDF5官网并没有找到编译好的二进制文件,得从源码自己编译一下了

注:Python有现成的,不用走C++这一套。

  1. Cmake的使用:
    1. 从源码配置项目:
      • "Where is the source code:" 字段中,选择你解压的 HDF5 源代码目录(例如 C:\path\to\hdf5-1.14.1-2)。
      • "Where to build the binaries:" 字段中,选择一个构建目录(例如 C:\path\to\hdf5-1.14.1-2\build)。
    2. 设置Cmake:
      • 点击 "Configure" 按钮。
      • 选择 "Visual Studio 16 2019"(或你的 Visual Studio 版本)作为生成器。
      • 选择 "x64" 作为平台。
      • 点击 "Finish"
    3. 设置变量:
      1. 在 CMake 配置界面中,启用 "HDF5_ENABLE_PARALLEL" 选项,并指定 MPI 编译器。如果没有看到 MPI 相关的选项,可以手动设置 CMake 变量:
      2. 改变将来二进制文件生成位置:CMAKE_INSTALL_PREFIX设置为将来二进制文件的生成位置
    4. 点击 "Generate" 按钮生成 Visual Studio 项目文件
  2. VS中编译二进制文件
    1. 双击HDF5.sln打开VS
    2. 打开INSTALL右键生成

  1. 有了二进制文件后:在系统变量添加路径,然后其他步骤一样,由于与MPI联动,所以要在C++项目中添加MPI对应的路径
  2. 报错:无法打开文件“hdf5.lib” Project1 C:\Users\Wangyan\Desktop\First\Hdf5\Project1\LINK 1
    1. 我发现我的文件内就没有这个,所以我从官网的编译好的二进制文件的.lib文件夹复制过去,然后问题解决,希望后续不会出问题

MPI的安装

在此我选择的是MSMPI,希望能用:

这个没什么波折,搜到下安装包,.msi与.exe的都安上就好了。VS内调用也同上,网上都把包含目录与库目录放在VC++下,我还是像HDF5一样分别放在C++与链接器下,也没什么影响。有什么区别咱也不清楚,往后再看。

还有一个说是把:C/C++ -> 代码生成 -> 运行库,选择:多线程调试(/MTd);我还是用的DLL/MTd也还能用,区别咱还是不知道,就先这样。

#include <stdio.h>
#include <mpi.h>

int main(int argc, char* argv[])
{
    int myid, numprocs, namelen;
    char processor_name[MPI_MAX_PROCESSOR_NAME];

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &myid);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    MPI_Get_processor_name(processor_name, &namelen);
    if (myid == 0)
    {
        printf("number of processes: %d\n", numprocs);
    }
    printf("%s: Hello world from process %d \n", processor_name, myid);

    MPI_Finalize();

    return 0;

}

代码先参照这位大佬的:MPI 在Windows11 和 VS2019 安装、测试、基本使用_mpich下载 win11-CSDN博客简单运行一下。

Eigen的搭建

Eigen下载好后就这一个步骤

2024.7.18,就这样,接下来希望搭建求解器顺利。

ParOSol的搭建

Eigen又出问题了,提示检测不到两个文件

  • 25
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值