我正在编写一个OpenMPI程序,它为每个处理器创建一个数据库实例,插入一些数据,并在完成后关闭数据库。该程序适用于一个处理器。在创建第二个数据库实例时,启动多个会导致分段错误。 我的MPI程序看起来像这样:
#include <mpi.h>
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "rocksdb_c.h"
int main (int argc, char *argv[]) {
MPI_Init(&argc, &argv);
int rank, size;
time_t t;
MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */
MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */
srand(rank * 1766+8765);
int key = 0, value = 0;
rocksdb_env_t* env= CreateEnvironment(size);
rocksdb_options_t* options= InstantiateOptions(env);
rocksdb_t *db=CreateDb(options);
rocksdb_writeoptions_t* writeoptions=WriteOptions();
int i;
for ( i = 1; i < 10000; ++i) {
value = rand()%10000;
//key = rand()%10000;
key = i*size +rank;
Put(ToCharArray(key),ToCharArray(value), db, writeoptions);
printf("i=%d, key=%d, value=%d, rank=%d,size=%d\n",i, key,value,rank,size);
}
CloseDb(db);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
我的rocksdb_c.h
看起来像这样:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include "rocksdb/c.h"
#include <unistd.h> // sysconf() - get CPU count
const char DBPath[]="/tm/rocksdb_simple_example";
const char DBBackupPath[] = "/tmp/rocksdb_simple_example_backup";
rocksdb_env_t* CreateEnvironment(int processes){
rocksdb_env_t* env=rocksdb_create_default_env();
rocksdb_env_set_background_threads(env,processes);
rocksdb_env_set_high_priority_background_threads(env, processes);
return env;
}
rocksdb_t* CreateDb(rocksdb_options_t* options){
rocksdb_t *db;
char *err=NULL;
db = rocksdb_open(options, DBPath, &err); assert(!err);
return db; }
void CloseDb(rocksdb_t *db){
rocksdb_close(db);
}
rocksdb_options_t* InstantiateOptions(int processes){
rocksdb_options_t* options= rocksdb_options_create();
rocksdb_options_set_create_if_missing(options, 1);
rocksdb_options_set_env(options,env);
return options;
}
rocksdb_writeoptions_t* WriteOptions(){
return rocksdb_writeoptions_create();
}
void Put(char* key, char* value, rocksdb_t* db, rocksdb_writeoptions_t* writeoptions){
char *err=NULL;
printf("before\n");
rocksdb_put(db, writeoptions, key, strlen(key), value, strlen(value) , &err);
}
rocksdb_open()
功能中CloseDB()
的第二次调用导致程序失败。错误分段失败。
任何想法?
答案 0 :(得分:1)
我认为每个实例都需要不同的showSignUpError(<?php echo $error; ?>);
,您也可以查看showSignUpError("<?php echo $error; ?>");
并在实例之间共享。